I/O Driver Blocks

The Simulink® Real-Time™ environment is a solution for prototyping and testing real-time systems using a desktop computer. In support of this, 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 I/O Modules

Speedgoat real-time target machines are available with a number of I/O modules. See Speedgoat I/O Modules.

Third-Party Driver Blocks

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.

I/O Driver Block Library

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 web site, see:

To find latency values for Speedgoat boards, contact Speedgoat technical support.

The Simulink Real-Time system supports PCI and ISA buses. If the bus type is not indicated in the driver block number, you can determine the bus type of a driver block by checking the block's parameter dialog box. The last parameter is either a PCI slot, for PCI boards, or a base address, for ISA boards.

You can open the I/O device driver library with the MATLAB® command slrtlib. The library 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 then displays the set of I/O device driver blocks for the specified I/O functionality (for example, A/D, D/A, Digital Inputs, Digital Outputs, and so on).

When you double-click one of the blocks, a Block Parameters dialog box opens, allowing you to enter system-specific parameters. Parameters typically include

  • Sample time

  • Number of channels

  • Voltage range

  • PCI slot (PCI boards)

  • Base address (ISA/104 boards)

Memory-Mapped Devices

The Simulink Real-Time software 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 that supported by the Simulink Real-Time software. You must select an address range supported by both the device driver and the Simulink Real-Time software.

ISA Bus I/O Devices

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.

PCI Bus I/O Devices

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. The user does 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 0, the driver uses the board in bus 0, slot X. 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 0. If the board is not able to locate this slot in the target computer, your real-time application will generate an error message after downloading.

If this additional entry is set to a value equal to or greater than 0, you must be aware of the manufacturer's identification number (Vendor ID) and the board identification number (Device ID) of those 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. An example is shown below:

Bus No.

Device No.

Func. No.

Vendor ID

Device ID

Device Class







IDE controller







Serial bus controller







Unknown PCI device







Display controller


In this example, the third line indicates the location of the Measurement Computing™ PCI-DIO48 board. This is known since the Measurement Computing vendor ID is 0x1307 and the device ID is 0xb. In this case, you can see that the Measurement Computing board is plugged into PCI slot 11 (Device No.), 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.

Simulink Real-Time I/O Driver Structures

Properties for Simulink Real-Time I/O drivers are usually 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 runtime. 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).

What is a message structure? — A message structure is a MATLAB array with each cell containing one complete message (command). A message consists of one or more statements.

First MessageSecond MessageThird Message

Syntax of a message statement — Each statement in a message has the following format:

Structure_name(index).field_name = <field character vector or value>

The field names are defined by the driver, and need to be entered 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.

Creating a message structure — You could enter the message structure directly in the edit field of the driver parameter dialog box. But because the message structure is an array and very large, this becomes cumbersome very 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(2).senddata='Wait and Read converted Value'

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 also need to move or copy the script defining the message structure.

During each sample interval, the driver block locates the structure defined in the Block Parameters dialog box, interprets the series of messages, and executes the command defined by each message.

Specific drivers and structures — For detailed information on the fields in a message structure, see the following topics:

Simulink Real-Time Support and SimState

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.

  • ASCII Encode

  • ASCII Decode

  • Async Buffer Read

  • Async Buffer Write

  • Baseboard Serial

  • 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)

  • Diamond Systems Emerald-MM Serial

  • Diamond Systems Emerald-MM Serial F

  • Diamond Systems Emerald-MM8 Serial

  • Diamond Systems Emerald-MM8 Serial F

  • FIFO bin read

  • FIFO ASCII read

  • FIFO write

  • Quatech® DSCP-200/300

  • Quatech DSCP-200/300 F

  • Quatech ESC-100

  • Quatech ESC-100 F

  • Quatech QSC-100

  • Quatech QSC-100 F

  • Quatech QSC-200/300

  • Quatech QSC-200/300 F

  • UDP Receive

  • UDP Send

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.

PWM and FM Driver Block Notes

In PWM and FM driver blocks, your control over the output frequency and duty cycle is not precise. In particular, these values are affected by the way that the base frequency is selected, as described in this section. The base frequency value is exact.

At the beginning of each sample time, two unsigned 16-bit integers, n and m, are computed based on the block parameters and the current values of the input signals. During the current sample period, the output signal is held high for m cycles of the base frequency, low for the next n-m cycles, high for the next m cycles, and so forth.

For a base frequency b, this results in a rectangular output signal of frequency b/n and duty cycle m/n. Because m and n must 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 (m/n) of 1/2. The input signal f to this block is a relative frequency. It specifies an output frequency of b × f. Because m and n must be integers, it is not always possible to find values of m and n such that f will equal b/n exactly and n will equal 2 × m (duty cycle m/n = 1/2) exactly. Such an exact match is only possible when the input signal f equals 1/4, 1/6, 1/8, and so forth. The output frequencies for the intervening input signal f values are approximate. The errors are smaller as f approaches 0 and larger as f approaches 1.

Hint, to achieve the smallest margin of error, select the largest possible base frequency. The fact that n and m must be 16-bit integers imposes a lower limit of

b / (2161)(1-1)

on the frequencies that can be generated using a given base frequency.

Driver Block Documentation

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 nameName of the board supported by the blocks. For example, National Instruments® PCI-6221.
ManufacturerManufacturer of the board. For example, National Instruments.
Bus typeBus that is used by the board. For example, PCI or ISA.
Access methodWhether the board is memory mapped or I/O mapped.
Multiple block instance supportIf 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 supportIf you can use multiple boards of the same type in one real-time application.

Was this topic helpful?