| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Windows Target |
| Contents | Index |
| Learn more about Real-Time Windows Target |
| On this page… |
|---|
Entering Simulation Parameters Entering Scope Parameters for Signal Tracing Creating a Real-Time Application Entering Additional Scope Parameters for Signal Tracing |
You create a real-time application to let your system run while synchronized to a real-time clock. This allows your system to control or interact with an external system. This is necessary if you use your system to stabilize a physical plant. The first step is to create a Simulink Model, as described in the previous section, Using Simulink Models.
After you create a Simulink model, you can enter simulation parameters for use by Real-Time Workshop code generation software for creating C code and building a real-time application.
This procedure uses the Simulink model rtwin_model.mdl as an example and assumes you have already loaded that model:
In the Simulink window, and from the Simulation menu, click Configuration Parameters.
Click the Real-Time Workshop node.
The Real-Time Workshop pane opens.
In the Target selection section, click the Browse button at the RTW system target file list.
The System Target File Browser opens.
Select the system target file for building a Real-Time Windows Target application, and click OK.

The dialog automatically enters the system target file rtwin.tlc, the template makefile rtwin.tmf, and the make command make_rtw into the Real-Time Workshop pane.
If you have the Real-Time Workshop® Embedded Coder™ product, you can build an ERT target application. To build an ERT target application, in the Target selection section, click the Browse button at the System target file list. Click rtwinert.tlc, and then click OK.
Although not visible in the Real-Time Workshop pane, when you click OK you also configure the external target interface MEX file rtwinext. This allows external mode to pass new parameters to the real-time application and to return signal data from the real-time application. The data is displayed in Scope blocks or saved with signal logging.
Your Real-Time Workshop pane looks similar to the next figure.

Do not select Inline parameters on the Optimization node. Inlining parameters is used for custom targets when you want to reduce the amount of RAM or ROM with embedded systems. Also, if you select inlining parameters, you disable the parameter tuning feature. Since PCs have more memory than embedded systems, we recommend that you do not inline parameters.
Click the Hardware Implementation node. The following values are set by default:
Device vendor — Generic
Device type — 32-bit x86 compatible
Emulation hardware — None

Click Apply to apply the changes to your model and leave the dialog box open.
Click OK to apply the changes to your model and close the dialog box.
You enter or change scope parameters to format the x-axis and y-axis in a Scope window. Other parameters include the number of graphs in a one Scope window and whether the scope is connected to a continuous or discrete model.
If you entered the scope parameters for running a simulation, you can skip this procedure. This information is repeated here if you did not run a simulation.
After you add a Scope block to your Simulink model, you can enter the scope parameters for signal tracing:
In the Simulink window, double-click the Scope block.
A Scope window opens.

A Scope parameters dialog box opens.
Click the General tab. In the Number of axes field, enter the number of graphs you want in one Scope window. For example, enter 1 for a single graph. Do not select the floating scope check box.
In the Time range field, enter the upper value for the time range. For example, enter 1 second. From the Tick labels list, choose all.
From the Sampling list, choose Sample time and enter 0 in the text box. Entering 0 indicates that the Simulink software evaluates this block as a continuous time block. If you have discrete blocks in your model, enter the Fixed step size you entered in the Configuration Parameters dialog box.
Your Scope parameters dialog box looks similar to the next figure.

Click Apply to apply the changes to your model and leave the dialog box open.
Click OK to apply the changes to your model and close the dialog box.
In the Scope window, point to the y-axis and right-click. From the menu, click Axes Properties.
The Scope properties: axis 1 dialog box opens.
In the Y-min and Y-max text boxes enter the range for the y-axis in the Scope window. For example, enter -2 and 2.

