Control PMSM Loaded with Dual Motor (Dyno)

This example uses field-oriented control (FOC) to control two three-phase permanent magnet synchronous motors (PMSM) coupled in a dyno setup. Motor1 runs in the closed-loop speed control mode. Motor2 runs in the torque control mode and loads Motor 1 because they are mechanically coupled. You can use this example to test a motor in different load conditions.

The example simulates two motors that are connected back-to-back. You can use a different speed reference for Motor1 and different torque reference or current reference (Iq) for Motor2. Motor1 runs at the reference speed for the load conditions provided by Motor2 (with different current reference).

The example runs in the controller hardware board. You can input the speed reference for Motor1 and current reference for Motor2 using a host model. The host model uses serial communication to communicate with the controller hardware board.

Current control loops in Motor1 and Motor2 control algorithms are offset by Ts/2, where Ts is the control-loop execution rate.

Models

The example includes this model:

  • mcb_pmsm_foc_f28379d_dyno

You can use this model for both simulation and code generation. You can use the open_system command to open the Simulink® model. For example, use this command for a F28379D based controller:

open_system('mcb_pmsm_foc_f28379d_dyno.slx');

Required MathWorks® Products

To simulate model:

  • Motor Control Blockset™

To generate code and deploy model:

  • Motor Control Blockset™

  • Embedded Coder®

  • Embedded Coder® Support Package for Texas Instruments™ C2000™ Processors

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

Prerequisites

1. Obtain the motor parameters for both Motor1 and Motor2. We provide default motor parameters with the Simulink® model that you can replace with the 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 Motor Parameters by Using Motor Control Blockset Parameter Estimation Tool.

2. Update the motor parameters (that you obtained from the datasheet, other sources, or parameter estimation tool) and inverter parameters in the model initialization script associated with the Simulink® model. For instructions, see Estimate Control Gains from Motor Parameters.

For this example, update the motor parameters for both the motors in the model initialization script.

Simulate Model

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

1. Open a model included with this example.

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

3. Click Data Inspector on the Simulation tab to view and analyze the simulation results.

4. Input a different speed reference for Motor1 and a different current reference (load) for Motor2. Observe the measured speed and other logged signals in the Data Inspector.

Generate Code and Deploy Model to Target Hardware

This section instructs you to generate code and run the FOC algorithm on the target hardware.

The 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. The prerequisite to use the host model is to 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 a closed-loop control.

Required Hardware

The example supports this hardware configuration. Use the target model name (highlighted in bold) to open the model for the corresponding hardware configuration, from the MATLAB® command prompt.

  • LAUNCHXL-F28379D controller + 2 BOOSTXL-DRV8305 inverters: mcb_pmsm_foc_f28379d_dyno

For connections related to the preceding hardware configuration, see Instructions for Dyno (Dual Motor) Setup.

Generate Code and Run Model on Target Hardware

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

2. Complete the hardware connections.

3. The model automatically computes the ADC (or current) offset values. To disable this functionality (enabled by default), update the value 0 to the variable inverter.ADCOffsetCalibEnable in the model initialization script.

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

4. Compute the quadrature encoder index offset value and update it in the model initialization scripts associated with the target model. For instructions, see Quadrature Encoder Offset Calibration for PMSM Motor.

For this example, update the QEP offset values in the pmsm_motor1.PositionOffset and pmsm_motor2.PositionOffset variables in initialization script.

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

6. To ensure that CPU2 is not mistakenly configured to use the board peripherals intended for CPU1, load a sample program to CPU2 of LAUNCHXL-F28379D, for example, a program that operates the CPU2 blue LED by using GPIO31 (c28379D_cpu2_blink.slx).

7. Click Build, Deploy & Start on the Hardware tab to deploy the model to the hardware.

8. Click the host model hyperlink in the target model to open the associated host model. You can also use the open_system command to open the host model:

open_system('mcb_pmsm_foc_host_model_dyno.slx');

9. In the Host Serial Setup block mask of the host model, select a Port name.

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

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

12. Update the Reference Speed for Motor1 and Current Reference for Motor2 in the host model.

13. Select the debug signals that you want to monitor, to observe them in the Time Scope block of host model.