Implementing Embedded Speed Control for Brushless DC Motors: Part 2 -

Implementing Embedded Speed Control for Brushless DC Motors: Part 2


Let's apply what we have learned about the basics of brushlessmotor control in Part1 to the example of Hall sensorsignal processing.At every interrupt, the MCU has to execute a code that properly changesthe output state. This interrupt-based code must interpret the Hallsignals correctly and then change power-switch states, first turningoff one switch and then turning on the next.

Since Hall sensors provide polarity, we can easily determine whichHall sensor interrupt has been received by reading all three polaritylevels. A Hall sensor set-up in which rising Hall signals occur atevery 120- degree position is shown in Figure10 below.

Notice that the rising U Hall signalis at 0 degrees, the rising VHall signal is at 120 degrees, and the rising W Hall signal is at 240degrees. Because Hall sensors have a south pole located 180 degreesfrom the north pole, a falling signal will occur at the 180-degreeoffset of each rising signal, thus creating six signals over thecomplete rotation.

On receiving the first interrupt -the rising edge of Hall A – theMCU firmware reads the three interrupt input pins as 1, 0, 1 and setsthe output pins to state 1, with Up and Vn on. On receiving the secondinterrupt – the falling edge of Hall C – the MCU firmware reads theinput pins as 1, 0, 0; compares this reading to the previous state (1,0, 1); and sets state 2.

On receiving the third interrupt – the rising edge of Hall B – theMCU reads the input pins as 1, 1, 0; compares the reading to 1, 0, 0and sets state 3. The next three interrupts are processed in a similarmanner to complete the cycle.

Figure10. Six step changes for 120 deg input Hall sensors.

In this example, we need to know which sensor is A, which is B, andwhich is C. Motor manufacturers generally provide this information.Nevertheless, it's instructive and helpful to lay out the board,connect the motor, power up the MCU only (not the entire motor), andview the signals from the Hall sensors, which get their power from theMCU board. Now we can examine the sequence of Hall signals easily,turning the motor by hand for one complete rotation. The signals canalso be viewed on a scope as the motor is rotated to determine whetheror not they are 120-degree Hall signals.

If we observe 60-degree Hall signals, which means that the risingedge occurs every 60 degrees rather than every 120 degrees, then thesequence of inputs changes as shown in Figure11 below . On the first interrupt, the firmware reads 1, 0, 0instead of 1, 0, 1. The sensor changes to a state-1 configuration inwhich Up and Vn are still on.

It does not change to the state-2 configuration used in the120-degree example. On the next interrupt, the sensor reads the inputpins as 1, 1, 0 and then the firmware makes the change to state 2. Thecycle continues according to the sequence of Hall signals. Notice thatthe firmware is changed slightly and the sequence of Hall input signalsis different. For proper sensor implementation, designers must know howthe Hall sensors are mounted and how the firmware should be written.

Figure11. Six step changes for Hall sensors mounted 60 degree rising signals.

Table 2, below furthercompares two Hall-sensor configurations. Again, the best way toimplement the firmware is to perform some initial tests to determinewhat is necessary for rotation in one direction and what is necessaryfor rotation in the reverse direction. Once this information isavailable, the firmware can be implemented easily, including thecorrect rotational sequence.

It's important to note that these examples are based on a onepole-pair motor. A motor that has more pole pairs will have a largersequence on the signals in one mechanical rotation. For example, aBodine motor has two pole pairs, and so instead of six interrupts, ithas 12 interrupts per mechanical rotation. Thus, when tests areperformed to obtain the sequence of Hall signals, the motor must berotated slowly, smoothly, and continuously—otherwise, the sequenceobserved may be incorrect.

Table2. Comparison of two Hall-sensor configurations.

The C programming code for a commutation sequence for the RenesasR8C MCU is shown in Figure 12below .The case statements are translated into a compact code size by thecompiler. Individual phase voltages and voltages between U-V, V-W andW-U are shown in Figure 13.

Figure12. R8C code in C language for 6 step changes for BLDC motor.
Figure13. Phase voltages for six step trapezoidal control.

Trapezoidal control with Hallsensors
To understand trapezoidal control in a BLDC motor, let's first considerfull-speed operation. When a full voltage is turned on every 120degrees of rotation, and when proper commutation is performed accordingto the Hall-signal inputs, the motor rotates at its full operationalspeed. The MCU receives interrupt inputs and properly executes outputsaccording to the sequence desired.

