S-Function Workflow

Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

S-Function Workflow

Page Contents+


Workflows

When building models in RT-LAB, there are two main workflows for linking the simulation’s software inputs and outputs with the physical hardware I/Os:

  1. S-Function workflow – Uses Simulink blocks exclusively.
    This workflow is explained in this page.

  2. OPAL-RT Boards workflow – Combines Simulink blocks with additional configuration through the RT-LAB interface.
    This workflow is explained here: OPAL-RT Board - Overview

Each method offers distinct advantages that become clearer as the user becomes familiar with the workflows.
The optimal choice depends on the user's preferences and the specific needs of the project.

S-Function Workflow

The S-function workflow has at its center four elements:

  • Simulink model – Contains the I/O blocks.

  • .bin bitstream file – This file is required and must be placed by the user in the same folder as the Simulink model. It contains the FPGA data necessary for simulation.

  • .conf configuration file – This file is used by both the user and the Simulink model and should also be placed in the same folder as the model (by the user).

  • Simulink Opal-RT I/O Library – This library is automatically added to your MATLAB Simulink block library upon RT-LAB installation. It contains blocks that handle the transmission and reception of Simulink signals to and from the real-world electrical signals of the simulator’s I/O cards.

    image-20250513-190352.png

     

Getting Started with the S-Function Workflow

  1. Identify the I/O cards installed in your simulator.
    Refer to the hardware overview in your simulator’s System Description Document. Make note of each card’s slot and module number (e.g., 1A, 1B, 2A, 2B).

  2. Open the Simulink model to which you want to add I/O blocks. Navigate to your real-time subsystem (SM_ or SS_).

  3. Ensure that the .bin and .conf files provided with your system (via USB drive or DVD) are located in the same directory as your Simulink model.

  4. Navigate to: RT-LAB I/O > Opal-RT > Common.
    If this path is not visible, you can add the library by following the procedure described in the knowledge base article: Bad Link Errors, Missing OPAL-RT Libraries / Toolboxes and Linking Issues After Restarting MATLAB

  5. Locate the OpCtrl block and add it directly into your real-time subsystem (SM_ or SS_).

     

     

  6. Configure the internal parameters of the OpCtrl block as follows:

    image-20250514-144543.png

     

    If you are unsure about your Board ID number (also known as the Board Index), there are several ways to find it::

    1. Scan the FPGA in RTLAB:

       

    2. Consult your documentation, particularly the FPGA section.

    3. Check the DIP switch on your simulator. If you're unsure where it is located, refer to the hardware documentation or prioritize the first two methods above.

  7. Add an I/O block from the Simulink Library Browser to your model’s real-time subsystem.
    You can select any I/O block type, provided that your physical simulator has one or more.
    For this example, we will use an Analog Out block.

     

  8. Configure the I/O block according to your bitstream configuration .conf file (also shown in the System Description Document):

    1. Open your .conf file in any text editor (e.g., Notepad, MS Word, or MATLAB)

    2. Locate the row(s) corresponding to the physical I/O card you want to use.
      For example, if your Analog Out card is installed in slot 1A, find the row(s) for Slot 1 Section A.

       

    3. Determine which physical channels you want to use for output.
      In this example, we’ll output signals from Channel 0 to 7.
      Each subsection represents a group of 8 channels:

      • Subsection 1: Channels 0–7

      • Subsection 2: Channels 8–15

      • And so on.

      Since the Analog Out card in slot 1A has 16 channels, it supports two subsections:

      • Subsection 1 = Channels 0–7

      • Subsection 2 = Channels 8–15

      Therefore, we select the row labeled Slot 1 Section A Subsection 1.

    4. Find the value in the PortName column that intersects with the selected row.
      For example, if the value is DataIn19, then you will enter 19 into the corresponding configuration field of the Analog Out block in Simulink.

    5. Click OK to confirm.
      The block should now display: Slot 1 Module A Subsection 1.

Final Steps

  • In Simulink, connect the input of the Analog Out block to any Simulink signal that you wish to output.

  • Note: The Analog Out block’s physical output is limited to a maximum amplitude of 16 Volts.

For more information on the other blocks in the RT-LAB I/O > Opal-RT > Common library, visit: RT-LAB Common Blocks Documentation

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323
Follow OPAL-RT: LinkedIn | Facebook | YouTube | X/Twitter