Link Search Menu Expand Document

MCHP

PMSM FOC using Reduced Order Luenberger Observer

This application implements the sensorless field oriented control (FOC) of a permanent magnet synchronous motor (PMSM). It estimates rotor position from measured phase currents and a reduced order luenberger observer (ROLO). This algorithm is implemented on a PIC32CM MC MCU.

Description

Permanent Magnet Synchronous Motor (PMSM) is controlled using Field Oriented Control (FOC). Rotor position and speed is determined using Reduced Order Luenberger Observer. Motor start/stop operation is controlled by the switch and motor speed can be changed by the on-board potentiometer. Waveforms and variables can be monitored runtime using X2CScope.

Key features enabled in this project are:

  • Dual shunt current measurement
  • Speed control loop

MHC Project Configurations

Project Graph

  • PMSM_FOC:

    • This component configures FOC algorithm parameters, motor parameters and motor control board parameters. It connects to underlying peripheral libraries ADC and TCC. This component auto configures ADC channels and PWM channels as per PMSM_FOC component configurations.
  • ADC0-ADC1 Peripheral:

    • ADC0 and ADC1 are setup to operate in Master - Slave mode with ADC0 acting as a Master.
    • Both ADCs convert single ended inputs. Phase U current is sampled and converted by ADC0 and Phase V current is sampled and converted by ADC1.
    • Both ADCs are hardware triggered simultaneously by an event generated from TCC0 at the end of each PWM cycle.
    • Conversion Ready interrupt is generated by ADC0. Since both ADCs are triggered simultaneously and have same resolution and sampling time, both ADCs complete conversion at the same time.
  • TCC0 Peripheral:

    Configured to generate three pairs of complimentary PWM signals at a frequency of 10 kHz in “Dual Slope PWM with interrupt/event when counter = ZERO” a.k.a. “Center Aligned Mode”.

    • Event output is enabled which is generated when the counter reaches ZERO.
    • Dead-time is enabled and set to
      • mchv3_pic32cm_mc_pim.X. - 2uS
      • mclv2_pic32cm_mc_pim.X. - 1uS
    • Non-recoverable Fault is enabled on EV0. When an event is detected on EV0, all PWM channels are held low.
  • EIC:
    • External Interrupt Controller detects a hardware over-current fault input and generates a non-recoverable fault event for TCC0, thereby shutting down the PWM in the event of an over-current fault.
  • EVSYS:
    • Event System acts as an intermediary between event generator and event users.
    • Event generated by the TCC0 when the counter reaches ZERO, is used by the ADC0 as a hardware trigger source via the Event System.
    • Event generated by the EIC upon over-current fault, is used by the TCC0 as a non-recoverable fault event via the Event System.
  • DIVAS:
    • This demo uses “Divide and Square Root Accelerator” to perform 32-bit signed and unsigned division and 32-bit unsigned square root operations.
    • DIVAS is set to overload “Divide - / “ operator i.e. c = a / b; would use DIVAS accelerator for division without using a special API. However, square root operation would still require a special API. Refer to the DIVAS help for more details.
  • SERCOM3 Peripheral:
    • SERCOM3 is configured in USART mode and is set to operate at 115200 bps.
    • This USART channel is used by the X2CScope plugin to plot or watch global variables in run-time. Refer to X2C Scope Plugin section for more details on how to install and use the X2CScope.

Control Algorithm

This section briefly explains the FOC control algorithm, software design and implementation. Refer to Application note AN2590 for the ROLO based estimator based sensor-less FOC technique in detail.

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. Measure the motor phase currents.
  2. Transform them into the two phase system (a, b) using the Clarke transformation.
  3. Measure the rotor position angle.
  4. Transform stator currents into the d,q-coordinate system using the Park transformation.
  5. The stator current torque (iq) and flux (id) producing components are controlled separately by the controllers.
  6. 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.
  7. Using the space vector modulation, the three-phase output voltage is generated.

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

Block Diagram

Software Design

PIC32CM MC

  • PMSM FOC Control loop is implemented in the ADC result ready interrupt. Refer to the flow chart given below.
  • ADC channel conversion is triggered by the PWM overflow/zero match event. This trigger point could vary based on the current measurement techniques and MCU PWM IP implementation.
  • For bandwidth constraints, the FOC is executed every alternate PWM cycle
  • Slow loop task is executed in every 10ms in the task process. Polling of switches for user inputs is handled in the slow loop task.

Timing Diagram

timing_diagram

Flow Chart

flow_chart

State Machine

  • Idle:

In this state, control waits for the switch press.

  • Field Alignment:

Rotor is aligned to known position at D-axis or Q-axis by applying a pre-defined value of the current for a pre-defined length of time. The magnitude of the current and the length of the time for which it is applied depends upon the electrical and mechanical time constant of the PMSM motor drive. Electrical time constant of the motor is a function of R and L values of the motor windings, whereas the mechanical time constant of the motor drive is primarily a function of the static load on the motor shaft.

  • Open Loop:

This state is applicable to sensorless position feedback methods. In this state, the speed of the PMSM motor is gradually ramped up using an open loop control. During this mode, the rotor angle is derived from the asserted open loop speed reference. This derived rotor angle would be lagging from the actual rotor angle. The speed is ramped up linearly to a minimum value required for the PLL estimator to estimate the electrical speed of the PMSM motor with sufficient accuracy. Rotor angle information is obtained by integrating the estimated electrical speed of the motor.

  • Closed Loop:

Control switched to closed loop and rotor angle is obtained from the configured position feedback method.

Code Structure

code_structure

Configurations:

  • mc_userparameters.h contains the user configurations.

PMSM FOC Application:

  • mc_pmsm_foc.c/h - PMSM FOC algorithm interface file

Interrupts:

  • mc_function_coordinator.c - Initializes and coordinates motor control ISR and slow task processes
  • mc_error_handler.c - PWM fault ISR to take corrective action on over-current

Control Middleware:

  • mc_motor_control.c/h - Implements the motor control state machines.

Control library:

  • mc_start_up.c/h - Implements the initial field alignment and open loop start-up profile.
  • mc_speed_control.c/h - Calculate and regulates the reference speed
  • mc_current_control.c/h - Controls the direct and quadrature axis currents
  • mc_rotor_position.c/.h - Calculate the position and speed of the rotor
  • mc_voltage_measurement.c/h - Get the DC Bus voltage
  • mc_current_measurement.c/h - Get the motor phase currents
  • mc_interface_handling.c/h - Manages global variables and data-types
  • mc_generic_library.c/h - FOC library
  • mc_pwm.c/h - Space Vector modulation (SVM) and updating PWM duty cycles
  • mc_ramp_profiler.c/h - Speed reference profiles for user inputs

HAL:

  • mc_hardware_abstraction.c/h - Hardware Abstraction Layer to interact with PLIBs

Development Kits

MCLV2 with PIC32CM MC Family Motor Control 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_rolo_pic32cm_mc .

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

Project Name Description Demo User Guide
mclv2_pic32cm_mc_pim.X MPLABX project for MCLV2 board with PIC32CM MC PIM MCLV2 with PIC32CM MC PIM

MCHV3 with PIC32CM MC Family Motor Control 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_rolo_pic32cm_mc .

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

Project Name Description Demo User Guide
mchv3_pic32cm_mc_pim.X MPLABX project for MCHV3 board with PIC32CM MC PIM MCHV3 with PIC32CM MC PIM


Copyright © 2020 Microchip Technology.