> 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/pe-add-on-simulink/examples/circuit-model-scenarios.md).

# Circuit Model Scenarios

## **Description**

This example demonstrates the **Scenarios feature** and how it can be used to modify the characteristics of passive elements in the Circuit Model during the simulation.

The example is available as two separate VeriStand projects, one providing support for the PXIe-7868R FPGA card and the other for the PXIe-7891 FPGA card. Both projects demonstrate the same concepts and behave almost identically.

## Detailed explanation

A simple voltage divider circuit is loaded and pre-configured with a set of scenarios containing different resistance values for each of the two resistors R1 and R2. During the simulation, you can toggle between scenarios to observe the effects of modifying R1 and R2.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FJtJt0zHpFjZsgK0RJNPg%2Fimage.png?alt=media&amp;token=6a46eb85-fb5d-4515-bed3-7e3f67f943e5" alt=""><figcaption><p><em>Voltage divider circuit used in the circuit model scenarios example.</em></p></figcaption></figure>

The circuit model used in this example contains **Measurements** allowing monitoring of the input voltage (Vin), output voltage (Vout), and current (I) of the simulated voltage divider.

In power-electronics HIL applications, scenarios are often used to simulate fault conditions, such as the shorting of an IGBT in an inverter. See [How to Simulate IGBT-Level Faults in a Two-Level Inverter Using eHS](https://portal.opal-rt.com/Knowledge-Base/Article?id=8db8144d-9356-ef11-bfe3-002248b1d264) for more information.

## Configuration

<details>

<summary><strong>Hardware Configuration</strong></summary>

* In the Configuration Tree, expand **Controller >> Custom Devices** and click the **Power Electronics Add-On** custom device to open its configuration page.
* The **Hardware Configuration** selected in the **Configuration** dropdown depends on the FPGA card targeted by the project. Note that this example could be re-created using any Hardware Configuration containing an eHS solver.

<table><thead><tr><th width="199.88897705078125">NI FPGA Card</th><th>Hardware Configuration</th></tr></thead><tbody><tr><td><strong>NI PXIe-7868R</strong></td><td>eHSx32_6_Ph_PMSM_BLDC_IO_32DO_7868R</td></tr><tr><td><strong>NI PXIe-7891</strong></td><td>eHSx64_Dual_6_Ph_PMSM_VDQ_IO_7891</td></tr></tbody></table>

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2Fvb13kRyHv9100HABVsKL%2Fimage.png?alt=media&amp;token=b3cafd52-e8e6-4642-a96f-937675831ba4" alt="" width="563"><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Circuit Model and Scenarios</strong></summary>

In this example, the **Circuit Model** represents a simple voltage divider that includes a set of **predefined scenarios**. Each Scenario specifies a different combination of resistance values for the two resistors in the circuit, R1 and R2.

* In the Configuration Tree, expand **Power Electronics Add-On** and click **Circuit Model.**
* The **Circuit Model File Path** points to the currently loaded Circuit Model. Open the file in Simulink to observe the circuit.
* Under **Scenario Configuration**, the **Use Scenarios?** parameter is enabled. A VeriStand channel called **Scenario Index** has been automatically added to the tree.
* The **Scenarios File Path** points to the currently loaded scenarios file. Open the file in a spreadsheet editor to observe the scenarios and modify them, if desired. See **How to Use the Scenarios Feature** for more information.
* *(optional)* Click the **Refresh** button to see additional model information, including the **Maximum Number of Scenarios** supported by the circuit model and the **Number of Scenarios Used** by the currently loaded Scenarios file.

**Circuit Model File Path:** *\<Circuit Model Scenarios>\Circuit Model\Voltage\_Divider.slx*

**Scenarios File Path:** *\<Circuit Model Scenarios>\Scenarios\Circuit\_Model\_Scenarios.xls*

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FTQ4H2psM2KnXGXsqBAqM%2Fimage.png?alt=media&amp;token=ddcb12f9-4fea-448d-951e-ee4e39cf753b" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FFW41ZmuzqQYxYmJNui97%2Fimage.png?alt=media&amp;token=a7c12778-a4e1-46cd-8cd2-c4e11b6f18df" alt="" width="543"><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Sources</strong></summary>

The **Sources page** maps signals to each source of the circuit model. In this example, a **Sinewave Generator** is used to control the input voltage of the voltage divider.

* In the Configuration Tree, expand **Circuit Model** and click **Sources**. This page is populated with a list of sources from the circuit model.
* The mappings are configured as shown below, with **SWG00** mapped to **Vsource**.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2F28NT2WrK5jCozHCwNiLD%2Fimage.png?alt=media&amp;token=92fabf45-443a-4d2e-9a7b-1e8df9d5a9a7" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Switches</strong></summary>

The **Switches page** maps signals to each switch of the circuit model. Because the voltage divider circuit model contains no switches, the eHS solver has automatically generated a dummy switch that does not affect the behavior of the simulation.

* In the Configuration Tree, expand **Circuit Model** and click **Switches**. This page is populated with a list of switches from the circuit model.
* Any signal can be mapped to the dummy switch.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FzV1cFKdWyzDygSZBnxmd%2Fimage.png?alt=media&amp;token=522fc0e4-9599-41fd-b37e-b03f96c41503" alt="" width="563"><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Sinewave Generators</strong></summary>

The default parameters of the **Sinewave Generator** mapped to **Vsource** are configured at edit-time. Because the parameters are VeriStand channels, they can also be modified during the simulation.

* In the Configuration Tree, expand **Circuit Model** >> **Sinewave Generators**
* In this example, the default values of the **Frequency Engines** and of **SWG 0** are configured as shown below.

| Frequency Engines - Channel Name | Default Value |
| -------------------------------- | ------------- |
| **Frequency Engine 0**           | 60Hz          |

| SWG 0 - Channel Name | Default Value |
| -------------------- | ------------- |
| **Frequency Engine** | 0             |
| **Phase**            | 0º            |
| **Amplitude**        | 10 V          |
| **Offset**           | 0             |

</details>

<details>

<summary><strong>Waveform Channels</strong></summary>

**Waveform Channels** allow signals to be streamed from the FPGA at a rate faster than that of the CPU execution.

* In the Configuration Tree, expand **Circuit Model** and click **Waveforms**.
* The signals in the example are mapped to the Waveform channels as shown below. The data from these channels will be streamed at the **Sample Rate (S/s)** specified at the bottom of the page.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FyeCmSsDL0pVeZlXldUGn%2Fimage.png?alt=media&amp;token=e08b762c-de4d-407d-a528-dd5b1c0fb3ba" alt="" width="563"><figcaption></figcaption></figure>

</details>

## Simulation

Open Circuit Model Scenarios.nivsscr and observe the relationship between the Vout and Vin signals, as well as the Voltage Divider Current (I) displayed in the second graph.

Modify the Frequency, Amplitude, and Offset parameters of the Source Voltage to observe their effects on Vout and I.

The scenario Resistances table in the grey box shows the R1 and R2 resistance values defined for each Scenario. Scroll through the Scenario Index values to observe the effects of the changing resistances on the output voltage of the circuit Vout.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FdbRs5GDxDsTQuSFsNmSS%2Fimage.png?alt=media&amp;token=3eac9793-5f85-4da9-8450-2d33fe5873a9" alt=""><figcaption><p>VeriStand Screen for the Circuit Model Scenarios example</p></figcaption></figure>

### Comparing Offline Results

The circuit model file used in this example contains additional blocks not parsed by the eHS solver. These allow the model to be run directly in Simulink so that the offline results can be compared with those obtained in the Real Time simulation.

Open the circuit model file in Simulink and click Run to start the offline simulation. Double-click the grey Scope block to view the output signals Vin, Vout, and I. The source voltage parameters and the R1 and R2 resistance values used in the offline simulation are defined in the file ParameterInitialization.m. They can be modified directly in that file, or from the MATLAB Workspace.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2Fl8MUowyXJqTBGNEJm4zH%2Fimage.png?alt=media&amp;token=b79435b2-ce1b-4a10-9765-73dd65800255" alt=""><figcaption><p>Voltage_Divider.slx</p></figcaption></figure>


---

# 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/pe-add-on-simulink/examples/circuit-model-scenarios.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.
