Implementing Embedded Speed Control for Brushless DC Motors: Part 5 - Embedded.com

Implementing Embedded Speed Control for Brushless DC Motors: Part 5

Voltage-over-frequency (V/f) open loop control is based on threeassumptions:

1) Motor impedance increasesas the frequency increases.
2) A fixed amount of current ismost desirable.
3) Motor speed can be increasedeasily by increasing the frequency andrelated voltage.

Typical V/f control is run from table-based values of for voltage(the tqdat variable in ourcode) and frequency (delta thetavariable inour code ), as illustrated in Figure39 , below. Notice that low frequencyvalues require lower voltage values. 

Figure39. V/f open loop control with current behavior and operational points.

When the commanded frequency increases beyond the Wops value, theonly possible control is to increase the applied synchronous frequencywhile holding the voltage level steady at 100 %. Table values from Wminto Wops, as plotted on the chart in Figure39 above , are determined in thelaboratory by observing the current, which is generally kept constant.

When the frequency increases beyond the Wops value, the currentvalue decreases. Most of this decrease in current comes from thegeneration of back-EMF current by the rotating magnetic field. At Wmaxspeed, current becomes minimal. Generally we do not drive the motorbeyond this maximum speed.

Figure40. Firmware flow for open loop V/f control without any speed feedback.

V/f open-loop control, illustrated in Figure 40 above , starts with adesired motor speed. Firmware looks up the table values to set thecommand frequency and pre-determined voltage level. The timer isinitialized and three sine waves are generated at the commandedfrequency and voltage level.

An interrupt routine handles the sine wave generation using PWMvalues. No feedback is given regarding the motor speed; we assume thatthe motor is running at the speed desired. This type of control isknown as open-loop control – no closed loops whatsoever are used.Generally, Wmin and Wmax depend on the motor plus load and Wops isdetermined by the system configuration.

This control method has two main advantages. First, it requires nomeasurement of current or speed. Second, it uses a simple algorithmthat is easy to implement. With some experimentation, we can rotate anyBLDC motor without knowing the details of its parameters. Thissimplicity, however, also has its disadvantages. Without feedback, wedo not know at what speed the motor is running. If the load isvariable, the motor speed will be variable also. If the system requiressome form of speed control, a speed sensor can be added.

However, this moves us to a closed-loop control system. Theopen-loop method provides no reading of the current, so an overcurrentcondition is possible. To protect against this condition, a shuntcurrent resistor can be used to measure the steady-state current. Thistechnique gives some feedback regarding speed as well as overcurrent.It may also give some feedback about the load on the motor. Adding ashunt current resistor is relatively easy and again moves us to a formof closed-loop control.

Open-loop implementation example
In Figure 41 below we haveimplemented open-loop control to show a profilewith three-speed motor operation. We start the speed profile at 5seconds by commanding a low speed of 2400 RPM. We use a ramp in speed,shown in Figure 42 below , toreach the commanded speed and we also use a rampin voltage. We begin generating a sine wave with a commanded value of1200 RPM (20Hz) and voltage (torq) value of 50% (32), because voltageis scaled 100% using a 2^6 format.

During the interrupt processing, we create a “near zero” flag whenthe angle (or sin_pt ) is nearzero. In the main routine, when the nearzero flag is true, firmware changes the commanded speed by a smallamount (for example, 120 RPM )and also increases the torq value by 1.Based on the speed and torq start and stop values, different rampprofiles will be generated.

Figure41. Speed profile with three different speed values as a function oftime.

Figure42. Speed ramp from 40 to 100 Hz as a function of time

The motor is run at low speed for 60 seconds and then the speed isincreased to a medium value of 3000 RPM. The motor reaches medium speedusing the same ramp module. Then the motor is run for an additional 60seconds and the commanded speed is increased to its high speed value of3600 RPM.

