Quadrature Encoder Offset Calibration for PMSM Motor

This example calculates the offset between the d-axis of the rotor and encoder index pulse position as detected by the quadrature encoder sensor. The control algorithm (available in the field-oriented control and parameter estimation examples) uses this offset value to compute an accurate and precise position of the d-axis of rotor. The controller needs this position to implement the field-oriented control (FOC) correctly in the rotor flux reference frame (d-q reference frame), and therefore, run the permanent magnet synchronous motor (PMSM) correctly.

Models

The example includes these models:

  • mcb_pmsm_qep_offset_f28069m

  • mcb_pmsm_qep_offset_f28069mLaunchPad

  • mcb_pmsm_qep_offset_f28379d

You can use these models only for code generation. You can use the open_system command to open the Simulink® model. For example, use this command for a F28069M based controller:

open_system('mcb_pmsm_qep_offset_f28069m.slx');

For the model names that you can use for different hardware configurations, see the Required Hardware topic in the Generate Code and Deploy Model to Target Hardware section.

Required MathWorks® Products

To generate code and deploy model:

1. For the models: mcb_pmsm_qep_offset_f28069m and mcb_pmsm_qep_offset_f28069mLaunchPad

  • Motor Control Blockset™

  • Embedded Coder®

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

  • Fixed-Point Designer™

2. For the model: mcb_pmsm_qep_offset_f28379d

  • Motor Control Blockset™

  • Embedded Coder®

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

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

Prerequisites

Update these parameters in the model initialization script.

1. pmsm.QEPSlits

2. pmsm.QEPIndexOffset

3. Number of pole pairs

4. Current control sample time (Ts)

5. CPU frequency of processor

Generate Code and Deploy Model to Target Hardware

This section instructs you to generate code and run the motor by using open-loop control.

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 model and run the motor in an open-loop configuration. You can use the host model to control the motor rotations and validate the direction of rotation of motor. The dashboard LED in the host model turns red to indicate that the motor is running in the reverse direction. When the LED turns red, you must reverse the motor phase connections (from ABC to CBA) to change the direction of rotation. After the target model receives the motor-start command from the host model, the motor runs in open-loop control for some time and then stops. After the motor stops running, the target model aligns the rotor to the d-axis and captures the position offset. The host model displays this offset value.

Required Hardware

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

  • F28069M controller card + DRV8312-69M-KIT inverter: mcb_pmsm_qep_offset_f28069m

For connections related to the preceding hardware configuration, see F28069 control card configuration.

  • LAUNCHXL-F28069M controller + BOOSTXL-DRV8305 inverter: mcb_pmsm_qep_offset_f28069mLaunchPad

  • LAUNCHXL-F28379D controller + BOOSTXL-DRV8305 inverter: mcb_pmsm_qep_offset_f28379d

  • LAUNCHXL-F28379D controller + BOOSTXL-3PHGANINV inverter: mcb_pmsm_qep_offset_f28379d

NOTE: When using BOOSTXL-3PHGANINV inverter, ensure that proper insulation is available between bottom layer of BOOSTXL-3PHGANINV and the LAUNCHXL board.

For connections related to the preceding hardware configurations, see LAUNCHXL-F28069M and LAUNCHXL-F28379D configurations.

Generate Code and Run Model on Target Hardware

1. Complete the hardware connections.

2. 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 target model, see Model Configuration Parameters.

3. 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), to ensure that CPU2 is not mistakenly configured to use the board peripherals intended for CPU1.

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

5. 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. For example, use this command for a F28069M based controller:

open_system('mcb_pmsm_host_offsetComputation_f28069m.slx');

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

You can use the Time Scope in the host model to monitor the rotor position and offset values.

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

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

8. Change the position of the Calibration Start / Stop switch to On, to start running the motor.

9. The dashboard LED turns green when the motor runs. Notice the rotor position and offset value variations in the Time Scope (the position signal indicates a ramp signal with an amplitude between 0 and 1).

10. If the dashboard LED turns red, stop the motor by changing the position of the Manual Switch to Motor Stop. Turn off the DC power supply (24V) and reverse the motor phase connections from ABC to CBA.

11. Repeat steps 7 and 8 and check if the dashboard LED is green.

12. After the motor runs for some time and stops, the host model displays the quadrature encoder offset in the Offset block.

Note: This example does not support simulation.

For examples that implement FOC using a quadrature encoder sensor, you must update the computed quadrature encoder offset value in the pmsm.PositionOffset parameter in the model initialization script linked to the example. For instructions, see Estimate Control Gains from Motor Parameters.