Main Content

Direct Torque Control of PMSM Using Quadrature Encoder or Sensorless Flux Observer

This example implements direct torque control (DTC) technique to control the speed of a three-phase permanent magnet synchronous motor (PMSM). Direct Torque Control (DTC) is a vector motor control technique that implements motor speed control by directly controlling the flux and torque of the motor. The example algorithm needs motor currents and position feedback from PMSM. It uses space vector pulse-width modulation (DTC-SVPWM) variant of DTC, which uses space vector modulation (SVM) to produce the pulse-width modulation (PWM) duty cycles that are used by the inverter. For more details about the DTC-SVPWM algorithm used in this example, see Direct Torque Control (DTC).

The example enables you to use either quadrature encoder sensor or sensorless flux observer to determine the rotor position. For details about the Flux Observer Simulink® block, see Flux Observer.

Model

The example includes the mcb_pmsm_dtc_f28379d model (target model).

You can use this model for both simulation and code generation.

For details about the supported hardware configuration, see the Required Hardware topic in the Generate Code and Deploy Model to Target Hardware section.

Required MathWorks Products

To simulate model:

  • Motor Control Blockset™

To generate code and deploy model:

  • Motor Control Blockset™

  • Embedded Coder®

  • C2000™ Microcontroller Blockset

  • Fixed-Point Designer™ (only needed for optimized code generation)

Prerequisites

1. Obtain the motor parameters. The Simulink® model uses default parameters that you can replace with values from either the motor datasheet or other sources.

However, if you have the motor control hardware, you can estimate the parameters for the motor that you want to use by using the Motor Control Blockset parameter estimation tool. For instructions, see Estimate PMSM Parameters Using Recommended Hardware. The parameter estimation tool updates the motorParam variable (in the MATLAB® workspace) with the estimated motor parameters.

2. Update motor parameters. If you obtain the motor parameters from the datasheet or from other sources, update the motor and inverter parameters in the model initialization script associated with the Simulink® model. For instructions, see Estimate Control Gains and Use Utility Functions.

If you use the parameter estimation tool, you can update the inverter parameters, but do not update the motor parameters in the model initialization script. The script automatically extracts the motor parameters from the updated motorParam workspace variable.

Simulate Model

This example supports simulation. Follow these steps to simulate the model.

1. Open the target model included with this example.

2. Click Run on the Simulation tab to simulate the model.

3. Click Data Inspector in the Review Results section to view and analyze the simulation results.

Generate Code and Deploy Model to Target Hardware

This section shows how to generate code and run the DTC algorithm on the target hardware.

This example uses a host and a target model. The host model is a user interface to the controller hardware board. You can run the host model on the host computer. Before you can run the host model on the host computer, deploy the target model to the controller hardware board. The host model uses serial communication to command the target Simulink model and run the motor in closed-loop control.

Required Hardware

The example supports this hardware configuration. You can also use the target model name to open the model from the MATLAB® command prompt.

LAUNCHXL-F28379D controller + (BOOSTXL-DRV8305 or BOOSTXL-3PHGANINV) inverter: mcb_pmsm_dtc_f28379d

Note: When using the BOOSTXL-3PHGANINV inverter, ensure that you have proper insulation between the bottom layer of BOOSTXL-3PHGANINV and the LAUNCHXL board.

For connections related to this hardware configuration, see LAUNCHXL-F28069M and LAUNCHXL-F28379D Configurations.

Generate Code and Run Model on Target Hardware

1. Simulate the target model and observe the simulation results.

2. Complete the hardware connections.

3. Open the target model. If you want to change the default hardware configuration settings for the model, see Model Configuration Parameters.

4. Set the Position Feedback radio button on the target model to Quadrature Encoder if you are using a quadrature encoder sensor to read the rotor position. Select Flux Observer if you want to use sensorless position estimation using a flux observer.

5. Compute the quadrature encoder index offset value and update it in the pmsm.PositionOffset variable available in the model initialization script associated with the target model. For instructions, see Quadrature Encoder Offset Calibration for PMSM.

Note: Skip step 4 if you are using the sensorless flux observer for position estimation.

6. The model by default computes the ADC offset values for phase current measurement. To disable this functionality, update the value of the inverter.ADCOffsetCalibEnable variable in the model initialization script to 0.

Alternatively, you can compute the ADC offset values and update them manually in the model initialization script. For instructions, see Run 3-Phase AC Motors in Open-Loop Control and Calibrate ADC Offset.

7. Load a sample program to CPU2 of the LAUNCHXL-F28379D board. For example, load the program that operates the CPU2 blue LED by using GPIO31 (c28379D_cpu2_blink.slx). This ensures that CPU2 is not mistakenly configured to use the board peripherals intended for CPU1. For more information about the sample program or model, see the Task 2 - Create, Configure and Run the Model for TI Delfino F28379D LaunchPad (Dual Core) section in Getting Started with Texas Instruments C2000 Microcontroller Blockset (C2000 Microcontroller Blockset).

8. Click Build, Deploy & Start on the Hardware tab to deploy the target model to the hardware. Check if the MATLAB base workspace shows the variables from the deployed target model.

9. Click the host model hyperlink in the target model to open the associated host model.

For details on serial communication between the host and target models, see Host-Target Communication.

10. In the model initialization script associated with the target model, specify the communication port using the variable target.comport. The example uses this variable to update the Port parameter of the Host Serial Setup, Host Serial Receive, and Host Serial Transmit blocks available in the host model.

11. Click Run on the Simulation tab to run the host model.

12. Change the position of the Start / Stop Motor switch to On, to start running the motor.

13. Update the Reference Speed value (in RPM) in the host model.

14. Use the Debug signals section of the host model to select the debug signals that you want to monitor:

  • Speed_ref & Speed_feedback — Display the speed reference and speed feedback signals in the scope.

  • Flux_ref & Flux_feedback — Display the flux reference and flux feedback signals in the scope.

  • Torque_ref & Torque_feedback — Display the torque reference and torque feedback signals in the scope.

  • Ia & Ib — Display the phase-|a| and phase-|b| currents in the scope.

  • Ia & Position — Display the phase-|a| current and rotor position signals in the scope.

15. Use the time scope available in the host model to monitor the selected debug signals.