Click Apply to apply the changes to your model and leave the dialog box open.
Click OK to apply the changes to your model and close the dialog box.
The Real-Time Workshop code generation software creates C code from your Simulink model, then the Open Watcom C/C++ compiler compiles and links that C code into a real-time application.
After you enter parameters into the Configuration Parameters dialog box for use by the Real-Time Workshop code generation software, you can build a real-time application. This procedure uses the Simulink model rtwin_model.mdl as an example, and assumes you have loaded that model:
In the Simulink window, from the Tools menu, point to Real-Time Workshop, and then click Build Model.
The build process does the following:
The Real-Time Workshop code generation software creates the C code source files rtwin_model.c and rtwin_model.h.
The make utility make_rtw.exe creates the makefile rtwin_model.mk from the template makefile rtwin.tmf.
The make utility make_rtw.exe builds the real-time application rtwin_model.rwd using the makefile rtwin_model.mk created above. The file rtwin_model.rwd is a binary file that we refer to as your real-time application. You can run the real-time application with the Real-Time Windows Target kernel.
Connect your Simulink model to your real-time application. See Entering Additional Scope Parameters for Signal Tracing.
After you create a real-time application, you can exit the MATLAB environment, start the MATLAB environment again, and then connect and run the executable without having to rebuild.
Simulink external mode connects your Simulink model to your real-time application. This connection allows you to use the Simulink block diagram as a graphical user interface to your real-time application.
After you have created a real-time application, you can enter scope parameters for signal tracing with Simulink external mode:
In the Simulation window, and from the Simulation menu, click Configuration Parameters.
Select the Real-Time Windows Target node.
The Real-Time Windows Target pane opens.
Select the External mode check box.
The MEX-file name label should have an entry of rtwinext. The MEX-file rtwinext.mex* is supplied with the Real-Time Windows Target software to work with Simulink external mode and support uploading signal data and downloading parameter values.
The Real-Time Windows Target pane should appear as follows.

In the Simulation window, and from the Tools menu, click External Mode Control Panel.
The External Mode Control Panel dialog box opens.

Click the Signal & Triggering button.
The External Signal & Triggering dialog box opens.
Select the Select all check box. From the Source list, choose manual. From the Mode list, choose normal.
The X under Signal selection indicates that a signal is tagged for data collection, and T indicates that the signal is tagged as a trigger signal.
In the Duration field, enter the number of sample points in a data buffer. For example, to specify a sample rate of 1000 samples/second and a stop time of 10 seconds, enter
10001
Select the Arm when connecting to target check box.
If you do not select this check box, data is not displayed in the Scope window.
The External Signal & Triggering dialog box looks like this:

Click Apply to apply the changes to your model and leave the dialog box open.
Click Close to apply the changes to your model and close the dialog box.
You must click the Apply or Close button on the External Signal & Triggering dialog box for the changes you made to take effect. Generally it is not necessary to rebuild your real-time application.
You run your real-time application to observe the behavior of your model in real time with the generated code. The process of connecting consists of
Establishing a connection between your Simulink model and the kernel to allow exchange of commands, parameters, and logged data.
Running the application in real time.
After you build the real-time application, you can run your model in real time. This procedure uses the Simulink model rtwin_model.mdl as an example, and assumes you have created a real-time application for that model:
Select External mode simulation.
Choose Connect To Target.
(You can connect to the target from the toolbar by clicking
).
The MATLAB Command Window displays the message
Model rtwin_model loaded
From the Simulation menu, choose Start Real-Time Code.
(You can also start the code from the toolbar by clicking
).
The Simulink software runs the execution and plots the signal data in the Scope window.
In this example, the Scope window displays 1000 samples in 1 second, increases the time offset, and then displays the samples for the next 1 second.
Note Transfer of data is less critical than calculating the signal outputs at the selected sample interval. Therefore, data transfer runs at a lower priority in the remaining CPU time after real-time application computations are performed while waiting for another interrupt to trigger the next real-time application update. The result may be a loss of data points displayed in the Scope window. |

Let the execution run until it reaches the stop time.
From the Simulation menu, click Stop Real-time Code.
The real-time application stops.
In the Simulation window, and from the Simulation menu, click Disconnect From Target.
From the Simulation menu, click External.
The MATLAB Command Window displays the message
Model rtwin_model unloaded
You can use the MATLAB command-line interface as an alternative to using the Simulink GUI. Enter commands directly in the MATLAB Command Window or enter them in an M-file.
After you build the real-time application, you can run your model in real time. This procedure uses the Simulink model rtwin_model.mdl as an example, and assumes you have created a real-time application for that model:
In the MATLAB Command Window, type
set_param(gcs,'SimulationMode','external')
The Simulink software changes to external mode.
set_param(gcs,'SimulationCommand','connect')
The MATLAB environment loads the real-time application, connects it to the Simulink block diagram, and displays the message
Model rtwin_model loaded
set_param(gcs,'SimulationCommand','start')
The Simulink software starts running the real-time application.
set_param(gcs,'SimulationCommand','stop')
The Simulink software stops the real-time application.
![]() | Using Simulink Models | Logging Signals to the Base Workspace | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |