Main Content

Tune Control Parameter Gains in Hardware and Validate Plant

This example uses field-oriented control (FOC) to run a three-phase permanent magnet synchronous motor (PMSM) in different modes of operation for plant validation. FOC algorithm implementation needs the real-time feedback of the rotor position. This example uses a quadrature encoder sensor to measure the rotor position. For details about FOC, seeField-Oriented Control (FOC).

The example runs the motor in these modes:

  • Stop- In this mode, the motor stops running because the inverter outputs zero volts.

  • Open loop- In this mode, the controller uses open-loop control to run the motor. You can use theOperating Mode Variables > Open-loop modearea of the host model to change the output voltage of the inverter (in per-unit) and the rotor speed (in per-unit). Use theMonitorarea to select the speed and rotor position values to display them on the scope for monitoring.

  • Torque control- In this mode, the controller uses a torque control algorithm to run the motor. You can use theOperating Mode Variables > Motor torque control modearea of the host model to change the${I_d}$reference and${I_q}$reference current values (in per-unit). You can also set the maximum speed limit of the motor (in per-unit).

You can lock the rotor by turning the slider switch to the Pos lock position that sets the rotor position to zero. Therefore, in this mode, the controller receives the position feedback as zero because the motor stops running. If you turn the switch to the Unlock position, the motor runs and the controller receives position feedback from the quadrature encoder (you can monitor this value by using the Position_meas signal in theMonitor主机领域模型)。您可以使用模拟的范围tor the two debug signals (Monitor Signal #1 and Monitor Signal #2) that you select in theMonitorarea. Therefore, you can use the slider switch to tune the torque control gain parameters.

  • Speed control- In this mode, the controller uses a speed control algorithm to run the motor. You can use theOperating Mode Variables > Motor speed control modearea of the host model to change the Speed Reference value (in per-unit) of the rotor. You can use the scope to monitor the two debug signals (Monitor Signal #1 and Monitor Signal #2) that you select in theMonitorarea.

For information related to the per-unit system, seePer-Unit System.

To further control the motor, you can also use theControl loop gainsarea of the host model to change the control parameters of thed-axis andq-axis current controllers and the speed controller.

You can use this example to run the motor in open-loop control, torque control, and speed control modes. You can also use this example for tuning the hardware gains and validating the plant model.

Caution:Stop the motor first before transitioning from one operating mode to another.

你可以选择其中的一个操作模式Control area of the host model:

  • Stop

  • Open loop run

  • Torque control

  • Speed control

Model

The example includes the modelmcb_pmsm_operating_mode_f28379d.

You can use the model for both simulation and code generation. You can also use the open_system command to open the Simulink® model:

open_system('mcb_pmsm_operating_mode_f28379d.slx');

Required MathWorks® Products

To simulate model:

  • Motor Control Blockset™

To generate code and deploy model:

1.Motor Control Blockset™

2.Embedded Coder®

3.C2000™ Microcontroller Blockset

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

Prerequisites

1.Obtain the motor parameters. 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, seeEstimate PMSM Parameters Using Recommended Hardware.

The parameter estimation tool updates themotorParamvariable (in the MATLAB® workspace) with the estimated motor parameters.

2.If you obtain the motor parameters from the datasheet or other sources, update the motor parameters and inverter parameters in the model initialization script associated with the Simulink® models. For instructions, seeEstimate 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 motor parameters from the updatedmotorParamworkspace variable.

Simulate Model

Follow these steps to simulate the model.

1.Open the target model included with this example.

2.ClickRunon theSimulationtab to simulate the target model.

3.Open themcb_pmsm_operating_mode_f28379d > Simulate Dashboardsubsystem.

Instructions for Open-Loop Run Mode:

1.If the current operating mode is other than open-loop run, selectStopin theControlarea to stop the motor. SelectOpen loop runto start the motor.

2.Set the reference voltage and reference speed values (in per-unit) in theVoltage ref (PU)andSpeed ref (PU)fields available in theOperating Mode Variables > Open-loop modearea.

Instructions for Torque Control Mode:

1.If the current operating mode is other than torque control, selectStopin theControlarea to stop the motor. SelectTorque controlin theControlarea.

2.Enter the value0(per-unit) in theIq Referencefield in theOperating Mode Variables > Motor torque control modearea. In addition, set the speed limit of the motor using theSpeed limitfield.

3.Move the slider switch toUnlockposition in theOperating Mode Variables > Motor torque control modearea.

4.Enter the value0.1(per-unit) in the in theIq Referencefield (in theOperating Mode Variablesarea) to start running the motor.

5.Open Simulation Data Inspector and select theIq_ref_PUandIq_fb_PUsignals for monitoring.

6.Follow steps 2 to 5 forId Referenceand monitor theId_ref_PUandId_fb_PUsignals.

NOTE:的年检or can reach high speeds if you run it under no load condition in this operating mode. In addition, the motor will not meet the Iq reference current under no load condition in this operating mode.

Instructions for Speed Control Mode:

1.If the current operating mode is other than speed control, selectStopin theControlarea to stop the motor. SelectSpeed controlin theControlarea.

2.Enter the value0.5(per-unit) in theSpeed Referencefield in theOperating Mode Variables > Motor speed control modearea.

3.Open Simulation Data Inspector and select theSpeed_ref_PUandSpeed_fb_PUsignals for monitoring.

Instructions for Tuning Gain of Torque Controller:

1.If the current operating mode is other than torque control, selectStopin theControlarea to stop the motor. SelectTorque controlin theControlarea.

2.Turn the slider switch toPos lockposition in theOperating Mode Variables > Motor torque control modearea.

3.Enter the value0.2(per-unit) in theId Referencefield in theOperating Mode Variablesarea.

4.打开仿真数据检查,选择Id_ref_PUandId_fb_PUsignals, and observe the step response of these signals.

5.Tune the control gains Kp and Ki for the d-axis current controller. Perform step change to validate the controller gains.

Instructions for Tuning Gain of Speed Controller:

1.If the current operating mode is other than speed control, selectStopin theControlarea to stop the motor. SelectSpeed controlin theControlarea.

2.Enter the value0.5(per-unit) in theSpeed Referencefield in theOperating Mode Variables > Motor speed control modearea.

3.Enter the value0.8(per-unit) in theSpeed Referencefield.

4.打开仿真数据检查,选择Speed_ref_PUandSpeed_fb_PUsignals, and observe the speed step response.

5.Tune the control gainsKpandKifor the speed controller. Perform step change to validate the controller gains.

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 model, run (and control) the motor in a selected operating mode, and monitor the debug signals of the model.

Required Hardware

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

For connections related to the preceding hardware configuration, seeLAUNCHXL-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.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, seeRun 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, seeQuadrature Encoder Offset Calibration for PMSM Motor.

5.Open the target model for the hardware configuration that you want to use. If you want to change the default hardware configuration settings for the model, seeModel 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, program that operates the CPU2 blue LED by using GPIO31 (c28379D_cpu2_blink.slx).

NOTE:

  • Do not directly switch between the open-loop run, torque control, and speed control operating modes. Always stop the motor before changing the operating mode.

  • Before you run the motor in speed control mode for the first time, run the motor in open-loop to determine the quadratue encoder index. This helps to start the motor smoothly in the closed-loop speed control mode.

Instructions for Open-Loop Run Mode:

1.ClickBuild, Deploy & Starton theHardwaretab to deploy the target model to the hardware.

2.Click thehost modelhyperlink in the target model to open the associated host model.

3.In the model initialization script associated with the target model, specify the communication port using the variabletarget.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.

4.ClickRunon theSimulationtab to run the host model.

5.SelectStopin theControlarea to stop the motor.

6.SelectOpen loop runto start the motor.

7.Set the reference voltage and reference speed values (in per-unit) in theVoltage ref (PU)andSpeed ref (PU)fields available in theOperating Mode Variables > Open-loop modearea.

Instructions for Torque Control Mode:

1.ClickBuild, Deploy & Starton theHardwaretab to deploy the target model to the hardware.

2.Click thehost modelhyperlink in the target model to open the associated host model.

3.In the model initialization script associated with the target model, specify the communication port using the variabletarget.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.

4.ClickRunon theSimulationtab to run the host model.

5.SelectStopin theControlarea to stop the motor.

6.Enter the value0(per-unit) in theId Ref (PU)andIq Ref (PU)fields in theOperating Mode Variables > Motor torque control modearea. In addition, set the speed limit of the motor using theSpeed limit (PU)field.

7.SelectTorque controlin theControlarea.

8.Move the slider switch toUnlockposition in theOperating Mode Variables > Motor torque control modearea.

9.SelectIq_refforMonitor Signal #1andIq_measforMonitor Signal #2in theMonitorarea.

10.Enter the value0.1(per-unit) in the in theIq Ref (PU)field (in theOperating Mode Variablesarea) to start running the motor.

11.Open the scope in the host model and monitor the Iq_ref and Iq_meas current signals.

Note:的年检or can reach high speeds if you run it under no load condition in this operating mode. In addition, the motor will not meet the Iq reference current under no load condition in this operating mode.

Instructions for Speed Control Mode:

1.ClickBuild, Deploy & Starton theHardwaretab to deploy the target model to the hardware.

2.Click thehost modelhyperlink in the target model to open the associated host model.

3.In the model initialization script associated with the target model, specify the communication port using the variabletarget.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.

4.ClickRunon theSimulationtab to run the host model.

5.SelectStopin theControlarea to stop the motor.

6.Enter the value0.5(per-unit) in theSpeed Ref (PU)field in theOperating Mode Variables > Motor speed control modearea.

7.SelectSpeed controlin theControlarea.

8.SelectSpeed_refforMonitor Signal #1andSpeed_measforMonitor Signal #2in theMonitorarea.

9.Open the scope in the host model and monitor the Speed_ref and Speed_meas output signals.

Instructions for Tuning Gain of Torque Controller:

1.ClickBuild, Deploy & Starton theHardwaretab to deploy the target model to the hardware.

2.Click thehost modelhyperlink in the target model to open the associated host model.

3.In the model initialization script associated with the target model, specify the communication port using the variabletarget.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.

4.ClickRunon theSimulationtab to run the host model.

5.SelectStopin theControlarea to stop the motor.

6.SelectTorque controlin theControlarea.

7.Turn the slider switch toPos lockposition in theOperating Mode Variables > Motor torque control modearea.

8.SelectId_refforMonitor Signal #1andId_measforMonitor Signal #2in theMonitorarea.

9.Enter the value0.2(per-unit) in theId Ref (PU)field in theOperating Mode Variablesarea.

10.Open the scope and monitor the step response signal.

11.Tune the control gainsKpandKifor thed-axis current controller.

Instructions for Tuning Gain of Speed Controller:

1.ClickBuild, Deploy & Starton theHardwaretab to deploy the target model to the hardware.

2.Click thehost modelhyperlink in the target model to open the associated host model.

3.In the model initialization script associated with the target model, specify the communication port using the variabletarget.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.

4.ClickRunon theSimulationtab to run the host model.

5.SelectStopin theControlarea to stop the motor.

6.SelectSpeed controlin theControlarea.

7.SelectSpeed_refforMonitor Signal #1andSpeed_measforMonitor Signal #2in theMonitorarea.

8.Enter the value0.5(per-unit) in theSpeed Ref (PU)field in theOperating Mode Variables > Motor speed control modearea.

9.Open the scope and observe the reference and the measured speed values.

10.Enter the value0.8(per-unit) in theSpeed Ref (PU)field.

11.Observe the speed step response in the scope.

12.Tune the control gainsKpandKifor the speed controller.

Instructions for Validating Plant Model:

1.Open the target model included with this example.

2.ClickRunon theSimulationtab to simulate the target model.

3.Open themcb_pmsm_operating_mode_f28379d > Simulate Dashboardsubsystem.

4.If the current operating mode is other than speed control, selectStopin theControlarea to stop the motor. SelectSpeed controlin theControlarea.

5.Enter the value0.2(per-unit) in theSpeed Referencefield in theOperating Mode Variables > Motor speed control modearea.

6.Enter the value0.5(per-unit) in theSpeed Referencefield.

7.打开仿真数据检查,选择Speed_ref_PUandSpeed_fb_PUsignals, and observe the speed step response.

8.ClickBuild, Deploy & Starton theHardwaretab to deploy the target model to the hardware.

9.Click thehost modelhyperlink 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_host_mode_control.slx');

10.In the model initialization script associated with the target model, specify the communication port using the variabletarget.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.ClickRunon theSimulationtab to run the host model.

12.SelectStopin theControlarea of the host model to ensure that the motor is not running.

13.SelectSpeed controlin theControlarea.

14.SelectSpeed_refforMonitor Signal #1andSpeed_measforMonitor Signal #2in theMonitorarea.

15.Enter the value0.2(per-unit) in theSpeed Ref (PU)field in theOperating Mode Variables > Motor speed control modearea.

16.Open the scope and observe the reference and the measured speed values.

17.Enter the value0.5(per-unit) in theSpeed Ref (PU)field.

18.Observe the speed step response in the scope.

19.Compare the speed step responses obtained in steps 7 (with simulation) and 18 (with code generation).

NOTE:In theControl loop gainsarea, you must enter the gain values that can be represented by the datatype defined in the model initialization script.

For details about the serial communication between the host and target models, seeHost-Target Communication.