We run the motor for 60 seconds at high speed, then slow it down to1200 RPM and stop it. We wait for 5 seconds, change the index offset,and start the motor again. This time we run the motor in reverse—animportant step, because we want to be sure that the motor has thisability.

Within the interrupt code, we use a port pin to output high (1) andlow(0) state. When we enter the interrupt processing module, we outputhigh (1) state on this port pin. When the interrupt processing iscomplete, we output low (0) state on the pin. In this way we canmeasure the CPU bandwidth, as Figure43 below shows. The rising-edge torising-edge time is our carrier-frequency time period, and therising-edge to falling-edge time is the time it takes the firmware toexecute the interrupt-processing routine.

Figure43. CPU bandwidth measurement for open loop sinewave.

At a 16kHz carrier frequency, the measured interrupt time is62.60 microseconds, whereas the calculated value is 62.50 microseconds.Our result is withinthe measurement error. The execution time is measured as 33.56microseconds, whichgives us a CPU bandwidth usage over 50%. Thus more than half of theavailable CPU processing time is used in this interrupt.

However,interrupt processing is the only time-critical task that the CPU has todo in this open loop implementation. Although not ideal, our open loopimplementation is reasonable because it leaves about 50% of the CPU'stime for performing other non-critical tasks. For closed loop, we willneed to add other time critical tasks that will require us to reducethe CPU bandwidth for sine wave generation task.

Optimizing the sine code
Our next step is to optimize the code for sine wave PWM execution timefor three reasons:
(1) If we want to increase thecarrier frequency from16kHz to 20 or 25kHz, then, the interrupt time is 50 and 40 ?srespectively. In this case, the CPU bandwidth usage will be 66% and 80%which is generally not acceptable.
(2) We want to addtime-criticalspeed and current measurement tasks, and
(3) We want to add interruptdriven closed loop control code, which is a time-critical task also.

Therefore, it is better to reduce the Sine wave PWM execution timeearly. To improve performance, we'd like to reduce the CPU bandwidthusage from its current level of over 50%. First we measure individualtimes for each PWM computation, including table lookup and longmultiplication. We are looking for ways to avoid table lookups becausethey take a lot of time. A significant amount of time is also beingspent in MAX-MIN checking. If we can avoid some of this computation, wewill save more CPU bandwidth. After detailed analysis, we implement thefollowing changes in our code:

Change #1 . Instead ofcomputing the sine value for W index, wesimply use the sum of the U and V sine values. This is true for onecase only: when all three sine waves are 120 degrees apart. If theindex difference between U, V, and W is not 120 degrees, then suchreplacement cannot be made. Since this technique is applicable to ourimplementation, we now save the time required for table lookup, longmultiplication, and scaling.

Change #2. We study theupper and lower bounds of the table as wellas the torq voltage variable in our code and guarantee by design thatthe PWM values generated by our equations will not require MAX-MINchecking. Then we eliminate these checks. This process saves more CPUbandwidth but requires that we spend time reviewing the entire code forsuch a guarantee.

Change #3 . Finally, aftermaking sure that we have generated aproper sine wave, we turn on the compiler optimization flag.

Listing2

The optimized code is shown in Listing2, above. Running this optimizedcode, we measure the CPU bandwidth again for comparison. As Figure 44below shows, the CPU interrupt-processing time is now 14.31ms,down from33.56ms required for the original code. This is a reduction of morethan 50% and thus CPU bandwidth usage is significantly lower. For a16kHz carrier frequency, interrupt time is now 62.5ms, which translatesinto 22.9% CPU bandwidth usage versus 53.7% with the original code.These improvements give firmware designers the freedom to addtime-critical sensor measurement and closed loop control tasks that areuseful in motor control.

Figure44. CPU bandwidth for optimized code

Closed-loop scalar control
Since we have optimized the sine-wave implementation, let's nowinvestigate closed-loop control using a scalar formulation. Closed-loopcontrol requires some type of position sensor that can measure speed,as shown in Figure 45 below.