The full speed at which the motor operates is determined by certaincharacteristics. The applied voltage and back-EMF are balanced so thatthe torque necessary to maintain operational speed is achieved. Figure 14 below shows a currentprofile – that is, the shape of the currents –  at full speed withinput Hall signals and six-step currents. Notice that the shape of thephase currents is trapezoidal.

As we have seen before, torque in BLDC motors is proportional to thecurrent passing through the coils. Therefore, to reduce the speed, wemust reduce the current. Torque is maintained at the necessary level bychanging the current to maintain the desired speed.

Figure14. Current at full speed operation is trapezoidal and hence the name”Trapezoidal” control.

To reduce the current in coils, voltage is modulated using the pulsewidth modulation (PWM) method illustrated in Figure 15, below. During a state,the voltage is turned on and off at a suitable frequency, known as thecarrier frequency, in a manner that applies less current to each coil.

As a result, less torque is created on the rotor and speed isreduced. A PWM timer is used to modulate the output state of the pinand thus the voltage applied to the phase. This modulation is typicallyperformed at a carrier frequency higher than the state-changefrequency. Even when the voltage is modulated, the current profileremains trapezoidal  – thus the name, trapezoidal control.

Figure15 Trapezoidal currents with modulation in lower switches.

The PWM method requires us to know carrier frequency and duty cycle.We can select an arbitrary frequency for the carrier signal we willmodulate. But how do we know what duty cycle is needed to maintain thedesired speed?

Hall sensors come to rescue again, as speed can be measured usingthe Hall signal interrupts. The angle between two consecutive Hallsignals is 60 degrees by construction, and these signals are mappedonto the interrupt pins by the MCU.

Using an MCU timer peripheral, the time between two consecutive Hallsignals can be measured and speed can be computed: It's 60 degreesdivided by the time measured between two Hall signals. To determineaverage speed, we can measure the time between six or more Hall signalinterrupts, whatever is suitable in terms of time to control the speed.Now it becomes easy to adjust the duty cycle. If the measured speed ishigh, the duty cycle is reduced. If the measured speed is low, the dutycycle is increased.

Figure16. R8C based BLDC control.

The MCU resources required for this activity include six outputpins, three input pins, one internal timer to measure the time betweentwo consecutive Hall signals. We also need one PWM timer that canmodulate each output pin, or a timer that can generate six outputsproperly with modulation, as well as one interrupt for emergencyshut-down. These resources are depicted in Figure 16 above, in which an R8C isthe MCU.

Timing example
Now let's consider an example of how timing is used in speed control.Assume that we have a BLDC motor that has two pole pairs and a maximumoperational speed of 3600 RPM. The MCU is running on a 20-MHz CPUclock, and that clock is also used for the timers and counters. Ourcalculations will be based on the following formulas:

<>Speed (Hz) = Speed (RPM) / 60 = mechanical Hz
        Mechanical Hz = 60
Electrical Hz = #pole pairs * mechanical Hz
        Electrical Hz = 120
Electrical time period or period = 1/electrical Hz;
        Period = 1/120 =8.3333 ms = 8333.3 µs
Time tH between two Hall signals =electrical Hz / 6;
        tH = 8333.3 /6 =1388.9 microseconds.

Counts between two Hall signals = Count Frequency in MHz * timebetween two Hall signals
        Counts = 20 * 1388.9 = 27,778counts in ourexample.

When we fix the counting frequency at 20 MHz and the pole-pair equalto 2, the formula can be simplified to give

Counts = 100,000,000 / RPM

This is a very simple formula.

Next we can prepare a table, shownbelow that gives RPM and corresponding counts. It's important tocheck at what RPM the size of the 16-bit counter will become an issue.In the example above, at 1200 RPM the count value is 83,333, whichcauses the counter to overflow. In fact, for a count less than 65,535,the minimum RPM is 1535. Therefore, a 16-bit counter driven by a 20-MHzclock is usable only as long as the motor speed stays above 1535 RPM.

Table3. Counts for various reference speeds. (Note: 16-bit counter overflowsbecause motor speed is too slow.)

Based on this simple formula and table, a control scheme can bedeveloped to adjust the duty cycle. We can measure counts between twoHall pulses fairly easily and thus determine whether or not a motor isrunning at the desired speed. For example, if the desired speed is 3000RPM, then we should expect 33,333 counts.

If we measure 40,000 counts, the motor is running slow and PWM dutycycle must be increased. If we measure 30,000 counts, the motor isrunning fast and the duty cycle must be reduced.

Code for such control is shown in Figure17 below , which again uses an R8C MCU as an example. The timer Cperipheral in this setup has two registers, tm0 and tm1 . Register tm1 sets up the carrier frequencyand tm0 sets up the dutycycle. Output is low (= 0) until the count reaches tm0. When the countmatches tm0 , the output isturned high (= 1). When the count matches the tm1 value, the output is set low(=0) and the counter is reset. Thus, the active duty cycle extends fromthe tm0 value to the tm1 value, and the non-active dutycycle is from 0 to the tm0 value.

Figure17. R8C code in C language for PWM duty control to achieve desiredspeed.

In our example, the register tm1 is set to a value of 1000 to get a20 kHz carrier frequency. The time between two Hall pulses is called CountMeas and the high and lowreference counts are CountRefH and CountRefL . When time ismeasured, the value of CountMeas is compared to CountRefH andregister tm0 is adjustedaccordingly.

If the measured count is higher than the reference count CountRefL , the motor is runningslow and the tm0 value isreduced to increase the duty cycle. If the measured count is lower thanthe reference count, the tm0 value is increased to reduce the duty cycle. Finally, a check is madeto protect the minimum and maximum values.

Simple code such as this works well for adjusting the duty cycle toget a desired speed. However, in a few cases this control method failsto work properly, particularly, when the increase and decrease in the tm0 register moves back and forth.Recall that we are using CountRefH and CounteRefL – not just asingle CountRef – forcomparison. This allows us to insert what is known as a dead band.

Let's say that we want our motor to rotate at 3000 RPM. From Table 3, earlier , we see that thereference count or expected count is 33,333. Now we must apply adead-band value, which is determined by the accuracy we require.

If we require 100-RPM accuracy, then we must compute values for CountRefH using 2900 RPM (34,483)and CountRefL using 3100 RPM(32,258). When RPM gets within this range, the control algorithm willstop adjusting the PWM value. Based on the control frequency, thesensor measurement frequency, and the accuracy requirements, we cantighten this dead-band value. However, we must be cautious. Too tight adead band will cause the motor speed to fluctuate between one value andanother.

Design engineers frequently use proportional-integral control andmotor response characteristics to determine gains. This approachgenerally gives a better control algorithm. We have used suchalgorithms successfully, but only after we first made the motor rotateclosed-loop using the simple approach just described. We generallysuggest such an approach.

Starting a motor. Becausemotors are started in open-loop fashion, they require a duty cyclesomewhere between 50 and 70%. This ensures that the motor has enoughstarting torque and that the rotor will turn in synchronization withthe rotating magnetic field of the stator. If the starting torque isinsufficient, the rotor may never attain a synchronous state and thefirmware may never get feedback from the Hall signals.

Generally motors are started at a 70% duty cycle with a fixedcommutation period of about 500 RPM. Once the MCU starts to receive theHall signals, the speed measurements are stabilized. Then the simplecontrol algorithm stabilizes the PWM value and the speed command is setto the desired speed.

This process works best when we make small, incremental speedchanges and allow the algorithm to follow with the appropriate PWMchanges.

Modulation schemes
Another issue in speed control is whether to modulate only the Up orboth the Up and Vn.Several approaches can be taken. Many designers prefer to modulate onlythe upper IGBT or power-MOSFETswitches, whileotherschoose tomodulate only the lower switches. These approaches are known asasymmetric modulation schemes.

If only the upper switches are modulated, then access energy isdrained out of the motor because the lower switches are always on. Ifonly the lower switches are modulated, the motor continues to storeenergy in the system.

The result may be good or bad. Asymmetric modulation createsdiffering stresses on the switches, so the control algorithm for suchmodulation has to exactly fit the operation. If the upper switches aremodulated, they are subject to greater stress and wear and tear, whichincreases the probability of their failure. If only the lower switchesare modulated, they will be more prone to failure.

