Main Content

Simulation of FOC Using PMSM Model

This example shows how to simulate field-oriented control (FOC) using a Permanent Magnet Synchronous Machine (PMSM) model. The model is created using the Simscape Electrical™ toolbox, C28x peripherals, and DMC library blocks.

Using this example, you can:

  • Simulate FOC using a PMSM model

  • Generate code for the embedded controller

Required Hardware

  • Spectrum Digital® F2808 or F2812 eZdsp board

  • Digital Motor Controller board: Spectrum Digital® DM550

  • Three-phase Permanent Magnet Synchronous Motor with quadrature encoder

Note: The characteristics of the power supply and the amplifier must be the same as the input characteristics of the selected motor.

Available Models


The following figure shows the Permanent Magnet Synchronous Motor Field-Oriented Control example model.

Simulate FOC Using a PMSM Model

The c2812 peripheral and DMC library blocks are used to control the speed and torque of a three-phase Permanent Magnet Synchronous Machine from Simscape Electrical Systems in a speed-controlled closed-loop fashion using the field-oriented control technique.

To set up the Permanent Magnet Synchronous Machine, double-click the block and specify the parameters to match your hardware configuration. For more information on setting up the Permanent Magnet Synchronous Machine, see the Simscape Electrical Systems documentation.

External torque can be added to the simulation to reproduce the mechanical action on the shaft of the motor. A default torque is applied at the beginning of the simulation and is reversed after 3 seconds of simulation. The controller model executes a speed controller algorithm and reacts to the torque changes to maintain the desired speed. You can achieve optimal results by tuning the PID controllers on the Embedded Controller side to suit the motor.

The following figure shows the speed of the PID controller in the speed controller subsystem. The desired speed is filtered and ramps up to a defined speed value. This value stays constant until the end of the simulation. At the beginning of the simulation, torque is applied on the shaft so that the motor spins by itself in one direction until enough opposite torque is accumulated in the controller to regulate the speed to the desired value. At time = 3 seconds, a different value of external torque is applied on the shaft of the motor, forcing the controller to change its output to maintain the desired speed.

Generate Code for the Embedded Controller

To generate code for the Embedded Controller, delete the Plant Model and the Input Parameters blocks and press Ctrl+B.

Connect the motor to the DM550 Digital Motor Controller and the eZdsp board to the DM550 Digital Motor Controller, using the standard cables. Follow the instructions given by the controller vendor. By default, the model is set up for motors with the following characteristics:

  • 2000 slits/mechanical revolution

  • 4 pole pairs

  • Encoder index offset: 1850

Change the model parameters to suit the motor. Match the voltage and power characteristics of the motor with the controller parameters. Use the Edit Parameters button to change the model parameters of the motor.

The motor is driven by the conventional voltage-source inverter. The controller algorithm generates six pulse width modulation (PWM) signals using vector PWM technique for six power switching devices. Two input currents of the motor (ia and ib) are measured from the inverter and sent to the processor through two analog-to-digital converters (ADCs).

Run the Model

  1. Open the model.

  2. Remove the Plant Model and Input Parameters blocks.

  3. Press Ctrl+B to generate, build, load, and run the controller code.

More About

C2000 PID Controller