Figure45. Closed loop speed control using position sensor and input capturetimer.

We can get the required position feedback from a single Hall-sensorthat gives one pulse per mechanical rotation, a tachometer sensor thatoutputs eight pulses per mechanical rotation, or from a Hall commutatorthat gives six signals per electrical rotation.

An input-capture function coupled with the proper counter providestwo measurements: elapsed time from one input capture to a second inputcapture, and change in rotor position. Both measurements togetherprovide the speed measurement. As we can infer from Figure 45 above ,  therotor position can be detected at every input capture, and using theprevious input capture data, the speed of the rotation can be computed.

Since we obtain the desired speed or speed command from a pre-setprofile, it is easy to implement a proportional-integral (PI) speedregulator as shown below.

A similar algorithm is deployed for the new voltage value of thesine wave. Thus, two parameters are computed for each speedmeasurement: a new sine frequency and a new sine voltage. In manydesigns, voltage calculations are not implemented because the motor atthat point is already running at the operational voltage and there isno need to change it. In such cases, eliminating the voltagecalculations saves CPU bandwidth.

Another form of control is based on theproportional-integral-derivative (PID) algorithm. In this method, aderivative term is added to the equation using the change in the errorterm.

Other terms remain the same. This method offers excellent control ofacceleration and braking and is preferred by many experts.Disadvantages of PID, however, are convergence time and stability ofthe control. Depending on the gain values, the PID algorithm may reactto small changes and continually perturb the system performance. Basedon his experience, the author prefers to implement PI type control.

Hall processing
Let's take a look at the sensor processing steps and CPU time necessaryto implement closed-loop scalar control. We use asingle-pulse-per-rotation Hall-sensor for this implementation. Afree-running, downcounting timer is started during initialization.

Then, at every Hall interrupt, this timer is stopped and the countsare moved into a variable called New_Meas .The timer is reset orreloaded and started again. A flag called new_data is set for the nexttask.

When the new_data flag isset, the process_hall modulecomputes thespeed. The module checks for conditions such as underflow or overflowand then calculates speed, based on one pulse per rotation. If we haveimplemented the type of Hall-sensor generally used for commutationsignals, then speed is computed based on 60 degrees of electricalrotation. Next, the speed computation is converted into mechanicalspeed using proper transformation based on the number of pole pairs.

The new_data flag iscleared for the measurement task and a flag isset for the speed regulator, which we call the velocity regulator. Oncethe new flag has been set, the velocity regulator processes the newspeed measurement and creates new values for frequency and voltageusing one of the formulas previously described.

Running closed-loop control of our BLDC motor using Hall sensors andother sensors gives preliminary measurement results such as those shownin Figure 46 below . Theexecution times for the two tasks are as follows:

Process_halls             16 µs everyHall interrupt
Velocity_regulator    10 µs every speed measurement to every Hallinterrupt

Figure46. CPU bandwidth measurements for sensor and closed loop speed control

Now we'll analyze CPU bandwidth usage for this closed-loop control.Sine wave PWM interrupt processing time is 15 microseconds. At a 16kHzcarrierfrequency, this time is 16000*15, which gives an interrupt-processingtime of 240000 µs.

This time period, which is required to generate a proper sine waveat a given frequency, represents nearly 24% of the CPU bandwidth at the16kHz carrier frequency. Note that the sine wave PWMinterrupt-processing execution time is not dependent on the speed. Thisis good news, because firmware designers will not have to calculate CPUloading every time the speed changes. The CPU usage turns out to benearly constant at every speed.

Our execution time for speed measurement or Hall process is 16µs. Let's use the case in which one Hall signal is sensed andprocessed per rotation. Because the number of times Hall processingmust be performed depends on the speed of the motor, the processorbandwidth required for speed measurement will also be speed dependent.

We will create a table, called Table4 , below, for two different speeds.Note that velocity- or speed-regulator execution time is 10 µs,and isalso speed dependent. This measurement also has an entry in our table.We compute the CPU bandwidth for two speed values -100Hz and 200Hz(indicating that each task must beprocessed 100 and 200 times ). Asshown in the last column of Table IV, the CPU bandwidth increases veryslightly, from 24% to 24.2% and 24.5%. That is not much of an increaseat all.

Table4. CPU Bandwidth calculations for one sensor measurement and onecontrol processing per mechanical rotation

We also want to calculate the CPU bandwidth for a case in whichtypical Hall commutation signals are used for speed measurements. Ourmotor has four pole pairs, and thus four electrical rotations per onemechanical rotation. Since there are six commutation signals perelectrical rotation, the number of Hall processes has now increased bya factor of 24. We average the speed measurements for one electricalrotation and apply the velocity regulator once per electrical rotationor four times per mechanical rotation. The corresponding CPU bandwidthcalculations are summarized in Table5,below .

In this case, sine-wave generation requires the same bandwidth asbefore, while speed measurement and speed control is done more oftenand therefore require more bandwidth. However, the increase in CPUbandwidth is still not much: bandwidth usage increases from 24% to 28%and 32 %, which is an increase of only about 4% for every 6000 RPMincrease.

It's important to point out that we made our calculations to showhow the CPU bandwidth usage increases. The designer must still decidehow to set the speed measurements and control-loop timings. If othertasks will be impacted by the 4% bandwidth increase, perhaps they canbe scaled back. This kind of tweaking may have an impact on speedaccuracy, but that is what optimization is all about. As we sawpreviously in Table 4, we can always perform speed measurement andspeed control tasks only once per mechanical rotation to reduce the CPUbandwidth.

Table5. CPU Bandwidth calculations for 4-pole-pair motor. (24 times sensormeasurement and 4 times control processing per rotation.)

V/f open-loop control vs closed-loop scalar control We havediscussed in detail the methods for V/f open-loop andclosed-loop-scalar control and evaluated the CPU bandwidth requirementsfor each. Now let's compare features and benefits of each type ofcontrol method.

As the name implies, V/f open-loop provides no feedback regardingspeed, while closed-loop control performs speed measurement using somesort of position sensor—for example, commutation Hall-sensors; a singleHall-sensor; an encoder with A, B quadrature and Z zero synch pulses;or a tachometer with multiple pulses per rotation.

In both the open- and closed-loop methods, the MCU generatessinusoidal modulation to the inverter drivers. However, speed-controlaccuracy differs significantly. Because the open-loop method does notprovide either feedback correction or control of the speed, theaccuracy is poor.

With closed-loop scalar control, on the other hand, the feedback onactual speed and the corrections made to the frequency and voltagegeneration result in highly accurate speed control. The motor rotatesvery close to the commanded speed in scalar control. No suchexpectation is possible in open-loop control, though, which cannot eventell us at what speed the motor is running.

Torque control is not applied in open-loop control, and itexistsonly indirectly in scalar control. In terms of MCU resources, bothcontrol methods require athree-phase timer unit with dead-time insertion capability. Open-loopcontrol requires no further resources except monitoring for highcurrent and high temperature conditions that would call for emergencyshutdown.

In scalar control, however, the MCU must have an additional timer tomeasure the time between two position pulses, as well as input capturewith interrupts. The V/f open-loop control method is relatively easy toimplement at minimal cost, while the need for sensors makes scalarcontrol somewhat more expensive.

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

Next in Part 6: The use ofvectorcontrol to control torque and flux.
To read Part 4: go to 180degree modulation for brushless motorcontrol.
To read Part 3, go to Pros and cons of sensor vs sensorless motorcontrol
To read Part 2, go to Brushless motor control using Hall sensorsignal processing
To read Part 1, go to Thebasics of brushless motor control.

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.

Leave a Reply

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