> 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/smart-power-simulation-software-sps/library-specific-guides/motor-drives/simulate-variable-speed-motor-control.md).

# Simulate Variable Speed Motor Control

## Introduction

Variable speed control of AC electrical machines makes use of forced-commutated electronic switches such as IGBTs, MOSFETs, and GTOs. Asynchronous machines fed by *pulse width modulation* (PWM) voltage sourced converters (VSC) are nowadays gradually replacing the DC motors and thyristor bridges. With PWM, combined with modern control techniques such as field-oriented control or direct torque control, you can obtain the same flexibility in speed and torque control as with DC machines. This tutorial shows how to build a simple open loop AC drive controlling an asynchronous machine. SPS contains prebuilt models that enable you to simulate electric drives systems without the need to build those complex systems yourself. For more information, see [Electric Drives Models.](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/library-specific-guides/motor-drives/electric-drives-models.md)

The **SPS** > **Electrical Machines** library contains four of the most commonly used three-phase machines: simplified and complete synchronous machines, asynchronous machine, and permanent magnet synchronous machine. Each machine can be used either in generator or motor mode. Combined with linear and nonlinear elements such as transformers, lines, loads, breakers, etc., they can be used to simulate electromechanical transients in an electrical network. They can also be combined with power electronic devices to simulate drives.

The **SPS** > **Power Electronics** library contains blocks allowing you to simulate diodes, thyristors, GTO thyristors, MOSFETs, and IGBT devices. You could interconnect several blocks together to build a three-phase bridge. For example, an IGBT inverter bridge would require six IGBTs and six antiparallel diodes.

To facilitate implementation of bridges, the [Universal Bridge](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/power-converters/switches/universal-bridge.md) block automatically performs these interconnections for you.

## Building and Simulating the PWM Motor Drive

Follow these steps to build a model of a PWM-controlled motor.

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-ea6645dd8e2c63ef5bb573e9234ce5d999417a3c%2Fvariable_speed_motor_control_PWM_schema.png?alt=media" alt=""><figcaption><p>Assembling and Configuring the Model</p></figcaption></figure>

{% stepper %}
{% step %}
Type power\_new at the command line to open a new model. Save the model as power\_PWMmotor
{% endstep %}

{% step %}
Add a Universal Bridge block from the **SPS** > **Power Electronics** library
{% endstep %}

{% step %}
In the **Parameters** settings for the Universal Brdge block, set the **Power Electronic device** parameter to IGBT /Diodes.
{% endstep %}

{% step %}
Add an [Asynchronous Machine block](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/machines/blocks/asynchronous-machine.md) from the SPS > Electrical Machines library library
{% endstep %}

{% step %}
Set the parameters of the Asynchronous Machine block as follows.

<table data-header-hidden><thead><tr><th width="169"></th><th width="383.4444580078125"></th><th></th></tr></thead><tbody><tr><td><strong>Settings</strong></td><td><strong>Parameter</strong></td><td><strong>Value</strong></td></tr><tr><td><strong>Configuration</strong></td><td><strong>Rotor type</strong></td><td>Squirrel-cage</td></tr><tr><td><strong>Parameters</strong></td><td><strong>Nominal power, voltage (line-line), and frequency [ Pn(VA), Vn(Vrms), fn(Hz) ]</strong></td><td>[3*746 220 60]</td></tr><tr><td></td><td><strong>Stator resistance and inductance [ Rs(ohm) Lls(H) ]</strong></td><td>[1.115 0.005974]</td></tr><tr><td></td><td><strong>Rotor resistance and inductance [ Rr'(ohm) Llr'(H) ]</strong></td><td>[1.083 0.005974]</td></tr><tr><td></td><td><strong>Mutual inductance Lm (H)</strong></td><td>0.2037</td></tr><tr><td></td><td><strong>Inertia, friction factor, pole pairs [ J(kg.m^2) F(N.m.s) p() ]</strong></td><td>[0.02 0.005752 2]</td></tr><tr><td></td><td><strong>[slip, th(deg), ia,ib,ic(A), pha, phb, phc(deg)]</strong></td><td>[1 0 0 0 0 0 0 0]</td></tr></tbody></table>
{% endstep %}

