| Contents | Index |
| On this page… |
|---|
A Simulink model is a graphical representation of your physical system. You create a Simulink model for a non-real-time simulation of your system, and then you use the Simulink model to create a real-time application.
You need to create a Simulink model before you can run a simulation or create a real-time application. This procedure explains how to create a simple Simulink model. You can use this model as an example to learn other procedures that are useful with Real-Time Windows Target software.
In the MATLAB Command Window, type
simulink
The Simulink Library Browser opens. The left pane shows a hierarchy of libraries and block categories, with the Simulink library at the top. The right pane shows the blocks available in the category selected on the left. See Library Browser for more information.
Choose File > New > Model, or click the New model button on the toolbar.
An empty Simulink window opens:
In the left pane of the Simulink Library Browser window, select Simulink > Sources. Click and drag a Signal Generator block from the browser to the Simulink window.
Select Continuous. Click and drag a Transfer Fcn block to the Simulink window.
Select Sinks. Click and drag a Scope block to the Simulink window.
Connect the Signal Generator output to the Transfer Fcn input by clicking-and-dragging a line between the blocks. Likewise, connect the Transfer Fcn output to the Scope input.
Double-click the Transfer Fcn block. The Block Parameters dialog box opens. In the Numerator text box, enter:
[10000]
In the Denominator text box, enter
[1 70 10000]
Your Block Parameters dialog box looks similar to the next figure.

Double-click the Signal Generator block. The Block Parameters dialog box opens. From the Wave form list, select square.
In the Amplitude text box, enter
1
In the Frequency text box, enter
20
From the Units list, select rad/sec.
Your Block Parameters dialog box looks similar to the next figure.

The next figure shows the completed Simulink block diagram, with toolbar and status bar not shown:

From the File menu, click Save As. The Save As dialog box opens. In the File name text box, enter a file name for your Simulink model and click Save. For example, type
rtwin_model
The Simulink software saves your model in the file rtwin_model.mdl.
To specify a default Real-Time Windows Target configuration set for your model, see Specifying the Default Configuration Set. If you activate this configuration set for your model, you can build your real-time application later without setting additional configuration parameters.
To manually configure your model, continue to Entering Configuration Parameters Manually, following. That section teaches you how to enter configuration parameters for your Simulink model, then leads you into procedures for entering scope parameters and running a non-real-time simulation of the model.
The Real-Time Windows Target software supports model referencing. See Referencing a Model in the Simulink User's Guide guide for more information.
Like most real-time environments, the Real-Time Windows Target software does not include a file system. Therefore, a Simulink model intended for use in a Real-Time Windows Target application cannot use any blocks, such as the To File or From File block, that generate file I/O calls such as fopen or printf.
If a Real-Time Windows Target model contains any block that tries to perform file system I/O, an error could occur when you try to compile the model, generate code for it, or use External Mode with it. Even if no error occurs, the block has no effect on either simulation or code execution.
To log signal data without needing a file system, use the techniques described in Logging Signals to a Disk Drive. See Running a Real-Time Application for information about using External Mode to execute a Real-Time Windows Target application.
After you create a Simulink model, you can enter configuration parameters for the model. These parameters control many properties of the model for simulation and code generation. This section contains the essential information you need when setting configuration parameters for a Real-Time Windows Target application. For complete information about Simulink configuration parameters, see Manage a Configuration Set and Configuration Parameters Dialog Box.
A configuration set is a named set of values for model parameters, such as solver type and simulation start or stop time. Every new model is created with a default configuration set, called Configuration, that initially specifies default values for the model's model parameters. You can subsequently create additional configuration sets and associate them with the model, as described in Manage a Configuration Reference.
The easiest way to specify configuration parameters for a Real-Time Windows Target model is to programmatically assign the default Real-Time Windows Target configuration set, as described in Specifying the Default Configuration Set. You can also set parameters manually, as described in Entering Configuration Parameters Manually. Other sections describe setting configuration patterns for specific purposes.
After you create a Simulink model, you can use the rtwinconfigset function to specify a default Real-Time Windows Target configuration set for the model. In most cases, using rtwinconfigset provides all the configuration parameter values that the model needs. The following procedure uses the Simulink model rtwin_model.mdl as an example and assumes you have already loaded that model (see Creating a Model):
If you have not already saved the model, from the File menu, click Save As. The Save As dialog box opens. In the File name text box, enter a file name for your Simulink model and click Save. For example, type
rtwin_model
The Simulink software saves your model in the file rtwin_model.mdl.
In the MATLAB Command Window, type
rtwinconfigset('rtwin_model')
The default Real-Time Windows Target configuration set, RTWin, is now active for the rtwin_model model. (Alternatively, you can set the default Real-Time Windows Target configuration set by setting the Configuration Parameters System target file option to rtwin.tlc.) You do not need to perform any other configuration for a Real-Time Windows Target application.
Save the model.
See Creating a Real-Time Application for a description of how to build your Real-Time Windows Target application.
To revert to the default configuration set, Configuration, or any other configuration set you have for the model, use Model Explorer. This is an alternative tool that you can use to enter simulation parameters for a model. See the Simulink documentation for a description of how to use Model Explorer.
Note Your model uses a Real-Time Windows Target configuration set when you change the System target file value to a Real-Time Windows Target one, such as rtwin.tlc or rtwinert.tlc. The software creates the Real-Time Windows Target configuration set, RTWin or RTWinERT, only if one does not already exist. |
The configuration parameters give information to Simulink software for running a simulation. 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. In the Configuration Parameters dialog box, click the Solver tab.
The Solver pane opens.
In the Start time field, enter 0.0. In the Stop time field, enter the amount of time you want your model to run. For example, enter 10.0 seconds.
From the Type list, choose Fixed-step. Simulink Coder code generation software does not support variable step solvers.
From the Solver list, choose a solver. For example, choose the general purpose solver ode5 (Dormand-Prince).
In the Fixed step size field, enter a sample time. For example, enter 0.001 seconds for a sample rate of 1000 samples/second.
From the Tasking Mode list, choose SingleTasking. (For models with blocks that have different sample times, choose MultiTasking.)
Your Solver pane 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.
You enter or change scope parameters to specify the x-axis and y-axis in a Scope window. Other properties include the number of graphs in one Scope window and the sample time for models with discrete blocks.
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 shown in the next figure, and right-click.

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 as shown in 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.
You use Simulink normal mode to run a non-real-time simulation. Running a simulation lets you observe the behavior of your model in nonreal time.
After you load your Simulink model into the MATLAB workspace, you can run a simulation. This procedure uses the Simulink model rtwin_model.mdl as an example and assumes you have loaded that model:
In the Simulink window, double-click the Scope block.
The Simulink software opens a Scope window with an empty graph.
Select Normal mode simulation.
Choose Start to begin simulation.
The Simulink software runs the simulation and plots the signal data in the Scope window.
During the simulation, the Scope window displays the samples for one time range, increases the time offset, and then displays the samples for the next time range.

Let the simulation run to the stop time.
From the Simulation menu, click Stop.
The simulation stops. The MATLAB environment does not display any messages.
![]() | Basic Procedures | Using Real-Time Applications | ![]() |

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