1.1.1.5 Field Oriented Control Implementation

The generated code from the Harmony QSpin intends to achieve following goals:

  • to spin a motor based on simple user inputs

  • to be modular and maintainable

  • to be a clear example to Microchip customers for a motor control Application using Microchip's 32 bit MCU devices

The following section describes an overview of control software architecture to meet the above mentioned goals.

Software Description

The software spins a motor using a velocity control loop, with an inner current loop using field-oriented control (FOC) to manage motor current and torque. Sensorless estimation techniques are used to estimate motor position for commutation and velocity control. User input is provided with a potentiometer and buttons to start and stop the motor, or to reverse direction. A state machine is used to control the transitions between these different modes of operation.

The motor startup process involves so-called “open-loop” operation. When the motor is at rest or moving very slowly, the sensorless estimator is not accurate enough; instead, a special set of states is provided to manage startup, in which commutation is forced at a desired acceleration rate, and the velocity control loop is disabled.

Software Architecture

The software performs following tasks:

  • Microcontroller and motor control peripheral initialization

  • FOC State machine in ADC ISR

  • Motor start and stop command by GPIO button

  • Motor speed command from potentiometer

Motor control peripheral initialization

On power-on reset, the software initializes the microcontroller and motor control peripherals according to the user requirements.

Motor control state machine

The software implements the motor control tasks in ADC ISR. The ADC ISR incorporates following states:

  • Idle. In this state, the motor does not spin. The software waits for a valid button press from the user to start the motor.

  • Start-up. In this state, the software executes the PMSM start-up procedure as described in Start-up Configurator.

  • Close-loop speed control. In this state, Control switched to closed loop and rotor angle is obtained from the configured position feedback method.

Motor speed command from potentiometer

The software calculates the speed reference from the measured from the potentiometer input.

Motor start and stop Command by GPIO

The software polls the GPIO button every 10ms to check if the button has been pressed. If the button press is detected, the firmware changes the motor control state from “Idle” to “Start-up” to initiate the motor spin at the specified reference speed.