{% step %}
Access internal signals of the Asynchronous Machine block

* Add a Bus Selector block from the **Simulink** > **Signal Routing** library.
* Connect the measurement output port, **m**, of the machine block to the input port of the Bus Selector block.
* To open the **Block Parameters** dialog box for the Bus Selector block, double-click the block.
* Remove the preselected signals. Under **Output elements**, **Shift** select `signal1` and `signal2`. Then, click .
* Under **Elements in the bus**, **Ctrl** select the signals of interest:\
  1\. **Stator measurements** > **Stator current is\_a (A)**\
  2\. **Mechanical** > **Rotor speed (wm)**\
  3\. **Electromagnetic torque Te (N\*m)**

Then, click or , depending on the layout of the dialog box.
{% endstep %}
{% endstepper %}

### **Loading and Driving the Motor**

Implement the torque-speed characteristic of the motor load. Assuming a quadratic torque-speed characteristic (fan or pump type load)., the torque *T* is proportional to the square of the speed ω.

$$
T=k \times \omega^2
$$

The nominal torque of the motor is

$$
Tn=\frac{3 \times 746}{188.5}=11.87 , \text{ N}
$$

Therefore, the constant *k* should be

$$
k=\frac{T\_n}{\omega^2}=\frac{11.87}{188.5^2}=3.34\times10^{-4}
$$

1. Add an Interpreted MATLAB Function block from the **Simulink** > **User-Defined Functions** library. Double-click the function block, and enter the expression for torque as a function of speed: 3.34e-4\*u^2.
2. Connect the output of the function block to the torque input port, **Tm**, of the machine block.
3. Add a [DC Voltage Source](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/basics/sources/dc-voltage-source.md) block from the SPS > Sources library. In the **Parameters** settings for the block, for the **Amplitude (V)** parameter, specify 400.
4. Change the name of the [Voltage Measurement](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/control-and-measurements/measurement/voltage-measurement.md) block to VAB.
5. Add a [Ground](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/basics/grounds/ground.md) block from the SPS > Utilities library. Connect the power elements and voltage sensor blocks as shown in the diagram of the **power\_PWMmotor model**.

### **Controlling the Inverter Bridge with a Pulse Generator**

To control the inverter bridge, use a pulse generator.

{% stepper %}
{% step %}
Add a [PWM Generator (2-Level) ](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/control-and-measurements/pulse-and-signal-generators/pwm-generator-2-level.md)block from the SPS > Power Electronics > Power Electronics Control library. You can configure the converter to operate in an open loop, and the three PWM modulating signals are generated internally. Connect the P output to the pulses input of the [Universal Bridge](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/power-converters/switches/universal-bridge.md) block
{% endstep %}

{% step %}
Open the PWM Generator (2-Level) block dialog box and set the parameters as follows.

| **Generator type**                          | Three-phase bridge (6 pulses) |
| ------------------------------------------- | ----------------------------- |
| **Mode of operation**                       | Unsynchronized                |
| **Frequency**                               | 18\*60Hz (1080 Hz)            |
| **Initial Phase**                           | 0 degrees                     |
| **Minimum and maximum values**              | \[-1,1]                       |
| **Sampling technique**                      | Natural                       |
| **Internal generation of reference signal** | selected                      |
| **Modulation index**                        | 0.9                           |
| **Reference signalfrequency**               | 60 Hz                         |
| **Reference signalphase**                   | 0 degrees                     |
| **Sample time**                             | 10e-6 s                       |
| {% endstep %}                               |                               |

