Documentation

Use I/O Driver Blocks

Simulink® Desktop Real-Time™ I/O driver blocks allow you to select and connect specific analog channels and digital lines to your Simulink model through I/O driver blocks. These blocks provide an interface to your physical I/O boards and your real-time application. They enable the C code created by Simulink Coder™ code generation software to map block diagram signals to the corresponding I/O channels. All I/O blocks support all applicable Simulink data types.

You can have multiple I/O blocks associated with each type of I/O board. For example, you can have one Analog Input block for channels 1–4 and another block for channels 5–8. Each I/O block in a model specifies its own block configuration parameters, which apply only to that instance of that block.

The capability of an I/O driver block is available only if the corresponding I/O hardware device supports that capability. For example, data-oriented devices like Serial Port and File support packet and stream I/O blocks. However, data acquisition devices do not support the packet and stream I/O blocks.

The Simulink Desktop Real-Time Library provides blocks that you can use with supported I/O boards. You can also create your own I/O blocks to work with Simulink Desktop Real-Time software. See Custom I/O Driver Basics for details.

View Simulink Desktop Real-Time Library

I/O driver blocks are available in the Simulink Desktop Real-Time Library. To view this library from the MATLAB® Command Window, type:

sldrtlib

To view the Simulink Desktop Real-Time Library from a model:

  1. In the model window, click View > Library Browser.

    The Simulink Library Browser opens. The left pane shows a hierarchy of libraries and categories, with the Simulink library at the top. The right pane shows the blocks available in the category selected on the left.

  2. In the left column, double-click Simulink Desktop Real-Time.

The Simulink Desktop Real-Time library opens.

You can add an I/O block in the library to your Simulink model by dragging it from the library to the model. After you add the block, connect it to your model as you would any other block, and provide block configuration parameter values.

Route Signals from an I/O Block

I/O driver blocks output multiple signals as a vector instead of individual channels or lines. To connect the individual channels and lines to parts of your Simulink model, separate the vector with a Demux block.

After you add and configure an I/O driver block in your Simulink model, you can separate and connect the output signals from the blocks:

  1. In the Simulink window, click View > Library Browser.

    The Simulink Library Browser opens.

  2. In the Simulink library, click Signal Routing. From the list in the right pane, click and drag Demux to your Simulink model.

  3. Double-click the Demux block. The Block Parameters: Demux dialog box opens. Enter the number of lines leaving the Demux block. For example, if you entered three channels in the Analog Input block, enter 3 in the Number of outputs box.

  4. Click OK.

  5. Connect the Analog Input block to the Demux block input.

  6. Connect each of the Demux block output lines to the input of other blocks.

  7. In the Simulink window, click Display > Signals & Ports > Wide Nonscalar Lines.

  8. Click Display > Signals & Ports > Signal Dimensions.

Note

In this example, inputs 1 and 2 are not connected, but they could be connected to other Simulink blocks.

Configure Channel Selection

To show how to specify device settings when using both analog and digital signals, this example uses the Keithley® Metrabyte™ DAS-1601 I/O board. The following is a specification summary of the DAS-1601 board:

  • Analog input (A/D) — 16 single-ended or 8 differential analog inputs (12-bit), polarity is switch configured as either unipolar (0–10 volts) or bipolar (± 10 volts). Gain is software configured to 1, 10, 100, and 500.

  • Digital input — Four unidirectional digital inputs

  • Analog output (D/A) — Two analog outputs (12-bit). Gain is switch configured as 0–5 volts, 0–10 volts, ± 5 volts, or ± 10 volts

  • Digital output — Four unidirectional digital outputs

  • Base address — Switch configured base address

This section explores different configurations for input signals.

Once an Analog Input block has been placed in the model and the I/O board selected and configured, you can set up the Analog Input block to handle input signals.

Single analog input — The most basic case is a single analog input signal that is physically connected to the first analog input channel on the board. In the Block Parameter: Analog Input dialog box, and the Input channels box, enter:

1 or [1]

The use of brackets is optional for a single input.

Input vector with differential analog — Number the analog channels from channel 1 up to the maximum number of analog signals supported by the I/O board.

In the case of the DAS-1601, when configured as differential inputs, eight analog channels are supported. The analog input lines are numbered 1 through 8. The complete input vector is:

[1 2 3 4 5 6 7 8] or [1:8]

If you want to use the first four differential analog channels, enter

[1 2 3 4]

Input vector with single-ended analog — Assume that your DAS-1601 board is configured to be single-ended analog input. In this case, 16 analog input channels are supported. The complete input vector is:

[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] or [1:16]

To use the first four single-ended analog input channels, enter:

[1 2 3 4] or [1:4]

The next figure shows the resulting block diagram.

Do not specify more channels than you actually use in your block diagram. Specifying unused channels results in additional overhead for the processor with A/D or D/A conversions. In this case, for example, even though some channels are not used in the block diagram, these channels are still converted.

You could attach terminator blocks to channels 4 and 5 inside your block diagram after passing the Analog Input block vector in to a Demux block. Adding terminator blocks provides you with graphical information in your block diagram that clearly indicates which channels you connected and which are available. The penalty is that even the terminated channels are converted, adding some computational overhead.

The next figure shows the block implementation.

Depending on the board and the number of channels used, I/O conversion time can affect the maximum sample rate that can be achieved on your system. Rather than converting unused channels, specify only the set of channels that your model actually requires.

Was this topic helpful?