MATLAB Examples

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 multiple 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 or DRV8312-69M-KIT) with F28035 or F28069 Piccolo or F28M35x or F28M36x Concerto processor(To use F28M35x/F28M36x you need Texas Instruments C2000 Concerto Support Package)
  • Three-phase PMSM with optional Hall sensors attached to connector J10 of the DRV8312EVM board

Dual Motor Control Configuration:

  • TI Dual Motor Control and PFC Developer's kit TMDS2MTRPFCKIT with F28035
  • 2 Three-phase PMSM, one with optional Hall sensors attached to connector J4 of the DRV8402-based Dual-Axis DMC EVM (TMDS2MTRPFCKIT)

High Voltage Motor Control Configuration:

  • TI High Voltage Motor Control and PFC Developer's kit TMDSHVMTRPFCKIT with F28035
  • Three-phase PMSM with optional Hall sensors attached to connector H1 of the High Voltage Motor Control Kit (TMDSHVMTRPFCKIT)

TI C2000 LaunchPad with Motor Drive BoosterPack Configuration:

  • Motor Drive BoosterPack featuring DRV8301 (BOOSTXL-DRV8301) with F28027 LaunchPad (LAUNCHXL-F28027)
  • Three-phase PMSM

Note: Match the characteristics of the power supply and the amplifier with the input characteristics of the selected motor.

Available versions of this example:

Contents

Model

The following figure shows the Permanent Magnet Synchronous Motor Field-Oriented Control example model.

close
open_system('c28069pmsmfoc_ert');

Description

This example shows how to use a closed-loop Field-Oriented Control (FOC) algorithm to regulate the speed and torque of a three-phase Permanent Magnet Synchronous Motor (PMSM). This example uses C28x peripheral blocks and C28x DMC library blocks from the Embedded Coder Support Package for Texas Instruments C2000 Processors.

The algorithm in this example uses an asynchronous scheduling. The pulse width modulation (PWM) block triggers the ADC conversion. At the end of conversion, the ADC posts an interrupt that triggers the main FOC algorithm.

Configure the interrupt operation with Configuration Parameters > Hardware Implementation > Hardware board settings > Target hardware resources > External Interrupt. For more information, see docid:texasinstrumentsc2000_ug.buj0fos-1.

The example models named *pmsmfocflash.slx, place the code in the flash memory section of the processor, allowing the application to run in a stand-alone fashion.

The model is set up for motors that have the following characteristics:

DM550 configuration:

  • 4 pole pairs
  • 2000 slits/mechanical revolution
  • Encoder index offset: 1850

DRV8312 Configuration:

  • 4 pole pairs
  • Sensorless using sliding mode observer (SMO)
  • 3 Hall sensors attached to connector J10 of the DRV8312EVM (optional)

Dual Motor Control Configuration:

  • 4 pole pairs
  • Sensorless using sliding mode observer (SMO)
  • 3 Hall sensors attached to connector J4 of the Dual-Axis DMC EVM (optional)

High Voltage Motor Control Kit Configuration:

  • 4 pole pairs
  • Sensorless using sliding mode observer (SMO)
  • 3 Hall sensors attached to connector H1 of the High Voltage Motor Control Kit (optional)

LaunchPad with Motor Drive BoosterPack Configuration:

  • 4 pole pairs
  • Sensorless using sliding mode observer (SMO)

You may need to change the model parameters to fit your specific motor. Match motor voltage and power characteristics to the controller.

A conventional voltage-source inverter drives motor. The controller algorithm generates six pulse width modulation (PWM) signals using a vector PWM technique for six power switching devices. The inverter measures the current of the two motor inputs (ia and ib) input currents of the motor (ia and ib) using two analog-to-digital converters (ADCs) and sends the measurements to the processor.

close_system('c28069pmsmfoc_ert', 0);

How to Run the Example with Code Composer Studio v4, v5 and v6

  • Open the example model that matches your hardware.
  • Open Model Configuration parameters and select the required tool chain under Code Generation pane.
  • 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).
  • Press Ctrl+B to build a binary executable from example model.
  • For CCS v4 and v5 and v6, Ctrl+B automatically loads and runs the executable on the target selected.