{% step %}
The block has been discretized so that the pulses change at multiples of the specified time step. A time step of 10 µs corresponds to +/- 0.54% of the switching period at 1080 Hz. One common method of generating the PWM pulses uses comparison of the output voltage to synthesize (60 Hz in this case) with a triangular wave at the switching frequency (1080 Hz in this case). The line-to-line RMS output voltage is a function of the DC input voltage and of the modulation index *m* as given by the following equation:

$$
V\_{LLrms} = \frac{m}{2} \times \frac{\sqrt{3}}{\sqrt{2}} V\_{dc} = m \times 0.612 \times V\_{DC}
$$

Therefore, a DC voltage of 400 V and a modulation factor of 0.90 yield the 220 Vrms output line-to-line voltage, which is the nominal voltage of the asynchronous motor.
{% endstep %}
{% endstepper %}

### **Displaying Signals and Measuring Fundamental Voltage and Current**

{% stepper %}
{% step %}
You now add blocks measuring the fundamental component (60 Hz) embedded in the chopped Vab voltage and in the phase A current. Add a [Fourier](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/control-and-measurements/analysis/fourier.md) block from the **SPS > Sensors and Measurements** library to your model. Open the Fourier block dialog box and check that the parameters are set as follows:

| **Fundamental frequency** | 60 Hz   |
| ------------------------- | ------- |
| **Harmonic n**            | 1       |
| **Initial input**         | \[0 0]  |
| **Sample time**           | 10e-6 s |

Connect this block to the output of the Vab voltage sensor.
{% endstep %}

