The Simulink® Real-Time™ environment is a solution for prototyping and testing real-time systems using a desktop computer. To support this solution, the software allows you to add I/O blocks to your model. The blocks of the Simulink Real-Time library provides a particular function of an I/O module. By using I/O blocks in your model, you can generate executable code tuned specifically to your I/O requirements.
You add I/O driver blocks to your Simulink model to connect your model to I/O modules (I/O boards). These I/O modules then connect to the sensors and actuators in the physical system.
Speedgoat real-time target machines are available with various I/O modules. See Speedgoat I/O Modules.
In addition to the blocks contained in the Simulink Real-Time library, you can also use third-party driver blocks in your Simulink Real-Time model. The description of these blocks is beyond the scope of the Simulink Real-Time documentation. See the provider of the third-party driver blocks for information on those boards and driver blocks.
A driver block does not represent an entire board, but an I/O section supported by a board. Therefore, the Simulink Real-Time library can have more than one block for each physical board. I/O driver blocks are written as C-code S-functions (noninlined S-functions). The source code for the C-code S-functions is included with the Simulink Real-Time software.
Note, if your model contains I/O blocks, take I/O latency values into account for the model sample time. To find latency values for a board supported by the Simulink Real-Time block library, consult the vendor data sheet. To find a link to the vendor website, see:
To find latency values for Speedgoat boards, contact Speedgoat technical support.
The Simulink Real-Time system supports PCI and ISA (PC/104) buses. If the bus type is not indicated in the driver block number, determine the bus type of the block by examining the block parameter dialog box. The last parameter is either a PCI slot, for PCI boards, or a base address, for ISA (PC/104) boards.
You can open the I/O device driver library with the MATLAB® command
slrtlib contains sublibraries grouped
by the type of I/O function they provide.
This library also contains the following blocks:
Simulink Real-Time Driver Examples — When you double-click this block, the Demos tab in the MATLAB Help Navigator opens, displaying the Simulink Real-Time examples and example groups.
Help for Simulink Real-Time — When you double-click this block, the Simulink Real-Time roadmap page is displayed. You can access the Simulink Real-Time documentation with this block.
Note: The Simulink Real-Time documentation describes only the Simulink Real-Time blocks. It does not describe the actual board. Refer to the board manufacturer documentation for information about the boards.
When you double-click one of I/O block groups, the sublibrary opens, displaying a list grouped by manufacturer. Double-clicking one of the manufacturer groups displays the I/O device driver blocks for the specified I/O functionality (for example, A/D, D/A, Digital Inputs, and Digital Outputs).
When you double-click one of the blocks, a Block Parameters dialog box opens, allowing you to enter system-specific parameters. Parameters typically include
Number of channels
PCI slot (PCI boards)
Base address (ISA/104 boards)
Simulink Real-Time reserves a 112 kB memory space for memory-mapped devices in the address range:
C0000 - DBFFF
Drivers for some memory-mapped devices, such as the Softing CAN-AC2-104 board, support an address range higher than the range that Simulink Real-Time supports. Select an address range supported by both the device driver and the Simulink Real-Time software.
There are two types of ISA boards:
Jumper addressable ISA cards
PnP (Plug and Play) ISA cards
The Simulink Real-Time software only supports jumper addressable ISA cards (non-PnP ISA boards) where you have to set the base address manually.
The Simulink Real-Time I/O library supports I/O boards with a PCI bus. During the boot process, the BIOS creates a conflict-free configuration of base addresses and interrupt lines for the PCI devices in the target system. You do not need to define base address information in the dialog boxes of the drivers.
PCI device driver blocks have an additional entry in their dialog
boxes. This entry is called
PCI Slot (-1 Autodetect) and
allows you to use several identical PCI boards within one target system.
This entry uses a default value of
-1, which allows
the driver to search the entire PCI bus to find the board. If you
specify a single number,
X, greater than
the driver uses the board in bus
When more than one board of the same type is found, you must use a
designated slot number and avoid the use of autodetection. For manually
setting the slot number, you use a number greater than or equal to
If the board cannot locate this slot in the target computer, your
real-time application will generate an error message after downloading.
PCI Slot (-1 Autodetect) to a value
equal to or greater than
0, you must identify which
board you want on the target computer. To identify the board, find
the manufacturer identification number (Vendor ID) and board identification
number (Device ID) of the boards supported by the I/O library. When
the target is booted, the BIOS is executed and the target computer
monitor shows parameters for the PCI boards installed on the target
computer. For example:
In this example, the third line indicates the location of the Measurement Computing™ PCI-DIO48
board. This location is known since the Measurement Computing vendor
0x1307 and the device ID is
In this case, you can see that the Measurement Computing board
is plugged into PCI slot 11 (Device Number), and that this value must
be entered in the dialog box entry in your I/O device driver for each
model that uses this I/O device.
Properties for Simulink Real-Time I/O drivers are defined using the parameter dialog box associated with each Simulink block. However, for more advanced drivers, the available fields defined by text boxes, check boxes, and pull-down lists are inadequate to define the behavior of the driver. In such cases, you must provide a more textual description to indicate what the driver has to do at run time. Textual in this context refers to a programming-language-like syntax and style.
The Simulink Real-Time software currently uses a character vector description contained in message structures for the conventional RS-232, GPIB, CAN (initialization), and the general counter drivers (AMD9513).
A message structure is a MATLAB array with each cell containing one complete message (command). A message consists of one or more statements.
|First Message||Second Message||Third Message|
Each statement in a message has the following format:
Structure_name(index).field_name = <field character vector or value>
The driver defines the field names. Enter them with upper- and lowercase letters as defined. However, you can choose your own structure name and enter that name into the driver parameter dialog box.
You could enter the message structure directly in the edit field of the driver parameter dialog box. But because the message structure is a large array, direct entry becomes cumbersome easily.
A better way is to define the message structure as a variable in the MATLAB workspace and pass the variable name to the driver. For example, to initialize an external A/D module and acquire a value during each sample interval, create a script file with the following statements:
Message(1).senddata='InitADConv, Channel %d' Message(1).inputports= Message(1).recdata='' Message(1).outputports= Message(2).senddata='Wait and Read converted Value' Message(2).inputports= Message(2).recdata='%f' Message(2).outputports=
This approach is different from other Simulink Real-Time driver blocks:
The script containing the definition of the message structure has to be executed before the model is opened.
After creating your Simulink model and message script, set the preload function of the Simulink model to load the script file the next time you open the model. In the Command Window, type
set_param(gcs, 'PreLoadFcn', 'script_name')
When you move or copy the model file to a new folder, you must also move or copy the script defining the message structure.
During each sample interval, the driver block locates the message structure, interprets the messages, and executes the command defined by each message.
For detailed information on the fields in a message structure, see the following topics:
You can save complete model simulation states while simulating, on a development computer, a Simulink model that contains some Simulink Real-Time blocks. The software does not support this behavior when executing such a model on the target computer.
For this operation, set the Save complete SimState in final state check box in the Data Import/Export pane of the Configuration Parameters dialog box. If your model contains the following blocks, you cannot save complete model simulation states while simulating on the development computer.
Async Buffer Read
Async Buffer Write
Baseboard Serial F
Bit Packing (Utilities library)
Bit Unpacking (Utilities library)
Byte Packing (Utilities library)
Byte Unpacking (Utilities library)
Commtech Fastcom® 422/2–PCI
Commtech Fastcom 422/2–PCI F
Commtech Fastcom 422/2–PCI-335
Commtech Fastcom 422/2–PCI-335 F
Commtech Fastcom 422/4–PCI-335
Commtech Fastcom 422/4–PCI-335 F
Condor® 1553 BC List
Create Ethernet Packet (Ethernet library)
FIFO bin read
FIFO ASCII read
Quatech DSCP-200/300 F
Quatech ESC-100 F
Quatech QSC-100 F
Quatech QSC-200/300 F
To prevent these messages, clear the Save complete SimState in final state check box in the Data Import/Export node of the Configuration Parameters dialog box.
In PWM and FM driver blocks, your control over the output frequency and duty cycle is not precise. Although the base frequency value is exact, the way the base frequency is selected affects the output frequency and duty cycle.
At the beginning of each sample time, the block reads the current
input signal values. It then computes two unsigned 16-bit integers,
from the signal values and the block parameters. During the sample
time, the block holds the output signal:
m cycles of the base frequency
Low for the next
High for the next
. . .
For a base frequency
b, this algorithm results
in a rectangular output signal of frequency
be integers, it is not possible to provide a continuous range of output
frequencies and duty cycles with perfect exactness.
For example, assume that you want to configure an FM block with
a duty cycle (
f to this block is a relative frequency
that specifies an output frequency of
b × f.
n must be integers.
Therefore, it is not always possible
to find values of
m/n = 1/2) such that:
f = b/n
n = 2 * m
1/8, and so forth. The output frequencies for the intervening input signal
fvalues are approximate. The errors are smaller as
0and larger as
To achieve the smallest margin of error, select the largest
possible base frequency. The fact that
be 16-bit integers imposes a lower limit of:
on the frequencies that can be generated using a given base frequency.
The typical Simulink Real-Time block documentation briefly describes the supported board, then describes the parameters for each of the blocks that support the board. Included in the documentation for each board is a board characteristics table. Board characteristics tables can include the following information:
|Board name||Name of the board supported by the blocks. For example, National Instruments® PCI-6221.|
|Manufacturer||Manufacturer of the board. For example, National Instruments.|
|Bus type||Bus that is used by the board. For example, PCI or ISA (PC/104).|
|Access method||Whether the board is memory mapped or I/O mapped.|
|Multiple block instance support||Whether you can use multiple blocks for the same function on the same board. For example, different blocks for different channels of an A/D device.|
|Multiple board support||Whether you can use multiple boards of the same type in one real-time application.|