How to Run the Example with Code Composer Studio v3.3

  • Open the example model that matches your hardware.
  • Open Model Configuration parameters and select the Texas Instruments Code Composer Studio v3.3 (C2000) as 'Tool chain' in Code Generation pane.
  • 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).
  • Press Ctrl+B to build a binary executable from example model. Use CCS v3.3 to load run the executable on the target hardware.
  • The "Flash_loader" section on the Hardware Implementation pane allows you to set Flash programming options for Code Composer Studio v3.3. Execute button in Flash_loader to load the code into flash with CCS v3.3. 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 slit encoder with a four pole pair motor. The encoder has 2 channels (QEPA and QEPB) and an index pulse (QEPI). Figure 1: Optical encoder disk.

The timer driven by the QEP increments by 4 for each slit as shown in the following figure.

Figure 2: QEP signals and counter.

The 4-pole pair motor in this example produces: * 8000 counts per mechanical * 2000 counts per electrical revolution

The following figure shows an 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 DRV8312EVM, Dual-Axis DMC EVM and High Voltage Motor Control Kit

The "Position Sensing Switch" in the model allows you to select sensorless position sensing or position sensing using Hall sensors. In case of sensorless (default), no calibration is needed. If using Hall sensors for position sensing, Hall sensors have to be connected to J10 of the DRV8312EVM board, J4 of the Dual-Axis DMC EVM or H1 for the High Voltage Kit. 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.

The "Speed Request Switch" allows you to select the source of the speed request. By default the speed will come from a normalized constant setting the speed request to half the acceptable speed range (0.5). For the DRV8312EVM, you can also select the speed request to come from potentiometer R66.

Figure 5: Interpretation of Hall Sensor Signals:

This section is not relevant if using sensor-less control. The model is configured with one interrupt for each Hall signal. In each Hall interrupt, there are four meaningful Hall values. Any other Hall value indicates a hardware problem. The Hall value read in a particular interrupt holds information about the motor's direction of rotation. 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. If the model detects a direction change, it invalidates the direction and speed of the motor. For the speed to be valid, the model requires two consecutive edges with the same direction. Otherwise, the model sets a flag 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, the model performs a linear extrapolation from the Hall reading and accurately estimates the position.

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).
  • Convert the time that elapsed from the previous edge to an electrical angle using the current speed.
  • If the speed information is not valid (speed is invalid after a direction change, at startup, when motor is stopped, when 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 motors included in the DRV8312EVM and Dual-Axis DMC EVM kits.

For the Dual-Axis DMC EVM kit, c28035pmsmfocdual.slx controls 2 motors from the same F28035 processor. Motor2 can use position sensing coming from Hall sensors attached to J4 of the Dual-Axis DMC EVM.

Fast Serial Data Monitoring:

Evaluation boards often provide serial over USB connections allowing fast serial transfers. The models running on the LaunchPads, are sending Ia and Ib currents over serial. Use c2000_host_read.slx to receive these signals on your host computer. Select the appropriate COM port matching your board in the following blocks:

  • c2000_host_read/Serial Configuration
  • c2000_host_read/Serial Receive
  • c2000_host_read/Enabled Subsystem/Serial Send

Adjust the Baud rate for your board:

  • For F28027 Launchpad, set Baud rate to 3.75e6
  • For F28069 Launchpad, set Baudrate to 5.625e6
  • For F28377S Launchpad, set Baud rate to 5e6

Run the c2000_host_read model and observe the current signals updated at 20kHz on the time scope. You can use the same technique to monitor other signals on other processors. Keep in mind that SCI_A is usually connected to the FTDI chip allowing serial transfers over USB on Launchpads, docking stations and ISO control cards. The FTDI FT2232D allows one way transfers up to 1.5Mbps while the FTDI FT2232H allows one way transfers up to 6Mbps.

Summary

This example showed how to control the speed of three-phase Permanent Magnet Synchronous Motors in a closed-loop fashion via Field-Oriented Control using the C28x peripherals and DMC library blocks. Multiple positioning techniques have been studied running on different hardware platforms.

% LocalWords:  DMC DM eZdsp DMC DM eZdsp Brushless EVM pmsmfocflash FOC QEP DMC
% LocalWords:  QEPA QEPB QEPI VBN Interpretration DM eZdsp Brushless EVM
% LocalWords:  pmsmfocflash FOC QEP QEPA QEPB QEPI VBN Interpretration