> 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/machine-drive-example-models/pmsm-constant-dq-six-phase-field-oriented-control.md).

# PMSM Constant DQ Six Phase Field Oriented Control

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

The **PMSM Constant DQ Six Phase Field Oriented Control** model illustrates the closed-loop control of a Six Phase Permanent Magnet Synchronous Machine (SixPhasePMSM) with constant DQ parameters, connected to 2 two-level voltage source inverters developed in schematic editor software and solved using the eHS solver. This example is based on OPAL-RT's real-time simulator, which has CPU and FPGA as two major processing units: the SixPhasePMSM and the inverters are simulated on FPGA and the controller is simulated on CPU in real time. One RT-LAB model and one Schematic Editor model is provided to illustrate the exchange of information between the controller and plant.

## Detailed explanation

The RT-LAB model consists of a master subsystem (i.e. "SM\_Controller") and a console subsystem (i.e. "sc\_user\_interface").

* The **master subsystem** has power network interface ("eHS1") and field-oriented control of the machine
* The **console subsystem** is used to control set points, such as speed reference, mechanical torque, and control activation during real-time simulation. Users can also monitor voltages, currents, machine torque and speed of the machine at any point during the simulation

The "eHS1" solver solves the power network built using schematic editor software during the real time simulation. The circuit built in schematic editor can be edited or viewed by choosing the edit option available in the solver block.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-d2efd1199aa9c5b1a5fec23078232fe28eddca4a%2Fehs-modelPMSMDQ6h-1.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 schematic editor circuit characteristics. Elements will be put into matrices and stored in .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.

Field Oriented Control of PMSM is implemented on the CPU, which runs at a sampling time of 25 microseconds. This has a standard outer loop speed control and inner loop current control implemented. The transformation used is Amplitude Invariant with D axis aligned to phase A axis (Original Park). The modulating waves are clamped to a value between 0 and 1 using a clamping circuit. 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.

Modulating waveforms generated by the controller are converted to PWM via PWMO IO block of OPAL-RT. These PWM pulses are fed back through digital loop-back cable to fire the eHS converter internally. Here, the gating pulses are chosen to receive from Digital In card of the OPAL-RT simulator. Here, to receive the PWM in schematic editor, the gates of each Half-Bridge Converter are configured by mapping them to Digital In Channels.

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

The measurements in the schematic editor FPGA model can be configured to route them via DAC of the selected chassis with necessary settings. Similarly, the inputs can be received from either CPU or by configuring the ADC's of the real time system. User can opt to read the measurements to the CPU environment or configure IO's to interface external hardware (see image below). Similarly, few parameters are given access to be defined in the schematic itself or be defined from the CPU model.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-45829763c0fc4071d5f3ada8778687058ce80a92%2Fehs-modelPMSMDQ6h-2%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

The OPAL-RT hardware chassis, FPGA module and firmware has to be chosen in the schematic editor prior to the building of the model. In Schematic Editor, go to: Simulate - Simulator Setup - Choose the Simulator - Choose the Firmware. Mark the "Use this setup" to fit your simulation requirement.

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

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

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

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

RT-LAB, Schematic Editor/Unified Database and the eHS Power Electronics Toolbox must be installed in order to successfully run this example project.

<details>

<summary><strong>OP5607 and OP5707 simulators</strong></summary>

In this configuration, an external Digital Output–to–Digital Input **loopback connection** must be used to control the gate signals. Connect a loopback cable from a digital output to the corresponding digital input on the simulator. This connection is required for the simulation to run successfully.

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

</details>

<details>

<summary><strong>OP4512 and OP4610 simulators</strong></summary>

When configured in **bi-directional mode**, the OP5369 card supports an internal Digital Output–to–Digital Input loopback. This allows a Digital Input assigned to a channel to directly read the signal generated by the Digital Output on the same channel.

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

</details>

{% hint style="info" %}
If your IO Configuration contains bi-directional OP5369 card, you can always use its internal loopback capability.
{% endhint %}

## 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>>Schematic\_Editor\_Workflow>>Machine Drives>>PMSM Constant DQ Six Phase Field Oriented Control**.
2. Compile the RT Model by clicking on **Build** in RT-LAB.
3. Once the model has been successfully built, **Load** and **Execute** the model in RT-LAB in order to begin the real-time simulation.
4. Once the real-time model and the eHS are running, observe the results of the eHS simulation by opening the **measurements** subsystem in the Simulink Console.

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

This model must be run with both the Hardware Synchronized and XHP modes 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 25 microseconds and all the variables required for controller is defined in the "ParameterInitialization.m" file that is automatically loaded during simulation.

Digital loop-back (internal or external) is used to transfer the gating pulses.

{% hint style="info" %}
In S-Function workflow, example models support any chassis. You can contextualize your example model by selecting the chassis in the Chassis selection block.
{% endhint %}

<details>

<summary><strong>S-function Workflow</strong></summary>

The **Mezzanine Option block** is an RT-LAB block used in the **S-Function workflow** to configure the settings of the I/O cards for each mezzanine. The available settings depend on the specific type of I/O card.

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

</details>

<details>

<summary><strong>OpalBoard workflow</strong></summary>

[OPAL-RT Board](https://www.opal-rt.com/docs/rt-lab/configure-ios/analog-digital-and-sfp-ios/opal-rt-board-workflow.md) allow the configuration of I/O card settings for each mezzanine.

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

If, for a given I/O mezzanine, this block is not used, then the corresponding settings will be kept at their default values. These default values are dependent on particularities of the bitstream, and they are not guaranteed to be exposed to the user loading their model. Further, the default values populating the Mezzanine Option block do not necessarily correspond to the default settings that will be seen if the Mezzanine Option block is not used.

Note that if a Mezzanine Option block is used, and the choice of mezzanine type is incorrect for the given slot, the model will still load and run. However, there will be errors in the load log in RT-LAB. For example, the following error is observed in the case that slot 1A on the simulator holds an OP5330-3, when we place a Mezzanine Option block that attempts to configure an OP5369 on slot 1A:

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

```
Mezzanine configurator: OP5369 Threshold configuration.
ERROR: OPAL-RT Board: The threshold control register for slot 1A is in an unexpected state. Please reprogram the bitstream.
ERROR: Mezzanine configurator: Threshold configuration failed...
```

{% endcode %}

Further, as documented in the aforementioned RT-LAB page, the block outputs its status: a 0 in the case when the block’s settings have been correctly applied, and a -1 otherwise. For example, in the below model I incorrectly configured one block by giving it the wrong I/O card, and set the other correctly. The result when we load the model reflects this:

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-a4fe002fb70685f86d0a022ad92068069ae7264d%2Fehs-opalboard-block-workflow.png?alt=media" alt="" width="188"><figcaption></figcaption></figure>

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

</details>

### Run the model

During real-time execution:

1. Speed reference is set to 300rpm. It can be varied until 350rpm
2. Load Torque is 150Nm by default. Machine can handle up to 650Nm load torque.
3. By default, Speed input is provided to the machine. To use Torque as an input to the machine, provide '1' to the Mode.

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

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-acb75652fe5ae428230cbca31656016aba46e540%2Fehs-modelPMSMDQ6h-7.png?alt=media" alt=""><figcaption></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/machine-drive-example-models/pmsm-constant-dq-six-phase-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.
