> 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/dfim-control.md).

# DFIM Control

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

This model illustrates the closed-loop control of eFPGASIM-based Doubly Fed Induction Machine (DFIM) using back-to-back PWM converters built with 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 DFIM and the converter are simulated on FPGA and the controller on CPU in real time. RT-Lab model is 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** equivalent model “SPS\_DFIMref\_2015a” is also provided along with these models for the users reference. This model needs the “ssn\_dfim\_windturbine\_init” 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.

## Detailed explanation

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 DFIM i.e. “Generic Machine”, converter interface i.e. “eHS CPU Block” and controls for back-to-back PWM converters.
* The **console subsystem** is used to control set points, like magnitude and frequency of source voltages, speed reference and mechanical torque during real time simulation. Also, users can monitor voltages, currents, machine torque and speed of the machine at any point of time during simulation. For this example the roles of each set point are as follows:

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

where:

* Vdc\_Ref: This sets the DC bus reference voltage for the outer loop of grid-side converter control.
* Kp Ki rotor: These are the Kp and Ki values of outer loop active and reactive power control of the rotor-side converter control.
* Kp Ki DC-link: These are the Kp and Ki values of inner loop active and reactive power control of grid side converter control.
* Iq\_related: This generates an Iq reference value manually when PQ control of rotor side converter is disabled.
* P ref: This block is used to set reference active power in PU to the rotor side converter outer loop control. This block holds a feature of generating reference value as a constant or a square wave with perturbation or a triangular wave with perturbation.
* Q ref: This block is used to set reference reactive power in PU to the rotor side converter outer loop control
* PQ\_Control: This block, upon setting a value of 0, enables all controls with respect to back-to-back PWM converters. It disables active and reactive power control of rotor side converter upon setting its value to 1. The value of Iq is given manually from “Iq\_related”.
* Rotor speed: The rotor speed of DFIM is set in per unit.
* Rotor speed type: The rotor speed continuously varies between sub and super synchronous mode upon setting a value 0. If the value is set to 1 then the speed mentioned in “Rotor speed” is considered.
* Frequency: Grid frequency

**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\_DFIM” is built by keeping the conventions of sources, switches, and measurements compatible with solver requirements. A total of 7 current/voltage sources are needed by the eHS circuit, three of them are generated and mapped via the RT-Lab model (Vabc grid0), and the last four are the current feedback from the machine model (Current Source Ia\_stator, Ib\_stator, Ia\_rotor and Ib\_rotor). The convention to follow in the eHS solver “Input Settings” tab is shown below.

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

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-3b8d84cbcf75d94b8fe7cde84643edf5566127fc%2Fehs-model-sps-dfimcontrol-3.png?alt=media" alt=""><figcaption></figcaption></figure>

When the model is compiled in Simulink, the configuration of the eHS solver will be generated according to the SPS Software (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.

The **generic machine** available in the eFPGASIM library has the capability to solve four motors with hardware. This machine model 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 is the necessary information to configure DFIM.

* Data In Port Number 29
* Load In Port Number 20
* Data Out Port Number 11

**Back-to-back converter control** of DFIM is implemented on the CPU, which runs at a sampling time of 20 microseconds.

**Rotor side converter (RSC)** shown below provides the excitation for the induction machine rotor. With this PWM converter it is possible to control the torque, hence the real power, and power factor at the stator terminals. The DFIM is controlled in a synchronously rotating dq axis frame, with the “d” axis oriented along the stator flux vector position. In this way a decoupled control between the electrical torque and the rotor excitation current is obtained. Consequently, the active and reactive power are controlled independently.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-160954d0c699500279614bc69622a4d0e86cc4f8%2Fehs-model-wind-turbines-6.png?alt=media" alt=""><figcaption><p>Reference: Dr. John Fletcher and Jin Yang “Introduction to Doubly-Fed Induction Generator for Wind Power Applications”</p></figcaption></figure>

**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 2000 Hz and the number of events chosen is 10. Exchange of information between the controller and plant happens within the software model.

## Simulation and results

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>>DFIM**.
2. Compile the RT Model by clicking on **Build** in RT-LAB.
3. 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.

{% hint style="info" %}
To run this example, user needs to ensure that the RT-Lab model and eHS model are present in the same folder.
{% endhint %}

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.

### 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 DFIM, 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%2Fgit-blob-344c05cf57732fb37fc76bc42c8689ae224795d8%2Fehs-model-spsPMSMSH-1.png?alt=media" alt=""><figcaption></figcaption></figure>

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

### 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%2Fgit-blob-d621d45f44e920a4bd3880eaab10a85db1441f88%2Fehs-model-sps-PMSMfoc-2.png?alt=media" alt=""><figcaption></figcaption></figure>

### Run the model without IO configuration \[Software-in-the-loop]

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. Set reference active power in PU to the rotor side converter controller **P ref** in the console.
2. Set reference reactive power in PU to the rotor side converter controller **Q ref** in the console.
3. Set Vdc reference to the grid side converter controller **Vdc\_Ref** in the console.

The user also has the option to play with the rotor speed mode and the nature of reference real power from the console.

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.

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

Tor run this model

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

```matlab
efsOpenExample('DFIM_IOs_rtlab');
```

{% endcode %}

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 (formerly SimPowerSystems) model describing the circuit to be solved.
2. 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 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-3c6352646ec3630f2444d685acc827c4cd426ecd%2Fehs-model-sps-dfimcontrol-8.png?alt=media" alt=""><figcaption></figcaption></figure>

* “Analog Output Mapping and Rescaling block Control Panel” block in the console subsystem is customized 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 following order {'DFIM1.Ias', 'DFIM1.Ibs', 'DFIM1.Ics', 'DFIM1.Iar', 'DFIM1.Ibr', 'DFIM1.Icr'}
* Machine currents are provided to the controller using Analog In (ADC) of the simulator
* “Encoder In” block reads the encoder output and generates speed and angle information of the machine shaft.
* 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.

4. 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. Set reference active power in PU to the rotor side converter controller **P ref** in the console.
2. Set reference reactive power in PU to the rotor side converter controller **Q ref** in the console.
3. Set Vdc reference to the grid-side converter controller **Vdc\_Ref** in the console.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-d34e2eeb052872e34101ab45281b45234bf4e6a8%2Fehs-model-sps-dfimcontrol-5.png?alt=media" alt=""><figcaption><p><em>Reference and measured active and reactive power captured on an oscilloscope.</em><br><em>The top one corresponds to active power and the bottom one corresponds to reactive power.</em></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/rt-lab/example-models/ehs-example-models/sps-software-example-models/machines-models/dfim-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.
