> 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/machine-sensors.md).

# Machine Sensors

## Description

This example illustrates the operation of the r**esolver**, q**uadrature encoder**, and **Hall Effect sensor** models, as well as how their configuration parameters influence the resulting output signals.

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

For this example, no **Circuit Model** is required, a placeholder circuit consisting of one Source, one Switch, and one Measurement is used.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FkQOFVI7jpuTZg7G0m2sP%2Fimage.png?alt=media&amp;token=c6176df5-84a4-443a-8a1f-7df1bdf68bc6" alt="" width="497"><figcaption></figcaption></figure>

Each sensor’s associated machine model is rotated to generate realistic sensor outputs, which are visualized directly in VeriStand.

In a typical **Hardware‑in‑the‑Loop (HIL)** setup, these simulated sensor signals would then be mapped to the appropriate **Digital** or **Analog Output** channels to interface with external hardware components.

## 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 that contains a Resolver, Encoder, or Hall Effect Sensor.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FSoZPKig0RmO50QbajBwY%2Fimage.png?alt=media&amp;token=3a2f9f2e-5d30-4342-baee-295da94fcc13" alt="" width="563"><figcaption></figcaption></figure>

| NI FPGA Card      | Hardware Configuration                   |
| ----------------- | ---------------------------------------- |
| **NI PXIe-7868R** | eHSx32\_Dual\_PMSM\_VDQ\_IO\_32DO\_7868R |
| **NI PXIe-7891**  | eHSx64\_Quad\_PMSM\_VDQ\_IO\_7891        |

</details>

<details>

<summary><strong>Circuit Model</strong></summary>

Because no **Circuit Model** is required for this example, it uses a placeholder circuit consisting of one Source, one Switch, and one Measurement.

* 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.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2F6hdes8HGaTzWV8fRykJS%2Fimage.png?alt=media&amp;token=9b4eac83-b091-4ecf-8ac9-2ab96d606709" alt="" width="563"><figcaption></figcaption></figure>

**Circuit Model File Path:** *\<Machine Sensors>\Circuit Model\PlaceholderCircuit.slx*

</details>

<details>

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

The **Sources page** maps signals to each source of the circuit model. In this example, the source mapping configuration does not affect the results of the simulation because the circuit is simply a placeholder.

1. In the Configuration Tree, expand **Circuit Model** and click **Sources**. This page is populated with a list of sources from the circuit model.
2. The mappings are configured as shown below; any **Group** and **Element** can be mapped to Source.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2F1gEla98nSagduQVTet6I%2Fimage.png?alt=media&amp;token=e3fa6703-dd78-4bde-964c-a831cb8409a6" alt="" width="563"><figcaption></figcaption></figure>

</details>

<details>

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

The **Switches page** maps signals to each switch of the circuit model. In this example, the switch mapping configuration does not affect the results of the simulation because the circuit is simply a placeholder.

1. In the configuration tree, expand **Circuit Model** and click **Switches**. This page is populated with a list of switches from the circuit model.
2. The mappings are configured as shown below; any **Group** and **Element** can be mapped to a switch.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2F3OJOwuJvw47EIBNx1a7a%2Fimage.png?alt=media&amp;token=7343d7b2-ee39-4825-b99e-6ab642aa463f" alt="" width="563"><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Machine model</strong></summary>

In this example, we manually rotate the machine models so that their respective **resolver**, **encoder**, and **Hall-Effect sensors** generate output signals. Because we are interested only in the mechanical rotation of the machine, we can leave the **Input Mapping Configuration** and the electrical **Machine Configuration** parameters unconfigured.

Each machine model is set to **Speed Controlled Mode** to allow its speed to be commanded via the **User-Defined Speed** channel.

1. In the Configuration Tree, expand **Circuit Model >> PMSM BLDC X** **>> Mechanical Model** and click the **Mechanical Model Mode** channel.
2. For all machine models, the **Default Value** of the channel is set to **0** for **Speed Controlled Mode**.

The PXIe‑7868R version of this example uses both of its available PMSM/BLDC models, while the PXIe‑7891 version uses three of its four models. The table below identifies which PMSM/BLDC model is used to simulate each type of sensor.

See the **Resolver** and **Encoder** documentation for a full description of the model and its parameters.

|                        | PXIe-7868R  | PXIe-7891   |
| ---------------------- | ----------- | ----------- |
| **Resolver**           | PMSM BLDC 1 | PMSM BLDC 1 |
| **Quadrature Encoder** | PMSM BLDC 1 | PMSM BLDC 2 |
| **Hall Effect Sensor** | PMSM BLDC 2 | PMSM BLDC 3 |

**Resolver**

* In the Configuration Tree, expand **PMSM BLDC X** and click **Resolver**.
* The **Angle Conditioning** and **Gain Configuration** parameters do not need to be modified because they are available as **VeriStand channels** and can be modified during the simulation. The **Excitation Frequency** and **Initial Carrier Angle** are not editable during the simulation.

In this example, the **Internal Carrier** parameters are configured as shown below.

| Parameter                                  | Value |
| ------------------------------------------ | ----- |
| **Initial Carrier Angle (deg)**            | 0     |
| **Excitation Frequency (Hz)**              | 10    |
| **Enable Internal Carrier**                | TRUE  |
| **Force Initial Angle**                    | FALSE |
| **Enable Resolver Parameters as Channels** | TRUE  |

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FYKT156AjMRtokGfasXww%2Fimage.png?alt=media&amp;token=f9bfcc41-a8be-425c-8971-482dd2f7ded6" alt="" width="563"><figcaption></figcaption></figure>

