> 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/example-models/ehs-example-models/sps-software-example-models/machines-models/scim-field-oriented-control.md).

# SCIM Field Oriented Control

## Description

This model illustrates the closed-loop control of eFPGASIM-based Squirrel Cage Induction Machine (SCIM) interconnected to a two level voltage source converter built with an eHS solver. This example is flexible for different real-time simulators, efsChassisSelection drop-down list gives five options in total. This model has a CPU and FPGA as two major processing units. Here, the scim and the converter are simulated on FPGA, and the controller on CPU in real time. Two RT-Lab models are provided to show the exchange of information between the controller and plant:

* Firmware selection for different platforms
* Exchange happening within the software
* Exchange through analog and digital I/O cards present on the simulator

An [SPS Software](https://www.opal-rt.com/docs/smart-power-simulation-software-sps) (formerly Smart Power Systems) equivalent model “SPS\_SCIM\_ref” is also provided along with these models for the users reference. This model needs a “ParameterInitialization” file with this model for initializing parameters.

## Requirements <a href="#requirements" id="requirements"></a>

The RT-LAB, RT-EVENTS, SPS Software and eFPGASIM toolboxes must be installed on the host and target computers in order to run this example model properly.&#x20;

Please refer to the product documentation for details on version compatibility.

## Setup and connections <a href="#setup-and-connections" id="setup-and-connections"></a>

This model must be run with the Hardware Synchronized option and with the XHP mode enabled. The firmware used in this model is generated using the RT-XSG tool, and it can be modified to generate firmware to fit another I/O hardware configuration. The CPU model simulation time step is set to 20 microseconds and all the variables required for eFPGASIM SCIM, eHS power network and controller block are defined in the “ParameterInitialization.m” file which gets loaded during simulation automatically.

* **For the model with I/O configured**, DB37 pin-based analog and digital loop back cables are required to be connected at the rear side of the simulator.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2FLWgMuaXELCEpfhvn95PE%2Fimage.png?alt=media&amp;token=2dc02095-515d-4656-a49b-3b0c8c7e6810" alt=""><figcaption></figcaption></figure>

* **For the model without I/O**, no cables are required.

## Procedure

The following procedure explains how to use the eHS solver and the eFPGASIM-based SCIM with Field-Oriented Control (FOC), helping users understand the workflow and key operating steps.

### Firmware selection

It supports five options, three for OP4510 (325T with eHSx32 and x64 and 410T with eHSx128) while two for OP5700 (eHSx64 and x128).

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2F5hZWpdPVqymDo94Ku3uK%2Fimage.png?alt=media&amp;token=47b60125-ee4c-43e4-945b-6632fb829776" alt="" width="480"><figcaption></figcaption></figure>

### RT-LAB model without IO configuration (Software-in-the-loop)

1. In order to run the example, follow the procedure below:
   1. If eFPGASIM is installed, add the example project to RT-LAB by selecting **File>>New>>RT-LAB Project>>eFPGASIM>>SimPowerSystems\_Workflow>>Machine Models>>SCIM**.
   2. Compile the RT Model by clicking on **Build** in RT-LAB.
2. Verify that the board type is set to TE0741 in the OpCtrl block in the master subsystem of the RT-LAB model. In the “OpCtrl” block, select the “Board ID” corresponding to the hardware on which eHS is executed. To get this information, select “Tools > Get I/O infos” on the target context menu in RT-LAB and find the index of your hardware.
3. To run this example, the user needs to ensure that the RT-Lab model and eHS model are present in the same folder.
4. RT Lab model consists of a master subsystem i.e., “SM\_Controller,” and a console subsystem i.e., “SC\_Console.”
   * The master subsystem has FPGA interface of SCIM, i.e. “Induction Machine”, converter interface i.e. "eHS CPU Block" and Field oriented control of the machine
   * The console subsystem is used to control set points like magnitude and frequency of source voltages, reference speed, mechanical torque and control activation during real time simulation. Also, the user can monitor voltages, currents, machine torque and speed of the machine at any time during the simulation.
5. eHS model consists of a power network and is solved by the eHS solver present in the master subsystem of the RT-Lab model. eHS model “eHS\_SCIM” is built by keeping the conventions of source, switch and measurements compatible to solver requirements. Out of 5 voltage/current sources needed by eHS circuit, three are generated and mapped via the RT-Lab model (Voltage Source Va,Vb and Vc) and the remaining are fed back from the eFPGASIM SCIM stator terminals (Currents Ia and Ib). The eHS solver form factor to be chosen while using is 64. The convention to follow in the eHS solver “Input Settings” tab is shown below. Here, the switch configuration is also shown. The user can choose to send the gating pulses from the CPU or configuring Digital In.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2FOyYhmeNK2qRUQ7gsf1iG%2Fimage.png?alt=media&amp;token=be6b4d6c-ccbd-4d4b-92d7-593e441f549c" alt=""><figcaption></figcaption></figure>

The converter terminal voltage measurements, namely, Y01, Y02, and Y03, are routed to machine terminals internally using the Generic Machine block in the Machine #1 tab with the Configure Inputs button. By doing it this way we ensure a proper loading/coupling between the eHS solver and eFPGASIM machine.

6. When the model is compiled in Simulink, the configuration of the eHS solver will be generated according to the SPS Software circuit characteristics. Elements will be put into matrices and stored into .mat files that will be transferred into the solver when the model is run from the RT-LAB interface. These matrices are generated during model compilation in RT-LAB.
7. The induction machine available in the eFPGASIM library solves only the electrical side of the system, and the mechanical model is computed in the CPU. The converter terminal voltages measured from the eHS solver will feed the machine terminals and similarly, the machine stator currents are fed back to the converter terminals as mentioned in point 5. Following are the necessary information to configure SCIM.
   * Data In Port Number 28
   * Load In Port Number 18
   * Data Out Port Number 9
8. Field Oriented Control of SCIM is implemented on the CPU which runs at a sampling time of 20 microseconds. This has a standard outer loop speed control and inner loop current control implemented. The transformation used is original parks transformation (2/3 factor) with d axis aligned to the phase A axis. RTE\_SPWM block is used to generate PWM pulses for the eHS converter upon activation of control from the console. The modulating waves are clamped to a value between 0 and 1 using a clamping circuit. The carrier frequency is 10kHz and the number of events chosen is 4. Exchange of information between the controller and plant happens within the software model. Machine generated currents, speed and theta information are routed to the controller as an input, and the output of the controller is connected to the eHS solver in RTE format.
9. To run simulations that include eHS solver and eFPGASIM machines in real time, create an RT-LAB project and add the RT-LAB model into the project. The eHS model should not be added to the RT-LAB project, as it does not need to be transferred to the target computer for execution. Compile the model, then assign a target node to run it in real time, then load the model onto it.
10. During real time execution;
    1. To start the control algorithm, give value 1 to PWM\_Enable;
    2. To set the reference speed, give a value between 0 and 2000 RPM to Speed\_Ref;
    3. To add mechanical torque to the machine, give a value between 0 and 150 to Mech\_Torque.

{% hint style="info" %}
To capture the data during real-time simulation, the OpWriteFile block can be used. A mat file is available in the following folder model\_name\model\_name\_SM\_xxxx\OpREDHAWKtarget upon model reset. This .mat file can be used to visualize more accurately the outputs or to compare the results of several simulations together.
{% endhint %}

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2FrSCifqcKAgPPmbZ71AOQ%2Fimage.png?alt=media&amp;token=58da9004-1368-40ab-b2f2-786f27d94081" alt=""><figcaption><p><em>Variation of electromagnetic torque, currents drawn and the shaft speed of SCIM with addition of mechanical load.</em></p></figcaption></figure>

### RT-LAB model with IO Configuration (Hardware-in-the-loop) <a href="#rt-lab-model-with-io-configuration-hardware-in-the-loop" id="rt-lab-model-with-io-configuration-hardware-in-the-loop"></a>

{% hint style="info" %}
Run this demo : efsOpenExample('SCIM\_IOs\_rtlab');
{% endhint %}

The following procedure will help the user understand how to work with the eHS solver and eFPGASIM based SCIM with field oriented control. Hardware-in-the-loop-based RT-Lab model, “SCIM\_IOs\_rtlab”, provided to show the exchange of information between the controller and plant.

1. Click on “Run this demo” on the top of this page (if this page is displayed in the Matlab demo browser). The RT-LAB model using the eHS solver will open automatically, as well as the SPS Software model describing the circuit to be solved.
2. Steps 2 to 8 from the previous section must be repeated to ensure proper configuration of the demo.
3. Unlike the previous model, the exchange of information between the controller and plant happens through analog and digital I/O cards present on the simulator as shown in the figure below.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2FPdyFbteNyKukFzGpH9Z7%2Fimage.png?alt=media&amp;token=c3848935-f4f5-4533-bf5c-77764c94a64a" alt=""><figcaption></figcaption></figure>

4. “Analog Output Mapping and Rescaling block Control Panel” block in the console subsystem is customised to map measurements from the eHS converter as well as signals from the CPU model to the analog out (DAC) card. For this example, analog out channels Ch00 to Ch03 are fixed as the controller expects the inputs in the same order
5. Machine currents are provided to the controller using Analog In (ADC) of simulator
6. “Encoder In” block reads the encoder output and generates speed and angle information of the machine shaft.
7. Firing pulses generated by the controller are sent out via a digital out card present on the simulator and fed back through a digital loop back cable to fire the eHS converter internally.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2F44hj4mSr4Ivl9052bAMG%2Fimage.png?alt=media&amp;token=e0e89fad-e48e-4b92-9f9a-1a40ef42fed7" alt=""><figcaption></figcaption></figure>

* To run simulations that include eHS solver and eFPGASIM machines in real time, create an RT-LAB project and add the RT-LAB model into the project. The eHS model should not be added to the RT-LAB project, as it does not need to be transferred to the target computer for execution. Compile the model, then assign a target node to run it in real time, then load the model onto it.
* During real-time execution;
  1. To start the control algorithm, give value 1 to PWM\_Enable;
  2. To set the reference speed, give a value between 0 and 2000 RPM to Speed\_Ref;
  3. To add mechanical torque to the machine, give a value between 0 and 150 to Mech\_Torque.


---

# 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/example-models/ehs-example-models/sps-software-example-models/machines-models/scim-field-oriented-control.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.
