FOC Based Position Control of PMSM Using Quadrature Encoder

This motor control example project shows how to control the position of Permanent Magnet Synchronous Motor (PMSM) using an Encoder based Field Oriented Control (FOC) on SAME54 Micro-controller.

Description The permanent magnet synchronous motors ( PMSM ) is widely used in various industries due to its high power density, smaller size and high efficiency. The Field oriented control is one of the most popular control mechanisms for the PMSM motor for applications which requires high dynamic performance.

This example shows how to configure motor control peripherals ADC, PDEC and TCC for the control operation. The control strategy is the sensored FOC, in which rotor position is determined by the Quadrature Encoder. Position is obtained using quadrature encoder and speed is calculated from the position.

Waveforms and variables can be monitored at runtime using X2CScope.

Key features enabled in this project are:

MHC Project Configurations


MHC Project Graph

Control Algorithm

This section briefly explains the FOC control algorithm, software design and implementation.

Field Oriented Control is the technique used to achieve the decoupled control of torque and flux. This is done by transforming the stator current quantities (phase currents) from stationary reference frame to torque and flux producing currents components in rotating reference frame using mathematical transformations. The Field Oriented Control is done as follows:

  1. 1.

    Measure the motor phase currents.

  2. 2.

    Transform them into the two phase system (a, b) using the Clarke transformation.

  3. 3.

    Calculate the rotor position angle.

  4. 4.

    Transform stator currents into the d,q-coordinate system using the Park transformation.

  5. 5.

    Position and speed are controlled by position and speed PI controllers respectively.

  6. 6.

    The stator current torque (iq) and flux (id) producing components are controlled separately by the corresponding PI controllers.

  7. 7.

    The output stator voltage space vector is transformed back from the d,q-coordinate system into the two phase system fixed with the stator by the Inverse Park transformation.

  8. 8.

    Using the space vector modulation, the three-phase output voltage is generated.

Quadrature Encoder based Position and Speed Measurement :

Rotor position and speed are determined using quadrature encoder sensor. PDEC counts the decoded quadrature pulses which is the position of the rotor. In this example, counter is a free running counter and software logic is implemented to get the exact angular position from the count. Speed is calculated by measuring the number of quadrature pulses in a fixed time interval.

Rotor is first aligned to a known position by exiciting either d-axis or q-axis. Motor's position is controlled in a closed loop there after.

The following block diagram shows the software realization of the FOC algorithm.


block_diagram

Software Design

The following figure shows the various state machines of the the motor control software.


state_machine

In the software, the PMSM position control task is realized by a state machine as shown in the previous figure. The following sections briefly describe the various states in the PMSM position control:

INITIALIZE In this state, following tasks are performed:

  1. 1.

    Initialization and configuration of motor control peripherals for generation of periodic ADC triggers and ADC conversion interrupt

  2. 2.

    Current Offset measurement and calibration

  3. 3.

    Initialize PI controller parameters for speed and current control loops

START In this state, the motor control state variables are reset and the periodic ADC conversion interrupt is enabled. Control waits for the switch press.

Run In this state, the motor starts spinning. The below flow chart and the timing diagram shows the tasks performed in run state: timing_diagram

The position control is carried out in the ADC interrupt task

Development Kits

MCLV2 with ATSAME54 PIM Downloading and building the application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is apps/pmsm_foc_encoder_position_sam_e54 .

To build the application, refer to the following table and open the project using its IDE.

Project Name Description Demo User Guide
mclv2_sam_e54_pim.X MPLABX project for MCLV2 board with ATSAME54 PIM Hardware Setup and Running The Application on MCLV2 with ATSAME54 PIM
 

MCHV3 with ATSAME54 PIM Downloading and building the application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is apps/pmsm_foc_encoder_position_sam_e54 .

To build the application, refer to the following table and open the project using its IDE.

Project Name Description Demo User Guide
mchv3_sam_e54_pim.X MPLABX project for MCHV3 board with ATSAME54 PIM Hardware Setup and Running The Application on MCHV3 with ATSAME54 PIM