MATLAB Examples

Simulation of FOC Using PMSM Model

This example shows how to simulate a Permanent Magnet Synchronous Machine model from SimPowerSystems™ toolbox using C28x peripherals and DMC library blocks.

Required hardware:

  • Spectrum Digital® F2808 or F2812 eZdsp board

Optional Hardware:

  • Digital Motor Controller board: Spectrum Digital® DM550
  • Three-phase Permanent Magnet Synchronous Motor with quadrature encoder

Note: Match the characteristics of the power supply and the amplifier with the input characteristics of the selected motor.

Available versions of this example:



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


This example shows the use of the c2812 peripheral and DMC library blocks to control the speed and torque of a three-phase Permanent Magnet Synchronous Machine from SimPowerSystems in a speed-controlled closed-loop fashion using the Field-Oriented Control technique.

Permanent Magnet Synchronous Machine Setup: Double-click on the block to specify the parameters that match your hardware configuration. Refer to SimPowerSystems documentation for more information on Permanent Magnet Synchronous Machine setup.

External torque can be added to the simulation in order to reproduce 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 these torque changes to maintain the desired speed. You can achieve optimal results by tuning the PID controllers on the controller side to suit the specific motor being tested.

The following picture shows the speed of the PID controller scope that you can find in the "speed controller" subsystem. Note that 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 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 our controller to change its output to maintain the desired speed.

If you would like to generate code for the Embedded Controller, delete the Plant Model and Input Parameters blocks and press Ctrl+B.

Optional Hardware Setup: Connect the motor to the DM550 Digital Motor Controller and the eZdsp to the DM550 Digital Motor Controller, using the standard cables for connection. Follow the instructions given by the controller vendor. By deafult, the model is set up for the motor with the following characteristics:

  • 2000 slits/mechanical revolution
  • 4 pole pairs
  • Encoder index offset: 1850

You may need to change the model parameters to fit your specific motor. Match motor voltage and power characteristics to the controller. Use the Edit Parameters button to change the motor model parameters.

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 via two analog-to-digital converters (ADCs).

How to Run the Example

  • Open the model. Remove the Plant Model and Input Parameters blocks.
  • Press Ctrl+B to generate, build, load, and run the controller code.