# Implementing Embedded Speed Control for Brushless DC Motors: Part 4

Building on the fundamentals of BLDC motor operation andcontrolcovered in Part 1 , Part2and Part3 in this series, let's now turn ourattention to putting this knowledge to work, shifting from the earliersix-step 120-degree modulation to an examination of 180-degreemodulation.

We will also discuss sinusoidal modulation including anexample of code used to generate a sine wave as well. Later we willdiscuss open-loop V/f control and closed-loop control, as well as a fewlast words on vector control.

180-degree modulation

Recall that for six-step 120-degree modulation, power switches areturned on and off so that the current passes through two coils, asshown in Figure 28. Every 60 degrees we switch connections so that thecurrent flowing from coil U to V now flows from U to W. This switchingeffectively keeps the V coil free of current for the next 60 degrees.During this period when no current flows in the V coil, the back-EMFsignal generated by the rotor's magnetic field can be detected in the Vcoil. The progression of six-step coil energization is shown in Figure 29, below.

Figure29. Progression of six coil energization steps. |

Another way to understand 120-degree modulation is to look at thetiming of Up, Vp, and Wp during electrical rotation. Each phase isenergized for a time that corresponds to 120 degrees of electricalrotation. Phase Up is on for 120 degrees; Vp is on for the next 120degrees; and finally Wp is on for the rest of the cycle. Lower switchesare turned on and off to provide the path for current flow. In thisscheme, there is a period of 120 degrees of rotation in which, forexample, phase U does not create any torque on the rotor. Effectivelyeach coil is utilized at only 2/3 of its capacity.

However, if we could use each coil for the entire electrical period,we would be able to generate more torque on the rotor. So, rather thanturning on Up for 120 degrees of rotation and then waiting another 60degrees before turning on Un, what if we could keep Up on for an entire180 degrees of rotation with no long wait period before turning Un on?

This modulation scheme is viable, but only if we provide enoughtransition time between the act of turning Up off and turning Un on toprotect the switches from a short circuit. If we turn Un on before Uphas been properly turned off, we risk creating a short circuit that canexplode the power switches. The transition time required to safelyimplement this 180-degree modulation scheme is known as dead time.

Figure30. 180 degree modulation scheme using three coils at a time |

Effectively with 180-degree modulation we are passing the currentthrough all three coils at all times, inserting a small transition timeto protect the power switches each time the direction of the current isswitched.

For the first 60 degrees, current flows in from Up and from Wp andexits the Vn coil as shown in Figure30, above. The Wn coil is no longer free, as it now also passesthecurrent. Next we switch Wp and Wn so that the current directionchanges, and for the next 60 degrees, current flows in from Up andexits the Vn and Wn coils.

We continue in a similar fashion for the next four steps. In thisway, the coils are utilized fully at all times to create torque on therotor. Note that the ability to detect back-EMF is greatly diminishedbecause of the short dead time.

Generally we say that with 180-degreemodulation, there is no back-EMF detection. This statement is correctfor all practical purposes. The dead-time requirement also affects theMCU timers, as a dead-time register must be used to insert the properdelay before each phase can be turned on.

We can contrast 120-degree modulation with 180-degree modulation asfollows. The 120-degree technique uses only 2/3 of the electricalperiod to create torque and rotate the motor, whereas the 180-degreemodulation scheme uses the entire electrical period.

Torque created using 120-degree modulation contains ripples, becausetorque is applied to a coil for the first 120 degrees, is not appliedfor the next 60 degrees, and then is applied again for 120 degrees.However, because 180-degree modulation does away with the long(60-degree) wait period, the current flow is smooth and torque ripplesare mostly eliminated. Moreover, 180-degree modulation makes possiblevarious other modulation strategies such as sine modulation, quasi-sinemodulation, and space vector modulation.

Let's consider the example of a timer with a dead-time register. TheRenesas M16C/Tinyseries microcontroller unit (MCU) has a special3-phase timer, shown in Figure 31,below ,which inserts the dead time required between turning the Up and Unpower switches on and off.

Timer channel B2 generates the carrier frequency and Timer channelsA1, A2, and A4 are used with buffers to set the pulse width modulation(PWM) values for on and off counts. The first buffer holds the valuethat turns on the output when a compare match occurs. The second bufferholds the value to turn off the output on a compare match.

When the dead-time register is programmed with a value, two internalsignals—P for Up and N for Un—are modified by inserting the dead-timecount in the compare match. Then, negative signal N is turned off forUn, dead time is inserted, and positive signal P is turned on for Up.Thus our internal timer hardware makes sure that the upper and lowerswitches are protected properly.

Figure31. MI6C 3-phase time automatically inserts dead time |

The dead-time register is programmed once at the beginning ofoperation, and the count value is dependent on the characteristics ofthe power switches. Two internal buffer bits—Di0 and Di1—are programmedto generate a specific high or low output on the compare match. Thecompare-match output is high if the bits Di0 and Di1 are set to 0,1.The output is low if these bits are set to 1,0. For the second buffer,the bits are DiB0 and DiB1.

