BLDC Motor Control
Overview
The page is dedicated to how to control a brushless DC (BLDC) motor in an embedded system. This includes control methods for both trapezoidal and sinusoidal wound BLDC motors. There are many different ways to control a BLDC motor, from simple hall-effect based switching, to complex encoder based field-orientated control with space-vector modulation (if you have no idea what these mean, don't worry, read on).
Acronyms And Terminology
Subscript | Parameter | Units (metric) | Units (imperial) |
---|---|---|---|
Continuous Torque | Nm | oz-in | |
Peak Torque | Nm | oz-in | |
Continuous Stall Torque | Nm | oz-in | |
Friction Torque | Nm | oz-in | |
Continuous Current | A | A | |
Peak Current | A | A | |
No-Load Speed | rad/s | rpm | |
Rated Power | W | W | |
Terminal Voltage | V | V | |
Input Power | W | W | |
Output Power | W | W | |
Torque Constant | Nm/A | oz-in/A | |
Back EMF Constant | V/rad/s | V/krpm | |
Motor Constant | Nm/sqrt(W) | oz-in/sqrt(W) | |
Rotational Inertia | gram-cm^2 | oz-in-s^2 |
Motors
Important Parameters:
- Torque Constant: An important parameter which relates the torque to the DC current draw. All other things being equal, higher-quality motors will have a higher torque constant.
- Rated Speed: Most are rated in the range of 3000-6000rpm. The motor can be driven at slightly higher speeds than those rated by a technique that is called 'flux weakening'
- Rated Current
- Cogging torque - This is the maximum torque the motor has when it is not being driven. This causes the rotation of the axle to feel 'bumpy' if rotated by hand when it's not being driven. For smooth operation at low speeds (< 100rpm), the cogging torque has to be small (or nothing at all). You shouldn't be able to feel this 'bumpy' phenomenon on motors with small cogging torques.
- Mechanical Time Constant: The time for the motor to spin up to full speed at rated voltage. Normally between 4-10ms. High performance motors can have a time constant as low as 1ms to speed up to 30,000rpm!
- Electrical Time Constant
- Winding Inductance: High precision motors typically have lower inductance. The winding inductance has the useful property of limiting the rate of change of current through the motor, and is what allows you to use PWM to produce smooth current. The lower the inductance, the higher the PWM needed to the same current ripple.
- Number of pole pairs. The number of pole pairs is equal to the number of electrical revolutions per mechanical revolution. Typical BLDC motors have a number of pole pairs varying from 1 to 5. If the motors datasheet instead states the number of poles, this is just 2x num. pole pairs. Note that if the motor has more than 1 pole pair, you cannot orientate the motor to a known mechanical position without some type of feedback (hall-effect, encoder).
The 3 phases of a BLDC motor are usually labelled either A, B, C or U, V and W.
Cogging torque is due to the variation in airgap permanence or reluctance of the stator teeth and slots above the magnets as the motor rotates.
Ripple torque is the torque produces by the interaction between the stator and rotor MMF. Ripple torque is mainly due to fluctuations in the field distribution.
The motor windings can be wound to either give trapezoidal or sinusoidal feedback, which relates to the control methods mentioned further down on this page. As quoted by Shiyoung Lee, Ph.D., A COMPARISON STUDY OF THE COMMUTATION METHODS FOR THE THREE-PHASE PERMANENT MAGNET BRUSHLESS DC MOTOR),
The simulation results verify that mismatch of the back-EMF waveform and commutation method produces ripple rich torque. Therefore, the BLDC motor and trapezoidal(six-step) commutation and the PMSM and sinusoidal commutation are the most desirable combination to produce minimum torque ripple.
So it pays to get the right motor for the right job!
Trapezoidal vs. Sinusoidal
There are two standard ways of winding the coils. One is to produce a trapezoidal shaped BEMF, the other produces a sinusoidal shapes BEMF. Sinusoidal motors have lower torque ripple (less vibration, mechanical stress e.t.c e.t.c), but suffers from higher switching losses and greater drive complexity than a trapezoidal motor. For this reason trapezoidal motors are very common.
In a sinusoidal motor, current travels through all three windings at any point, while in a trapezoidal motor, current only flows through 2 of the 3 windings. Sinusoidal motors come under a number of names, including PMSM (permanent magnet synchronous motor), an AC servo motor, or BLAC (brushless AC, a term used by Atmel). Trapezoidal designed motors go under the name BLDC (brushless DC).
Positional Sensing
Because there are no brushes to switch the current in the windings (commutation), the position of the rotor relative to the stator needs to be known so that the current can be switched externally. There a three main methods for detecting where the rotor is:
- Hall-Effect Sensors
- An Encoder
- Zero-crossing (aka sensor-less)
Hall-Effect sensors output a voltage relative the magnetic field strength (or more technically, the magnetic flux density). Three of them are spaced 120° apart from each other and designed so that their output voltage changes rapidly as the phase coils require switching. This can make the switching electronics easy to implement. Be careful, some hall-effect sensors can be open-drain, even though the motor's datasheet suggest that the output is fully driven!
The encoder method uses, well, an encoder attached to the axle to determine rotor position. This is more complex than the hall-effect method as the encoder output requires decoding. The encoder is typically of the incremental quadrature type, which requires a counter to count the pulses and a phase detection logic to determine the direction. This feedback method can also suffer from glitches which causes the encoder count to drift from the correct value. The PSoC microcontroller has a very nice quadrature decoding component with built-in glitch filtering.
Zero-crossing has become popular in recent years due to the fact it requires no sensors, making it cheap to implement. It is the method of measuring the voltage of the floating winding during operation (1 winding is always undriven), to determine the position of the rotor. One disadvantage of this method it does not work below a minimum speed (because the voltage is too small).
Trapezoidal Control
A common example of a trapezoidal (or block) commutation cycle of a BLDC motor with hall-sensor feedback is shown in the below table. This will drive the motor in one particular direction. This can be used to form a LUT for quick hardware/software commutation.
Commutation Table | |||||
---|---|---|---|---|---|
Sensor Output | Driver Input | ||||
HS1 | HS2 | HS3 | A | B | C |
0 | 0 | 1 | X | HI | LO |
0 | 1 | 1 | HI | X | LO |
0 | 1 | 0 | HI | LO | X |
1 | 1 | 0 | X | LO | HI |
1 | 0 | 0 | LO | X | HI |
1 | 0 | 1 | LO | HI | X |
where H1, H2, and H3 are the hall-effect sensors, and A, B, and C are the motor phases of a 3-phase star-connected BLDC motor. Note that the either the high-side, low-side, or both driver inputs can be modulated with a PWM signal to provide speed control.
![](/assets/images/hall-effect-interrupts-from-bldc-motor-for-both-rise-and-fall-cb759ce1e9b1f9350e219f3759497d41.png)
The schematic below shows the hardware used in a PSoC 5 microcontroller to perform hall-effect based trapezoidal commutation. With the correct mux selects, this control method can run completely from hardware and be completely processor independent (when running at a constant duty-cycle).
![](/assets/images/psoc-bldc-schematic-luts-and-multiplexors-for-phase-drive-c9cf9074d57e93953043c56fe1dbe2da.png)
Sinusoidal Control
The benefits:
- Smoother operation/less torque ripple than trapezoidal
- Greater efficiency/less heat dissipation
- Able to run the motor at slower speeds
The disadvantages:
- Complex control
- Embedded firmware uses more flash/ROM space
- More processing power used
- Slightly lower maximum torque (although third-harmonic injection can reduce this)
- Hall-effect feedback becomes insufficient at low speed with varying loads, and optical encoders are preferred
- Back EMF feedback is not possible
Sinusoidal control (also known as voltage-over-frequency control) is more complex than trapezoidal techniques, but offers smoother operation and better control at slow speeds.
Look-up tables (LUTs) are recommended over using the sin()
function due to speed issues. The sin()
function in C is computationally intensive and can easily create delays that effect the performance of the control algorithm. The implementation of the sin()
is platform dependent, but for example, using the GCC compiler on a PSoC 5 Cortex-M3 processor, calculating the sin()
function three times (once for each phase), took approximately 24,000 clock cycles. With a processor running at 48MHz, this is about a 500us delay. Considering a 4-pole BLDC motor spinning at 6000rpm takes about 830us to move between commutation states. In each commutation cycle you want at least 6-bit resolution (64 PWM changes), and as you can see, the delay in calculating sin()
is far too large.
With a LUT that stores floats, and a small amount of float multiplication (no divide) on a embedded processor that does not have floating point hardware support (such as the ARM Cortex-M3), you could expect the look-up and assign process to take around 500-1000 clock cycles (maybe 20us at 48MHz). This is a big reduction over using the sin()
function!
![](/assets/images/16-bit-500-count-sine-wave-lut-data-graph-1-b59addb29444ee32d7e26b7a2878a8da.png)
Phase displacement. Sinusoidal control requires three PWM signal's, preferably dual-output with adjustable dead-time for synchronous switching.
Example LUT Code
The following code is an example of how to create a LUT in the C programming language. This function calculates the LUT values at run-time, using the sin()
function. In space constrained applications it may pay to pre-calculate the values and save them directly into flash. More help with the C language can be found here.
#include <math.h>
#define configBLDC_MAX_SINE_LUT_VALUE (1000)
#define configNUM_SINE_LUT_ENTRIES (500)
float _sineWaveLut[configNUM_SINE_LUT_ENTRIES] = {0};
//! @brief Populates the sine LUT
//! @details The sine LUT is placed in RAM for fast access.
//! Call as part of the initialisation sequence.
//! Shifts sinewave so that values never go negative,
//! making it easy in ISR to multiply by scaling factor to get duty cycle
//! @note Not thread-safe. Call from Bldc_MainTask() only.
//! @private
void Bldc_FillSineLut(void) {
uint16_t i = 0;
// Populate LUT
for(i = 0; i < configNUM_SINE_LUT_ENTRIES; i++) {
double radians = (((double)i/(double)configNUM_SINE_LUT_ENTRIES)*360.0)*(configPI/180.0);
_sineWaveLut[i] = (configBLDC_MAX_SINE_LUT_VALUE/2.0)*sin(radians) + (configBLDC_MAX_SINE_LUT_VALUE/2.0);
}
}
Third-Harmonic Injection
With a pure phase-neutral sinusoidal drive, the maximum phase-to-phase voltage is only roughly . This can be improved by 'injecting' the sine wave with the third harmonic. The first thing you may think is, won't this disrupt my nice and smooth sine wave control? Well, no, because as it happens, the third harmonic is in-phase with every winding (which are 120 apart), and since it is applied to every winding, the phase-to-phase waveform does not change. It does however flatten the phase-neutral waveform, making the PWM become under-modulated. You can then scale this back up to full-modulation, and gives approximately a 16% phase-to-phase voltage increase.
To implement third-harmonic injection, all you have to do is add the third-harmonic to the sine-wave LUT. The third-harmonic has an amplitude that is 1/6 of that of the fundamental (your original sine wave). You'll notice that the maximum value in the LUT has decreased. At this point, scale up all the values in the LUT so they use the full-range again.
Sensor Field Orientated Control (FOC)
The benefits:
- You can control motor parameters which relate directly to it's physical behaviour (the variables make sense to a human)
- Angle can be determined from phase currents (usually using a sliding state estimator), no encoder needed
The disadvantages:
- Greater control complexity than trapezoidal or sinusoidal
- Requires fast processor to execute necessary maths
- Requires phase current to be measured (usually with low-side current sense resistors and an ADC)
- Requires the tuning of three PID loops (usually)
Sensor field orientated control (also called vector control) is a permanent magnet motor control method that allows one to regulated both the speed and torque independently from each other. However, this form of control is more computationally intensive than trapezoidal or sinusoidal. Part of the complexity is due to the need to be able to measure both the current going through the windings, while both trapezoidal and sinusoidal only requires positional feedback. Clark (aka alpha-beta) and Park transforms (aka d-q) have to be calculated with the phase currents.
The Clark Transformation (alpha-beta)
The Clark transformation (also called the transformation, and occasionally called the Concordia transformation, but I don't know why!) is the projection of three separate sinusoidal phase values onto a stationary 2D axis.
The unsimplified Clark transformation equation is shown below: