> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/rt-lab/configure-ios/analog-digital-and-sfp-ios/s-function-workflow.md).

# S-Function Workflow

The **S-Function Workflow** uses Simulink blocks from the ***Opal-RT** > **Common*** **sub-library** within the [RT-LAB I/O library](https://github.com/Opal-RT-Technologies/product-docs-rt-lab/tree/main/.gitbook/simulink-blocks-reference/rt-lab-i-o-library/README.md). **It is the recommended approach for most applications.**

{% stepper %}
{% step %}

### Prepare the model directory

Copy the **bitstream files** (`.bin` and `.conf`) provided with your system to the model folder. These files are typically found on the USB drive or CD under *Test Models > RT-LAB Project*.

* The `.bin` file configures the FPGA to recognize the locations of each I/O module in the simulator. If modules are moved, a new bitstream is required.
* The `.conf` file provides a clear text-based mapping between each `DataIn` and `DataOut` port in your RT‑LAB model and the corresponding I/O module. It specifies details such as I/O type, slot, section, subsection, signal count and bit size.
* **Do not rename bitstream files**, as their naming convention is critical for correct operation.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-744493754e737ef5bf257233600bb6b8db6fb267%2FDR-sfunction-bitstream.png?alt=media" alt="" width="458"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Add the **OpCtrl** block

The **OpCtrl** block is required whenever the simulator FPGA is used; for example, when the model interacts with external hardware or a DUT through the simulator's I/O modules.

From *RT-LAB I/O > Opal-RT > Common*, add the block to the real-time subsystem where signals will be exchanged through I/O modules (**SM\_** or **SS\_**), and configure the following parameters:

* **Primary Bitstream Filename** – Select the correct `.bin` file.
* **Board Type** – Identify from the bitstream filename.

All other parameters can remain at their default values **unless you are working with multiple FPGA systems or external synchronization**.
{% endstep %}

{% step %}

### Add Analog I/O blocks (if applicable)

From *RT-LAB I/O > Opal-RT > Common*, add **AnalogIn** and/or **AnalogOut** blocks to the real-time subsystem (**SM\_** or **SS\_**). Each block supports up to 8 channels (Channels 0–7 **or** 8–15 on the I/O module).

**AnalogIn block**

* Reads voltage signals from the physical I/O module into Simulink.
* Each signal is expressed in volts (1 V from the module = 1 in the model).
* Configure the **`DataOut` port number** according to your **System Description Document** or `.conf` file. For a module in a given location, two `DataOut` port numbers are available: the smaller number corresponds to channels 0–7, and the larger number corresponds to channels 8–15.
* By default, the output is an 8-element vector. Changing the **Number of Ain channels** parameter adjusts the vector size. Use a **Demux** block to separate the vector into individual signals.

**AnalogOut block**

* Sends voltage signals from the model to the physical I/O module.
* Each signal is expressed in volts (1 in the model = 1 V output).
* Configure **`DataIn` port number** according to your **System Description Document** or `.conf` file.
* By default, the input is an 8-element vector. Adjusting the **Number of Aout channels** parameter changes the vector size. Use a **Mux** block to combine individual signals into a single input vector.
  {% endstep %}

{% step %}

### Add Digital I/O blocks (if applicable)

From *RT-LAB I/O > Opal-RT > Common*, add Digital I/O blocks to the real-time subsystem (**SM\_** or **SS\_**). Each block supports up to 8 channels (Channels 0–7, 8–15, 16-23, **or** 24-31 on the I/O module).

Three type of digital I/O exists:

* Static **DigitalIn** / **DigitalOut**: Measures or generates a single 0/1 state per channel at each model time step. Commonly used for control elements such as breakers.
* Pulse width modulated **PWM In / PWM Out**: Measures or generates a single PWM frequency and duty cycle per channel at each model time step. Commonly used for high-frequency PWM signals.
* **EventDetector / EventGenerator**: Captures up to 250 transitions or generates up to 250 precise PWM events, optimized for high-frequency signals.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-f1b1303d8e9e027ebb26a4d658d3c82ce15882ea%2FDR-digitals2.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
Most digital output modules require an external DC power source. Verify voltage ranges in the I/O module specifications to ensure safe operation.
{% endhint %}

* For each block in the model, configure its **`DataOut`** or **`DataIn` port number** according to your **System Description Document** or `.conf` file.
* By default, each block’s ports are 8-element vectors. Adjusting the **Number of channels** parameter changes the vector size. Use a **Demux** to separate vectors into individual signals, and a **Mux** block to combine individual signals into a single input vector.
  {% endstep %}

{% step %}

### Add SFP I/O blocks (if applicable)

From *RT-LAB I/O > Opal-RT > Common*, add **DataOut Recv** and/or **DataIn Send** blocks to the real-time subsystem (**SM\_** or **SS\_**). For each block, configure its **`DataOut`** or **`DataIn` port number** according to your **System Description Document** or `.conf` file.

Each **`DataOut`** port corresponds to one SFP **RX** channel, and each **`DataIn`** port corresponds to one SFP **TX** channel. Each channel (RX or TX) supports up to 250 32‑bit data words.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-59efacfdc290c01b5a524cc2f1b033057ed83112%2FDR-rtlab-sfunction-sfp.png?alt=media" alt=""><figcaption></figcaption></figure>

These blocks are typically connected to [Convert double to Single (FPGA)](https://www.opal-rt.com/docs/rt-lab/simulink-blocks-reference/rt-lab-library/convert-double-to-single-floating-point-fpga.md) or [Convert Single (FPGA) to Double](https://www.opal-rt.com/docs/rt-lab/simulink-blocks-reference/rt-lab-library/convert-single-floating-point-fpga-to-double.md) blocks to convert signals between FPGA (single precision) and model (double precision) formats.
{% endstep %}

{% step %}

### Add other I/O blocks (if applicable)

Available options depend on the installed hardware and the **supplied** **bitstream**. Refer to your **System Description Document** for details, then use the appropriate Simulink blocks from the ***Opal-RT** > **Common*** sub-library in the [RT-LAB I/O library](https://www.opal-rt.com/docs/rt-lab/simulink-blocks-reference/rt-lab-i-o-library.md).
{% endstep %}

{% step %}

### Save and run the Simulink model

Save and run the Simulink model to confirm that everything works as expected.
{% endstep %}

{% step %}

### Prepare the Hardware setup

Refer to the **Connect Analog & Digital I/Os** section of your simulator and/or expansion unit documentation for detailed instructions on connecting external hardware or a DUT through its I/O modules.
{% endstep %}

{% step %}

### Build, load and execute the model in RT-LAB

1. In RT-LAB, build the model.
2. Go to the **Execution** tab and ensure that the **Real-time simulation mode** is set to **Hardware synchronized**.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-1d02ffd8d756374940dcab0414d35383d4e16c6f%2FDR-hardware-synchronized.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Open the **Assignation** tab and ensure that the **XHP** box is checked (enabled).
4. Load and execute the model in RT-LAB.
   {% endstep %}
   {% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/rt-lab/configure-ios/analog-digital-and-sfp-ios/s-function-workflow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