By changing the bits properly, a center-aligned or edge-aligned PWMoutput can be generated easily. Since each channel has a set of bufferbit settings, designers can change the behavior of any channel at will.

The MCU's 3-phase timer is quite versatile in its ability togenerate various modulation schemes. It can generate 180-degree, sinewave, quasi-sine wave, space vector, or any custom modulation scheme.It can also generate 120-degree modulation with 60-degree or 120-degreemodulation time. It can modulate the upper switches only, the lowerswitches only, both switches together, or one at a time every 60degrees. Because the phase timer has dual buffers—the first buffer forthe rising-edge compare match and the second buffer for thefalling-edge compare match—dual sampling of the angle is possible forbetter sine-wave generation.

Sine-wave generation Using the MCU's 180-degree modulationcapability, we can generate a sine-wave output easily. In this case,instead of a 360-degree electrical cycle period, we employ a periodcalled the carrier-wave-frequency period. During this period, wecalculate sine of the angle and set the PWM accordingly. The basicsteps to generate this sine-wave output, illustrated in Figure 32 below , are as follows:

1 . Select a carrier wavefrequency f_{c} such as 20kHz or 16kHz.

2 . Select the voltage V0 andfrequency f of the output wave.

3. Compute the phase angle ofthe voltage at every carrier-wave period.

4. Look up the correspondingsine value from the table.

5. Multiply the sine value withthe modulation ratio to generate the PWM value.

6. Transfer the PWM values tothe registers.

Figure32. Basic steps of sinewave generation. |

The basic formulas are listed below.

Let's examine in detail the steps for sine-wave generation. Threevalues are required—the carrier frequency fc, the sine wave frequencyf, and the voltage level V0. We will use fc =10kHz, f =50 Hz, andV0=100 % of the possible DC bus voltage. The maximum voltage level isVdc and the minimum voltage is zero, thus implying

V _{max} = V _{dc} and V _{min} = 0.

The sine wave is generated from a center value to a maximum value V0and then to a minimum value -V0. Therefore the center value is Vdc/2computed as

(Vmax + Vmin)/2 = ½ Vdc .

Note that V0 (at maximum 100%) is also ½ Vdc. In our case,Vdc = 160 volts; therefore, V0 = 80 volts and the center point is also80 volts. The sine wave is now calculated as

½ Vdc + ½ Vdc * Sin(theta).

We can write this as,

Vpwm = ½ Vdc + ½ Vdc* Sin (theta).

We will get Vpwm = Vmax at 90 degrees and Vpwm = Vmin at 270 degreesas expected.

The angle traversed every carrier frequency is now

theta = 2f / fc = 360 * 50 /10000 =360 / 200 = 1.8 degrees.

Also,

t = 1/fc = 1/10000 = 100 µsperiod,

Max PWM count = t *counting frequency, and

PWM max = t * 20MHz = 100 * 20 = 2000.

Because we are using a center-edged PWM generation timer, thetimer's B2 channel is ½ of this value. The timer B2 period is1000 counts, and the first PWM for the rising edge is

PWM1 = 500 + 500 * Sin (theta).

We can compare this to

½ Vdc + ½ Vdc * Sin(theta).

The second PWM for the falling edge is

PWM2 = 1000 – PWM1.

At 90 degrees, the sine of the angle is 1. We must therefore get themaximum number of counts. At 270 degrees, the sine of the angle is -1and we must get the minimum number of counts.

In summary, to generate a sine wave, we begin with theta=0 and thensetthe timer channel B2 to a value of 1000 counts for the count down. Weset the interrupt at every second underflow, which is the completion ofthe triangular center-edge waveform.

In the interrupt routine, we compute the angle, look up the sinetable, and multiply by the voltage value to compute the PWM1 value. Wecheck this value for maximum and minimum bounds and then compute PWM2.We will examine the code for this procedure in the next section.

You probably noticed that we performed a sine-table lookup ingenerating PWM. How do we create this sine table? Since the MCUperforms all calculations in integer arithmetic, we must use a scaledvalue for the sine table. We also must use a scaled value for thevoltage.

Using Microsoft Excel, we can create a sine table with one-degreeresolution similar to the one in Figure33, below . We start at zero degrees and advance the table by onedegreefor each entry, using the sine of the average angle for the index. Allsine values are computed in floating values, as shown in the thirdcolumn.

Figure33. Sine wave table and its graph with integer values |

We then convert these values to 2^13 format – that is, value 1 isrepresented by 2^13 = 8192. Next we take the floor value of thecalculation to get the sine value in integer format. For the U value,we continue with the angle computation, and for the V and W values, weadd a 240-degree and 120-degree offset, respectively, for the lookupprocess. Then we plot the three values to see if correct sine wavesresult.

Several important points should be noted. Applying a dynamicallychanging PWM voltage to the stator results in sine-wave voltage andcurrent passing through the stator. This action requires a carrierfrequency. We select the value of the carrier frequency based on howprecise and accurate the applied sine wave must be and how large atable our MCU's memory can handle. Typical carrier frequency valuesfalls in range of 2 to 20kHz.

