> 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/srm-speed-control-op5707.md).

# SRM Speed Control - OP5707

## Description <a href="#description" id="description"></a>

The **SRM Speed Control for OP5707** model illustrates the closed-loop control of eFPGASIM-based Switched Reluctance Machine (SRM) interconnected with an individual phase bridge converter built with an eHS solver. This example is based on OPAL-RT's OP5700 real time simulator, which has CPU and FPGA as two major processing units. Here, the SRM and the converters 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:

* Exchange happening within the software
* Exchange through analog and digital I/O cards present on the OP5700 simulator

A **SPS Software** equivalent model “SPS\_SRM\_ref” is also provided along with these models for the users reference. This model needs a “motorsrm” file for initializing the parameters.

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

The **RT-LAB**, **RT-EVENTS**, **SPS Software** (formerly SimPowerSystems) and **eFPGASIM toolboxes** must be installed on the host and target computers to run this example model properly. Please refer to the product documentation for details on version compatibility.

## Simulation and results

### 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 10 microseconds and all the variables required for eFPGASIM SRM, eHS power network and controller block are defined in the “ParametersInitialization.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. Three loop back cables in total are required.
* For the **model without I/O**, no cables are required.

### Run the model without IO configuration \[Software-in-the-loop] <a href="#rt-lab-model-without-io-configuration-software-in-the-loop" id="rt-lab-model-without-io-configuration-software-in-the-loop"></a>

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>>SRM>>OP5700**.
2. Compile the RT Model by clicking on **Build** in RT-LAB.
3. Verify that the board type is set to VC707 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.
4. To run this example, user needs to ensure that the RT-Lab model and eHS model are present in the same folder.
5. RT Lab model consists of a master subsystem i.e. “SM\_SRMeHS” and a console subsystem i.e. “SC\_Console” .
   * The master subsystem has an FPGA interface of SRM, i.e. “Switch Reluctance Motor”, converter interface i.e. “eHS CPU Block” and control of the machine.
   * The console subsystem is used to control set points, like magnitude and frequency of source voltages, speed reference, mechanical torque, and control activation during real-time simulation. Also, users can monitor voltages, currents, machine torque and speed of the machine at any point of time during simulation
6. 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 “SRM\_eHS\_LCA” is built by keeping the conventions of sources, switches, and measurements compatible with solver requirements. Out of 6 voltage/current sources needed by the 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 eFPGASIM SRM stator terminals (Currents Ia, Ib and Ic). The eHS solver form factor to be chosen while using OP5700 is 128. The convention to follow in 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%2Fgit-blob-650c108ff9d8ab20d9ad31ca2017593537bd494d%2Fehs-model-sps-SRM-op5707-1.png?alt=media" alt=""><figcaption></figcaption></figure>

The converter terminal voltage measurements, namely, Y01, Y02, and Y03, are routed to machine terminals internally using machine interface blocks. By doing it this way we ensure a proper loading/coupling between the eHS solver and the eFPGASIM machine. LoadIn port number to configure this block is 27.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-3efe21c7c859fbcdc998c3cc17602ecb7bbe282f%2Fehs-model-sps-SRM-op5707-2.png?alt=media" alt=""><figcaption></figcaption></figure>

7. When the model is compiled in Simulink, the configuration of the eHS solver will be generated according to the [SPS Software](https://opal-rt.atlassian.net/wiki/spaces/PSPS) (formerly SimPowerSystems) 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. Matrices are generated during model compilation in RT-LAB.
8. The SRM available in the eFPGASIM library has the capability to solve two motors with OP5700 hardware. This machine model can solve both the mechanical and electrical sides of the system. 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 SRM.
   * DataIn Port Number 21
   * LoadIn Port Number 25
   * DataOut Port Number 19
9. Speed Control of SRM is implemented on the CPU which runs at a sampling time of 10 microseconds. This has a standard outer loop speed control and inner loop current control implemented. Torque and Currents tables are imported in matrix form with respect to rotor angle, flux and stator currents. RTE\_SPWM block is used to generate PWM pulses for the eHS converter. The modulating waves are clamped to a value between 0 and 1 using a clamping circuit. The carrier frequency is 10000 Hz 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.
10. 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.
11. During real time execution;
    1. To set the reference speed, give a value between 0 and 150 to Ref\_Speed\_rad/s;
    2. To add mechanical torque to the machine, give a value between 0 and 10 to Tmech.

Note: 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.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-aed9da9ebabec30169dd8930d63ae9c2024b5c32%2Fehs-mdel-sps-SRM-op4510-4.png?alt=media" alt=""><figcaption><p><em>Variation of speed, current drawn and electromagnetic torque of SRM with the addition of mechanical load</em>.</p></figcaption></figure>

### Run the 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>

Run this model:

{% code overflow="wrap" lineNumbers="true" %}

```matlab
efsOpenExample('SRM_OP5700_IOs_rtlab');
```

{% endcode %}

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

1. Click on “Run this demo” on the top of this section (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 (formerly SimPowerSystems) 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, exchange of information between the controller and plant happens through analog and digital I/O cards present on the OP5700 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%2Fgit-blob-9bc8527d029d2586920f8955140cb8728a648241%2Fehs-model-sps-SRM-op5707-4.png?alt=media" 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 Ch06 are fixed as the controller expects the inputs in the same order.
5. “DualAngleSensors\_wfaults” block in the master subsystem configures Resolver and Encoder sensors. Cosine, Sine and Excitation outputs of resolver1 can be mapped via an analog out card and Encoder signals are looped back using DB37 connectors via a digital IO slot .
6. Machine currents are provided to the controller using Analog In (ADC) of the simulator.
7. “Encoder In” block reads the encoder output and generates speed and angle information of the machine shaft.
8. 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%2Fgit-blob-9a28fc4897b351453072d5be38ca2ff52fa48574%2Fehs-mdel-sps-SRM-op4510-6.png?alt=media" alt=""><figcaption><p><em>Variation of speed, current drawn and electromagnetic torque of SRM with the addition of mechanical load.</em></p></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 set the reference speed, give a value between 0 and 150 to Ref\_Speed\_rad/s;
2. To add mechanical torque to the machine, give a value between 0 and 10 to Tmech.


---

# 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/srm-speed-control-op5707.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.
