The objective of this module is to use the Embedded Target for the C2000, and the Digital Motor Control Library (DMClib) to control a Permanent Magnet Synchronous Motor (PMSM) with an encoder using the Field Oriented Control Technique.
Inside Collection (Report): From MATLAB and Simulink to Real-Time with TI DSP's
Summary: The objective of this module is to use the Embedded Target for the C2000, and the Digital Motor Control Library (DMClib) to control a Permanent Magnet Synchronous Motor (PMSM) with an encoder using the Field Oriented Control Technique.
The objective of this module is to use the Embedded Target for the C2000, and the Digital Motor Control Library (DMClib) to control a Permanent Magnet Synchronous Motor (PMSM) with an encoder using the Field Oriented Control Technique.
The following figure shows the complete application that we will implement step by step during the laboratory.
ias = Phase-a stator current
ibs = Phase-b stator current
ias = Stationary a-axis stator current
ibs = Stationary b-axis stator current
ids = Synchronously rotating d-axis stator current
iqs = Synchronously rotating q-axis stator current
vas = Stationary a-axis stator voltage
vbs = Stationary b-axis stator voltage
vds = Synchronously rotating d-axis stator voltage
vqs = Synchronously rotating q-axis stator voltage
vdc = DC-bus voltage
qlr = Rotor flux angle
qm = Mechanical angle
dir = Rotor direction
wr = Rotor speed
Ta = Phase-a duty cycle ratio of PWM signal
Tb = Phase-b duty cycle ratio of PWM signal
Tc = Phase-c duty cycle ratio of PWM signal
The simulation process will be based on a simulation model for the PMS Motor.
![]() |
Based on this model, the simulation will comprise five steps as follows:
The diagram below highlights the modules used in the first step. This first incremental step confirms operation of peripheral and target independent modules on forward control path and the code framework.
At this very first stage the goal is to generate a saw–tooth waveform with a varying frequency. This waveform is an emulation of the rotor angle, which is then passed into the Park transformation allowing us to check the correct computation of the Space Vector PWM needed for the Field Oriented Control.
%Mechanical system
%Electrical part
DC_voltage = 200;
encoder_resolution = 2000;
%PWM
freq_max=75e6;
%Controller
Ts=5e-5;
![]() |
Vd Testing
![]() |
The purpose of this step is to simulate open–loop operation with power-stage and motor connected and to check out current sensing and feedback path.
Key Modules Used for this level
In addition to the modules used in the previous section, we now start to build the feedback loop using:
![]() |
Figure 8: Open Loop Model
![]() |
Figure 9: Current Sensing
The purpose of this step is to close the current loop and to set the PI regulators correctly to get a stable system while the motor is still running in speed open-loop.
Key Modules:
In addition to the modules already used, we use the PI module:
![]() |
Vd Testing
![]() |
For ease of use, the default PID parameters are already tuned. You can still play with them and observe the results. Within the watch windows, the PID coefficients are displayed for both iq and id. Using the following picture will help you to interpret the variables.
During this step we will check the encoder feedback and we will align the calculated angle with the shaft angle.
KEY MODULES:
In addition to the modules already used, we use:
![]() |
Until now, the magnetic field in the motor was generated without taking care of the shaft position. Even if our motor is a synchronous motor, with no load and at load speed, it was easy to expect the shaft to start and to catch the magnetic field without problem. Now, if we want to close the speed loop, we need to know the shaft angle at every moment. The shaft position is given by the encoder but we still have to align the initial sensed position with the shaft.
For this, we use the Data Log module to display in real time the rmp_out variable (angle we used until now to create the magnetic field) and theta_elec (sensed angle).
The purpose of this step is to verify the speed regulator, close the speed loop and tune up the gains for the speed regulator if necessary. All the modules previously described are used in this final step.
The real-time software will run in the following hardware:
For safety reason it is mandatory that you strictly respect the following picture to connect the DMC 550.
During this build, the speed reference will be given to the DSP through a potentiometer placed on the DMC 550 (R66). To start with, please put the potentiometer around its midle position.
The motor should have good response time now thanks to the speed closed loop. As usual the PID controller is already tuned. Using the same graphical display we used during the lab 4 you can see the impact of the PID parameters.
Since all the kits are different, the default settings for the current and speed PID may not be suitable and the maximum command may be instable
Moving the speed potentiometer, you can appreciate the fast and smooth response time!