However, many designers want to avoid the audible frequency range,so they select values of or above 16kHz. Because a single PWM signalcannot create negative current, a lower power switch is used to enablethe current to flow in the opposite direction. Positive and negativePWM output switches are required. To protect these switches, dead timemust be inserted between positive and negative signals, as we havediscussed previously. Hardware-based dead time is more accurate thansoftware based dead time and reduces CPU bandwidth usage.

With sine-wave implementation, we can improve control performanceand efficiency. However, this process requires a true 3-phase timerunit with dead time insertion for proper operation. Sine-wavemodulation is compared to trapezoidal modulation in Figure 34, below.

Figure34. Comparison of 120 deg trapezoidal and 180 deg Sine wave modulation. |

Sine-wave generation example Now let's consider how to code a devicefor sine-wave generation. We begin with a motor-control referenceplatform, shown in Figure 35. This platform consists of two boards—aStarter Kit Plus (SKP) and a Power Board. A Renesas M16C/28 series MCU,an LCD, and LEDs are mounted on the SKP. The power board has AC-to-DCconversion and an integrated power module (IPM) with six power switchesplus drivers built in. The IPM uses a heat sink, as Figure 35 below shows.

Figure35. Power and MCU board for controlling the motor. |

To measure the motor position and current in the U and V phases, thepower board provides a Hall-sensor input, an encoder input, and twoDCCT devices. Three back-EMF resistor ladders plus a fourth resistorladder for measuring the Vbus are also implemented on the board, too. Aprecision shunt resistor on the low voltage side is also included tomeasure the overall current or to perform a one-shunt current detectiontechnique for current measurements. Together these elements allow us torun various BLDC algorithms.

Figure36. Test set-up with Bodine motor. |

Our test set-up consists of a Bodine BLDC motor with two pole pairs,as shown in Figure 36, above .The MCUis used to generate a sine-wave PWM series of various frequencies, andthe current waveforms are captured by the DCCT sensors. The basicsine wave is generated as follows.

When the interrupt is entered, the MCU's firmware checks thevalidity of the new frequency update. If the update is true, the newfrequency is commanded and the delta theta for angle computation isupdated. Delta theta is presented in 2^6 format, so delta theta = 64means 1 degree, and delta theta = 96 means 1.5 degree.

The firmware then integrates the total angle, denoted as sinpt_sum,byadding the delta theta value. If the resulting sinpt_sum is greaterthan 360 degrees ( 23040 using 2^6 format), then roll-over has occurredand the sinpt_sum must be corrected to a new value by subtracting23040. Then, sinpt_sum is scaled back by a 2^6 value to get an index inthe sine table. This index is called sin_pt in our code.

The constants C4_DAT and C2_DAT in our code are based oncarrierfrequency and represent ¼ and ½ counts for thecarrier-frequency time period. For example, assume that the carrierfrequency is 10kHz. Thus, the time period is 100 microoseconds.Counting at 20MHz,it represents 2000 counts. It follows that C4_DAT = 500 and C2_DAT =1000 counts. Using the C4_DAT constant, three PWM values are computed,as shown in Listing 1, below .

As you can see, sin_pt isused as an index for the sine table.Voltage is represented by the variable tqdat, and the entiremultiplication is scaled by 2^19 because sine values are given in 2^13format and voltage values in 2^6 format. For V and W values, offset_v and offset_w variables areused. To rotate the motor forward, V and Wmust have offsets of 240 and 120, respectively. To rotate the motor inreverse, V and W must have offsets of 120 and 240. Notice that thisprocedure is not unlike running the six-step state table in reverseorder.

Next, PWM values for U, V and W are checked for PWM_MIN and PWM_MAXto protect the timer operations, and code is developed to reduce theexecution time. A PWM2 value is computed using the constant C2_DAT ,again to minimize the execution. Finally the six timer registers areloaded, with ta4 and ta41 representing the PWM1 and PWM2 for U phase.

Figure37. Current wave forms using DCCT sensors at 40 and 60 Hz sinewave. |

Since we have two buffers, we can integrate the angle for thefirst-half period and use the first index for PWM1. Then we canintegrate the angle for the second-half period and use that index forPWM2. Although this method doubles the number of sine lookups and thusincreases execution time, it also provides a higher-resolution sinewave.

Figure38. PWM output with 10kHz filtering. |

As Figure 37 above shows, wecapture the current waveforms at 40Hz and 60Hz using DCCT sensors with10kHz filtering. As Figure 38 above shows, we capture the PWMoutput from the MCU with 10kHz filtering toview the PWM. We see that the DCCT current waveforms and PWM output aresinusoidal and represent proper fidelity.

To read Part 1, go to Thebasics of brushless motor control.

To read Part 2, go to Brushless motor control using Hall sensorsignal processing

To read Part 3, go to Pros and cons of sensor vs sensorless motorcontrol

Next in Part 5: V/f open-loop controlin DC brushless DC motors

Yashvant Janiisdirector ofapplication engineering for the system LSI business unit at RenesasTechnology America.

References

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.