Asymmetric modulation typically employs one of two schemes:120degree modulation or 60-degree modulation. As Figure 18 below shows, in120-degree modulation the upper switches are modulated as necessaryduring the entire on time. In 60-degree modulation, the upper switchesare modulated for the first 30 degrees and the last 30 degrees, withthe switch left on for the middle 60 degrees.

This 60-degree modulation scheme does not permit a full range ofoperation. In many cases, the motor can be operated only in 50 to 100%of its speed range.

Figure18 Asymmetric modulation schemes for six step control method.

Some designers modulate both the upper and lower switches. Eventhough this scheme is somewhat more complicated to implement, it allowsmore symmetrical stress and wear and tear on the switches. With thisscheme, each switch can be modulated 60 degrees at a time, asillustrated in Figure 19 below ,stressing it in a more symmetrical fashion. The scheme also works wellwith the interrupts and state-change requirements.

As we know from the six-step algorithm, a state change is requiredevery 60 degrees. Thus, when a state change is made, a switch is alsoselected for modulation. As shown in Figure 19, each switch ismodulated 60 degrees, creating an equal stress on each.

Also, the motor can operate in the full speed range, because themodulation covers the entire electrical cycle. Generally, each switchremains on for 120 degrees of electrical rotation time, and thestate-change algorithm selects which 60-degree portion will bemodulated.

Figure19. Symmetric modulation scheme that stresses all power switchesequally.

If we combine our modulation scheme, speed sensing, and PWMcomputation within our motor control firmware, then our firmwarestructure will be similar to that shown in Figure 20 below . Block 1 ensuresthat proper state changes are made to achieve 120-degree modulation.

Many times this commutation is based strictly on the MCU receivingthe Hall-sensor signals and processing them in interrupts, animplementation technique that ensures that state changes are madeproperly. Thus, if the motor is running slowly, no abrupt state changeswill be made, and the motor will maintain its synchronization.

Block 2 of Figure 20hastwo components, the first of which is used to measure speed from theHall sensors. This measurement requires the use of a timer resource.For every Hall-signal interrupt, the timer is read and reset so that itwill measure the time of the next Hall signal.

Figure20. Closed loop control method with position sensor

The second component in Block 2 uses this measured count or measuredspeed in the control algorithm to set the new duty cycle according tothe calculations discussed earlier. Notice here that we have added abus-voltage measurement into our scheme.

When AC is rectified into DC, voltage ripple can occur at about 60Hz. Often this ripple is in the 5% range – a large variation that canbe handled properly. Because the modulation runs at 20 kHz and theripple is at 60 Hz, we can correct for the ripple by accuratelymeasuring the bus voltage at the right frequency.

Experience tells us that when we make such corrections, the motorwill reach the desired speed quickly and maintain that speed properly.If we don't make such corrections, then the voltage ripple will causetorque ripple that may, in turn, cause the speed of the motor tocontinually vary above and below the set point.

To read Part 1 go to : Thebasicsof brushless motor control.
Next in Part 3: Pros and cons ofsensor vs sensorless motor control

Yashvant Jani is director ofapplication engineering for the system LSI business unit at RenesasTechnology America.

1. PowerElectronics and Variable Frequency Drives Technology and Applications,Edited by Bimal K. Bose, IEEE Press, ISBN 0-7803-1084-5, 1997
2. MotorControl Electronics Handbook, By Richard Valentine, McGraw-Hill,ISBN 0-07-066810-8, 1998
3. F IRSTCourse On Power Electronics and Drives, By Ned Mohan, MNPERE, ISBN0-9715292-2-1, 2003
4.Electric Drives, By Ned Mohan, MNPERE, ISBN 0-9715292-5-6, 2003
5. Advanced Electric Drives,Analysis, Control and Modeling using Simulink, By Ned Mohan,MNPERE, ISBN 0-9715292-0-5, 2001
6. DC Motors Speed Controls Servo Systems including Optical Encoders,The Electro-craft Engineering Handbook by Reliance Motion Control, Inc.
7. ModernControl System Theory and Application, By Stanley M. Shinners,Addison-Wesley, ISBN 0-201-07494-X, 1978
8. The IndustrialElectronics Handbook, Editor-in-Chief J. David Irwin, CRC Press andIEEE Press, ISBN 0-8493-8343-9, 1997

This article is excerpted from apaper of the same name presented at the EmbeddedSystems Conference Boston 2006.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.