From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Field-Oriented Controller (FOC) / Space-Vector Controller for a Brushless DC Motor Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW FPGA Module
  • LabVIEW

Code and Documents

Attachment

Download All

Overview

This set of code provides an example implementation of a Field-Oriented Controller (FOC) or a Space-Vector Controller used for controlling a brushless DC (BLDC) motor.

 

Description

Brushless motors have significant advantages over the more common brushed DC motor including increased efficiency, reduced electromagnetic interference (EMI), reduced required maintenance, etc. However, the increased complexity of the motor also requires a more sophisticated control system to make it run properly. The typical BLDC controller requires either hall effect sensor, encoder, or current feedback (frequently a combination of the types of feedback).

 

Various methods of control have been developed for a BLDC motor, from simple 6-phase stepping controlled by hall sensor feedback to sinusoidal control where the control system generates 3-phase sinusoidal voltages to drive the motor, to Field-Oriented control. This block of code focuses on the third control method, the basis of which involves a transformation matrix that takes the currents in the motor windings and represents them in a rotating coordinate system (directions d and q) attached to the rotor. The control system then uses three PI loops to control the speed and the currents in the rotating coordinate system. Current in the "q" direction generates pure torque while the current in the "d" direction generates pure thrust on the motor bearings. The goal is to control the "q" current to provide the proper speed while minimizing the "d" current.

 

The inverse transformations in the controller take the currents in the "d" and "q" directions and represent them as three voltage vectors in the windings of the motor, Va, Vb and Vc. Finally, the SVgen block takes the three voltages and computes the PWM duty cycles that will generate those voltages in a 6-FET bridge designed for BLDC motor control. 

The images belove show the front panel and block diagrams of the example FOC algorithm. There are 5 inputs to the controller: Ia, Ib, theta, speed setpoint, and speed. Ia and Ib are the measured currents in the coils of the brushless DC motor, and due to the known shape of the back EMF, Ic can be calculated. These can be measured with a dedicated current sensor or with a shunt resistor in series with each motor winding. Theta is defined as the angle of the rotor and is initialized so that theta = 0 at the rising edge of hall effect sensor. The speed setpoint is defined by the user, and the speed in RPMs must be calculated from hall sensor information, encoder sensor feedback or some other method of feedback.

 

There are two system constants in the controller, the PWM period and the inverse of the bus voltage. These two values tune the SVgen block to match the system parameters.

 

Each of the PI blocks has its own gains for controlling the current. These gains will be dependent on the motor, the system attached to the motor, etc. In the implementation, it is helpful to tune them one at a time. Start with a constant Vd, and a constant input to the Iq PI controller and tune Kp (Iq) and Kd (Iq). Once that is tuned, add the Id PI controller and tune its gains. Finally, add the speed feedback and tune the gains for the speed PI loop.

 

There a few important notes about testing the FOC controller:

  1. To test the Clarke and Park transformations, wiring them all in series should yield a transformation matrix equal to the identity matrix. The input to Clarke should be the same as the output from the inverse Clarke. To test this, wire Clarke to Park to inverse Park and finally flip the inputs to the Modified Clarke block (the modified version of the bloc has the inputs flipped internally so that they make the SVgen function more straightforward).

  2. To test the inverse Park and Modified Inverse Clarke transformation, wire constants to Vq and Vd. The output of Modified Clarke should be three phases of sinusoidal voltages.

  3. To test the SVgen block, replace Va, Vb and Vc with three sinusoids 120 degrees out of phase (or include the inverse Park and modified inverse Clarke with a constant Id and Iq). The output of the SVgen block should be the same as the output of a lookup table for sinusoidal (or V/f) control (a periodic shape that resembles connected "W" "M").

The attached files should be able to be used to implement a functional FOC algorithm. The zipped file contains a source distribution of the example code. A hardware implementation also requires a 6-FET (or 7-FET) motor drive with access to the individual gates. The schematic below illustrates the setup used to test this control algorithm (for this specific control algorithm, the 7th "bus level" gate was programmed to always be energized).

 

Requirements

Software:

  • LabVIEW 2012 (or compatible)
  • LabVIEW FPGA Module

Steps to Implement or Execute Code

1. Run VI.
2. Set your values for FOC and follow calculated values and PWM output on the front panel.

 

Additional Information or Resources

front 2012.PNG2012.png

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
srm@viewpointusa.com
Active Participant
Active Participant
on

Ben,

could you post your demonstration code for the cRIO?  It would be good to see the algorithm in context including the output to the FET bridge.  Same comment for the sinusoidal control method.

Stu
shrupru
Member
Member
on

Ben,

Could you please give some explaination about the working of FOC VIs you have uploaded.

Thanks

makflai
Member
Member
on

Ben,

I don't understand in what the Modified Inverse Clarke transformation make the math in SVgen VI more straightforward !!??

Could you explain me ?

Thanks, Benjamin

shane5ab
Member
Member
on

Hi Ben,

Could you please advise, all the cRIO modules which you have used for this article.

Thanks.

Demie
Member
Member
on

what do you do with the Back EMF of the BLDC motor in a sensorless situation? Capacitor?

Demie Ajayi
bmann2000
Active Participant
Active Participant
on

do you have torque speed plots of FOC control versus traditional square wave to demonstrate the result?

garrett.tetil
Member
Member
on

Can you see any way of performing this FOC control with a sensorless BLDC motor?  Thanks.

hayko
Member
Member
on

anybody can help me how can ı implement this foc algorithm in to the sbRIO 9637 , which part of these applications in fpga target or real time or host pc ???

bmann2000
Active Participant
Active Participant
on

FOC Algorithm.vi is targeted to the FPGA, if you look at FOC Block.JPG you will see the target is FPGA as bottom-right corner of image.  Try out some examples from LabVIEW help to get falimilar with the RT section communicating with the FPGA, create a few pratice programs of your own to get more famililar, then try out following this example.  You need need a dynamometer to test out a commutaion scheme for a motor if your actually going to use it in a product. Kt=Ke, just apply the opposite of the backEMF for good commutation, this FOC scheme helps you keep them in phase across the speed range.  It's also worth looking at Space Vector Modulation (SVM) as it's a neat trick to beat the Buss/2 limit on available volts.  Bear in mind this code might not work, it may just be some code lashed up to make a motor turn when unloaded, there is no test evidence of functionality or performance.  I'd be surpised if it worked using hall sensors, they won't provide the required feedback resolution.

vidya1825
Member
Member
on

Ben,

i tried to open the code in LabVIEW 2017, but is showing Fxpsim.dll missing. Can you please share the details to download or send the dll to mentioned id vidyasankarggt@gmail.com

 

Thanks,

vidya sankar.p

 

P Vidya sankar,