**Quadrature Encoder**

* In the Configuration Tree, expand **PMSM BLDC X** and click **Encoder**.
* Set the **Encoder Mode** to **Quadrature Encoder** to view the Encoder parameters. They are not editable during the simulation.

In this example, the encoder **Configuration** parameters are configured as shown below.

| Parameter                       | Value              |
| ------------------------------- | ------------------ |
| **Encoder Mode**                | Quadrature Encoder |
| **Number of Pole Pairs**        | 1                  |
| **Angle Offset (deg)**          | 0                  |
| **Number of Pulses/Revolution** | 10                 |
| **Rotation Type**               | A Leads B          |
| **Polarity**                    | Active High        |

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FDxambqs5KotVFBfAiDKB%2Fimage.png?alt=media&amp;token=463a5177-b56d-4f2a-87a5-36306475fa44" alt="" width="563"><figcaption></figcaption></figure>

**Hall Effect Sensor**

The Hall Effect Sensor is a mode of the **Encoder** model.

* In the Configuration Tree, expand **PMSM BLDC X** and click **Encoder**.
* Set the **Encoder Mode** to **Hall Effect** to view the Hall Effect Sensor parameters.

In this example, the Hall Effect Sensor **Configuration** parameters are configured as shown below. They are not editable during the simulation.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FbXqAnFBvn86QDxQG4QAj%2Fimage.png?alt=media&amp;token=25d8d23f-0027-484d-8281-e6511ae8b8e9" alt="" width="563"><figcaption></figcaption></figure>

</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%2FKp1cTNNM2nMqJLrlGKrw%2Fimage.png?alt=media&amp;token=4b96f137-9da9-4bde-99b3-c34e60c0e996" alt="" width="563"><figcaption></figcaption></figure>

</details>

## Simulation and results

This project includes three visualization tabs that allow you to analyze the behavior of the resolver, quadrature encoder, and Hall Effect sensor models.

The configuration information displayed in grey is for informational purposes only; these parameters can only be modified from the System Definition file while the project is undeployed.

### Resolver

Open the VeriStand Screen (.nivsscr) files and manipulate the parameters in the blue boxes to observe the resulting output signals (set a slow **Machine Speed**, such as 10 RPM).

In this example, the excitation for the resolver is provided by an internal carrier with a frequency of 10Hz. The **Excitation Frequency**, as well as the other **Internal Carrier Configuration** parameters can be modified in the System Definition file.

The **Sine** and **Cosine** outputs are computed as shown in the equations below. Refer to the **Resolver** page for in-depth information about each parameter and for a description of the Resolver model.

$$
Sine\ Output = \[\mathrm{Sin.Sin}\ \*\ \sin(pp(\theta\_m - \theta\_{offset}))\ +\ \mathrm{Sin.Cos}\ *\ \cos(pp*\theta\_m - \theta\_{offset})]\ \*\ Excitation\\\[8pt]

Cosine\ Output = \[\mathrm{Cos.Sin}\ \*\ \sin(pp(\theta\_m - \theta\_{offset}))\ +\ \mathrm{Cos.Cos}\ \*\ \cos(pp \* \theta\_m - \theta\_{offset})]\ \*\ Excitation\\\[8pt]
$$

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FTdPxZQi1xh4EZZ3MvExl%2Fimage.png?alt=media&amp;token=d2506de1-1759-4a92-a6e9-4e85c9fb263a" alt=""><figcaption></figcaption></figure>

### Encoder

Open *Encoder.nivsscr* and set a slow **Machine Speed**, such as 10 RPM. Observe the generated **A**, **B** and **Z** output signals, as well as their relationship to the **Machine Angle**.

The **Encoder Configuration** parameters shown in the grey box, can be modified in the System Definition file when the project is undeployed.

Refer to the **Encoder** page for in-depth information about each parameter and for a description of the Quadrature Encoder model.

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FcSfiyLr6Qg44xKQt44J9%2Fimage.png?alt=media&amp;token=eae84913-8dea-44dd-8351-61055b35f2f4" alt=""><figcaption></figcaption></figure>

### Hall Effect Sensor <a href="#hall-effect-sensor" id="hall-effect-sensor"></a>

Open *Hall Effect Sensor.nivsscr* and set a slow **Machine Speed**, such as 10 RPM. Observe the generated **A**, **B** and **C** output signals, as well as their relationship to the **Machine Angle**.

The **Hall Effect Sensor Configuration** parameters shown in the grey box can be modified in the System Definition file when the project is undeployed.

Refer to the **Encoder** page for in-depth information about each parameter and for a description of the Hall Effect Sensor model.

{% hint style="info" %}
Note that the Hall Effect Sensor is a mode of the Encoder model. It is available in all machine models except the **IM SM** model.
{% endhint %}

<figure><img src="https://2999842053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe9Kk9pJCHht2LLBSxPap%2Fuploads%2FSl5LvPDbzlMexHVetA3K%2Fimage.png?alt=media&amp;token=af184bbe-9e08-4b04-a4f8-92645a18f828" 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/pe-add-on-simulink/examples/machine-sensors.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.
