Main Content

Quadrature Encoder Offset Calibration for PMSM Motor

This example calculates the offset between thed设在转子和编码器指数脉冲的职务n 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 thed-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:

You can use these models only for code generation. You can also use the open_system command to open the Simulink® models. 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_f28069mandmcb_pmsm_qep_offset_f28069mLaunchPad

  • Motor Control Blockset™

  • Embedded Coder®

  • C2000™ Microcontroller Blockset

  • Fixed-Point Designer™

2.For the model:mcb_pmsm_qep_offset_f28379d

  • Motor Control Blockset™

  • Embedded Coder®

  • C2000™ Microcontroller Blockset

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

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. TheIncorrect motor directionLED in the host model turns red to indicate that the motor is running in the opposite direction. When the LED turns red, you must reverse the motor phase connections (from ABC to CBA) to change the direction of rotation. The host model displays the calculated offset value.

Required Hardware

This example supports these hardware configurations. 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, seeF28069 control card configuration.

To configure the modelmcb_pmsm_qep_offset_f28379d, set theInverter Enable Logicfield (in the配置panel of target model) to:

  • Active High: To use the model with BOOSTXL-DRV8305 inverter.

  • Active Low: To use the model with BOOSTXL-3PHGANINV inverter.

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, seeLAUNCHXL-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, seeModel Configuration Parameters.

3.Update the motor parameters in the配置panel of the target model.

  • Number of Pole Pairs

  • QEP Slits

  • PWM Frequency [Hz]

  • Data type for control algorithm

  • Vd Ref in Per Unit voltage

4.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.

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

6.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. 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, seeHost-Target Communication.

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

7.In the host model, open the blocks Host Serial Setup, Host Serial Receive, and Host Serial Transmit, and select aPort.

8.ClickRunon theSimulationtab to run the host model. The motor runs and calibration begins when you start simulation. After the calibration process is complete, simulation ends and the motor stops automatically.

9.See theCalibration Statussection to know the status of the calibration process:

  • TheCalibration in progressLED turns orange when the motor starts running. Notice the rotor position and the variation in the offset value in the Scope (the position signal indicates a ramp signal with an amplitude between 0 and 1). After the calibration process is complete, the LED turns grey.

  • TheCalibration completeLED turns green when the calibration process is complete. Then theCalibration Outputfield displays the computed offset value.

  • TheIncorrect motor directionLED turns red if the motor runs in the opposite direction. Then theCalibration Outputfield displays the value "NaN." Turn off the DC power supply (24V) and reverse the motor phase connections from ABC to CBA. Repeat steps 5 to 8 and check if the Calibration complete LED is green. Verify that theCalibration Outputfield displays the offset value.

Note: To immediately stop the motor, click theEmergency Motor Stopbutton.

This example does not support simulation. The example automatically saves the computed offset value in thePositionOffsetvariable available in the base workspace.

For examples that implement FOC using a quadrature encoder sensor, update the computed quadrature encoder offset value in thepmsm.PositionOffsetparameter in the model initialization script linked to the example. For instructions, seeEstimate Control Gains and Use Utility Functions.