{% step %}
Duplicate the [Fourier](https://opal-rt.atlassian.net/wiki/spaces/PSPS/pages/1551731890/Fourier) block. To measure the phase A current, you connect this block to the **Stator current is\_a** output of the Bus selector block.
{% endstep %}

{% step %}
Stream these signals to the Simulation Data Inspector: the Te, ias, and w signals of the measurement output of the Asynchronous Machine block, and the VAB voltage
{% endstep %}
{% endstepper %}

## **Simulating the PWM Motor Drive with Continuous Integration Algorithm**

Set the stop time to `1 s` and start the simulation. Open the **Simulation Data Inspector** and look at the signals.

The motor starts and reaches its steady-state speed of 181 rad/s (1728 rpm) after 0.5 s. At starting, the magnitude of the 60 Hz current reaches 90 A peak (64 A RMS) whereas its steady-state value is 10.5 A (7.4 A RMS). As expected, the magnitude of the 60 Hz voltage contained in the chopped wave stays at

$$
220 \times \sqrt2=331 \text{ V}
$$

Also notice strong oscillations of the electromagnetic torque at starting. If you zoom in on the torque in steady state, you should observe a noisy signal with a mean value of 11.9 N.m, corresponding to the load torque at nominal speed.

If you zoom in on the three motor currents, you can see that all the harmonics (multiples of the 1080 Hz switching frequency) are filtered by the stator inductance, so that the 60 Hz component is dominant.

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-6653f32ee95c6230f0e3b2367492bdaed97d5dda%2Fimage.png?alt=media" alt="" width="488"><figcaption><p>PWM Motor Drive; Simulation Results for Motor Starting at Full Voltage</p></figcaption></figure>

### Using the Multimeter Block

The Universal Bridge block is not a conventional subsystem where all the six individual switches are accessible. If you want to measure the switch voltages and currents, you must use the Multimeter block, which gives access to the bridge internal signals:

{% stepper %}
{% step %}
Open the **Universal Bridge** dialog box and set the **Measurement** parameter to Device currents.
{% endstep %}

{% step %}
Add a **Multimeter** block from the SPS > Sensors and Measurements library Double-click the Multimeter block. A window showing the six switch currents appears.
{% endstep %}

{% step %}
Select the two currents of the bridge arm connected to phase A. They are identified as

| **iSw1**      | `Universal Bridge` |
| ------------- | ------------------ |
| **iSw2**      | `Universal Bridge` |
| {% endstep %} |                    |

{% step %}
Click **Close**. The number of signals (2) is displayed in the Multimeter icon.
{% endstep %}

{% step %}
Send the signal from the Multimeter block to the Simulation Data Inspector.
{% endstep %}

{% step %}
Restart the simulation. The waveforms obtained for the first 20 ms are shown in this plot.

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-1898fe94ed3a427af2ab47cd6abbaf30bb8e240c%2Fimage.png?alt=media" alt="" width="404"><figcaption><p>Currents in IGBT/Diode Switches 1 and 2</p></figcaption></figure>
{% endstep %}
{% endstepper %}

As expected, the currents in switches 1 and 2 are complementary. A positive current indicates a current flowing in the IGBT, whereas a negative current indicates a current in the antiparallel diode.

{% hint style="info" %}
**Multimeter block use is not limited to the Universal Bridge block**. Many blocks of the Electrical Sources and Elements libraries have a Measurement parameter where you can select voltages, currents, or saturable transformer fluxes. A judicious use of the Multimeter block reduces the number of current and voltage sensors in your circuit, making it easier to follow.
{% endhint %}

### Discretizing the PWM Motor Drive

You might have noticed that the simulation using a variable-step integration algorithm is relatively long. Depending on your computer, it might take tens of seconds to simulate one second. To shorten the simulation time, you can discretize your circuit and simulate at fixed simulation time steps.

In the **Simulation** tab, click **Model Settings**. Select **Solver**. Under **Solver selection**, select the Fixed-step and Discrete (no continuous states) options. Open the powergui block and set **Simulation type** to Discrete. Set the **Sample time** to 10e-6 s. The power system, including the asynchronous machine, is now discretized at a 10 µs sample time.

Start the simulation. Observe that the simulation is now faster than with the continuous system. Results compare well with the continuous system.

### Performing Harmonic Analysis Using the FFT Tool

The two Fourier blocks allow computation of the fundamental component of voltage and current while simulation is running. If you would like to observe harmonic components also you would need a Fourier block for each harmonic. This approach is not convenient.

Add a Scope block to your model and connect it at the output of the VAB Voltage Measurement block. In the Scope block, log data to workspace as a structure with time. Start the simulation. Now use the FFT tool of powergui to display the frequency spectrum of voltage and current waveforms.

When the simulation is complete, open the powergui and select **FFT Analysis**. A new window opens. Set the parameters specifying the analyzed signal, the time window, and the frequency range as follows:

| **Name**                  | `ScopeData`                    |
| ------------------------- | ------------------------------ |
| **Input**                 | `input 1`                      |
| **Signal number**         | `1`                            |
| **Start time**            | `0.7 s`                        |
| **Number of cycles**      | `2`                            |
| **Display**               | `FFT window`                   |
| **Fundamental frequency** | `60 Hz`                        |
| **Max frequency**         | `5000 Hz`                      |
| **Frequency axis**        | `Harmonic order`               |
| **Display style**         | `Bar (relative to Fund or DC)` |

The analyzed signal is displayed in the upper window. Click **Display**. The frequency spectrum is displayed in the bottom window, as shown in the next figure.

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-634d3ab8f0c300a5e0969cfe2b3e32ebe2e11a2f%2Fimage.png?alt=media" alt=""><figcaption><p>FFT Analysis of the Motor Line-to-Line Voltage</p></figcaption></figure>

The fundamental component and total harmonic distortion (THD) of the Vab voltage are displayed above the spectrum window. The magnitude of the fundamental of the inverter voltage (312 V) compares well with the theoretical value (311 V for m=0.9).

Harmonics are displayed in percent of the fundamental component. As expected, harmonics occur around multiples of carrier frequency (n\*18 +- k). Highest harmonics (30%) appear at 16th harmonic (18 - 2) and 20th harmonic (18 + 2).


---

# 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/smart-power-simulation-software-sps/library-specific-guides/motor-drives/simulate-variable-speed-motor-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.
