Permanent Magnet Synchronous Motor Field-Oriented Control
This example shows how to control the speed of a three-phase Permanent Magnet Synchronous Motor in a closed-loop fashion via Field-Oriented Control using the C28x peripherals and DMC library blocks.
Required Hardware:
This example supports two hardware configurations:
DM550 configuration:
- Spectrum Digital® F2808-based board, F2808 or F2812 eZdsp board
- Digital Motor Controller board: Spectrum Digital DM550
- Three-phase Permanent Magnet Synchronous Motor with quadrature encoder
DRV8312 Configuration:
- TI® DRV8312 Three-Phase Brushless Motor Control Kit (DRV8312-C2-KIT) with F28035 Piccolo processor
- Three-phase Permanent Magnet Synchronous Motor with Hall sensors attached to connector J10 of the DRV8312EVM board
Note: Match the characteristics of the power supply and the amplifier with the input characteristics of the selected motor.
Available versions of this example:
- DM550 + F2812 eZdsp: c2812pmsmfoc.mdl
- DM550 + F2812 eZdsp with flash-based memory map: c2812pmsmfocflash.mdl
- DM550 + F2808 eZdsp: c2808pmsmfoc.mdl
- DM550 + F2808 eZdsp with flash-based memory map: c2808pmsmfocflash.mdl
- DM550 + F28335 eZdsp: c28335pmsmfoc.mdl
- DM550 + F28335 eZdsp with flash-based memory map: c28335pmsmfocflash.mdl
- DRV8312 + F28035 Piccolo: c28035pmsmfoc.mdl
Contents
Model
The following figure shows the Permanent Magnet Synchronous Motor Field-Oriented Control example model.
Description
This example shows the use of the c2000 peripherals and DMC library blocks to control the speed and torque of a three-phase Permanent Magnet Synchronous Motor in a closed-loop fashion using the Field-Oriented Control technique.
The algorithm is implemented using an asynchronous scheduler. In this example, the pulse width modulation (PWM) block triggers the ADC conversion. ADC posts an interrupt at the end of conversion that triggers the main FOC algorithm.
In the flash version, the code is placed in the flash memory section of the processor, allowing the application to run in a stand-alone fashion.
The model is set up for the motor with the following characteristics:
DM550 configuration:
- 4 pole pairs
- 2000 slits/mechanical revolution
- Encoder index offset: 1850
DRV8312 Configuration:
- 4 pole pairs
- 3 Hall sensors attached to connector J10 of the DRV8312EVM
You may need to change the model parameters to fit your specific motor. Match motor voltage and power characteristics to the controller.
The motor is driven by the conventional voltage-source inverter. The controller algorithm generates six pulse width modulation (PWM) signals using vector PWM technique for six power switching devices. Two input currents of the motor (ia and ib) are measured from the inverter and sent to the processor via two analog-to-digital converters (ADCs).
How to Run the Example
- Open the model
- Press Ctrl-B to generate, build, load and run the controller code.
If you select the flash version, you must make the proper jumper settings on the eZdsp boards. Default jumper settings are set to execute the code from RAM, (refer to the eZdsp Technical Reference for more information). The "Flash_loader" section on the "Peripherals" tab of the "Target Hardware Resources" tab in the Coder Target pane allows you to set Flash programming options. By default, the flash memory will be programmed after building the model. This option requires installation of TI FLASH APIs available on TI's website.
High power must be applied to the Inverter before running the program. Stopping the program in the middle of its execution with high power on can damage the hardware. Use "Reset" to stop the execution of the program.
Model Calibration with DM550 and QEP
In this example, we are using a 2000 slits encoder with a 4 pole pair motor. The encoder has 2 channels (QEPA and QEPB) and an index pulse (QEPI). Figure 1: Optical encoder disk.
This means that the timer driven by the QEP will increment by 4 for each slit as per the following figure.
Figure 2: QEP signals and counter.
In this example, we will get 8000 counts per mechanical revolution which is equivalent to 2000 counts per electrical revolution, since we are using a 4 pole pair motor.
The following figure shows A-N back EMF waveform and the position of the encoder index pulse relative to the back EMF of the motor. The neutral point is obtained by connecting a star resistor network on the 3 legs of the motor.
For F281x processors:
- Phase A is the one controlled by PWM1-2
- Phase B is the one controlled by PWM3-4
- Phase C is the one controlled by PWM5-6
For F280x/F2833x processors:
- Phase A is the one controlled by PWM1A-1B
- Phase B is the one controlled by PWM2A-2B
- Phase C is the one controlled by PWM3A-3B
Spin the motor externally to get B-N 120° out of phase on the right hand side of A-N on the oscilloscope (Figure 4). Make sure that the counter driven by the encoder is increasing while spinning in this direction. The reference position of the encoder is when A-N crosses the 0V axis on its way up. Measure the time from that point to the next encoder index pulse on the right hand side and convert that time into number of counts. Put the result in the “index offset” parameter of "Edit Parameters" block in the model.
Figure 3: V_A-N waveform with index pulse.
The following picture shows the position of the B-N waveform compared to A-N:
Figure 4: V_A-N and V_B-N waveforms.
Model Calibration with DR8312 and QEP
The model concatenates the three Hall signals into a variable with Hall_A being the Least Significant Bit (LSB) and Hall_C being the Most Significant bit (MSB) of the variable.
Figure 5: Interpretation of Hall Sensor Signals:
The model is configured with one interrupt for each Hall signal. In each Hall interrupt, there are 4 meaningful Hall values that can be read; any other Hall value indicates a problem on the hardware. The Hall value read in a particular interrupt holds information about the direction in which the motor is spinning. For example, in Hall_A interrupt, reading a Hall value of 2 indicates that the motor is spinning in direction 0 and a falling edge has just occurred. The model invalidates the direction and speed, if a direction change is detected. For the speed to be valid, 2 consecutive edges with the same direction have to occur; otherwise, a flag is set to invalidate the speed.
The following logic applies to the corresponding flag updates:
- New_direction = Hall_direction
- New_valid_flag = Previous_direction == Hall_direction;
- Global_speed_and_direction_ready_flag = New_valid_flag && Old_valid_flag;
The Field Oriented Control algorithm takes a position signal from 0 to 1 reflecting an electrical revolution. If the speed signal is valid, a linear extrapolation from the hall reading will be performed to accurately estimate the position based on the measured speed.
Principle of the hall based position estimation algorithm:
- Read the halls.
- Get the value of the latest timer (timer captured from the last interrupt that triggered).
- With the current speed, convert the time that elapsed from the previous edge to an electrical angle, to accurately determine the position within the 60 electrical degrees defined by the Hall reading.
- If the speed information is not valid (speed is invalid after a direction change, at startup, motor is stopped, speed is too low...), the algorithm assumes that the position is in the middle of the 60 electrical degrees defined by the Hall reading. The maximum position signal error in these cases is therefore 30 electrical degrees.
The Hall decoder will be referenced (position = 0) when Hall_A is rising in direction 0. A Hall_position_offset variable is used to inform the FOC algorithm of the position difference between the Hall reference and the back EMF waveforms of the motor. Like the QEP example, this value has to be calibrated by comparing the Hall signals with the back EMF waveforms of the motor. In the DR8312 example, Hall_position_offset is normalized on the electrical revolution and is set to 0.57, to match the characteristics of the motor included in the DRV8312 kit.