Before continuing with the explanation started in
The pre-scaler value is determined by a 2n+1 factor, with n beingthe pre-scale register value. Therefore, a pre-scaler register value of4 will select a pre-scale value of “divide by 32” (24+1) of theperipheral clock.
Once the timer is started, the mechanism to change the pre-scalervalue is limited to a single increment/decrement at the time the timeris reset and cannot be directly written by software. This is animportant point when discussing the method used to blindly step themotor during the switched-mode.
The central timer is not simply a free running timer. This timer isreset to zero at certain points depending upon the mode of operation:switched mode or auto-switched mode.
During switched mode there are no reliable zero crossing events sothe rotor position is not known. As a result the timer is based on andreset by the commutation event interrupt.
Once the rotor is spinning and reliable zero crossing events areoccurring the commutation timing is transferred to auto-switched mode.During auto-switched mode the timer is based on and reset by theZ-event controller interrupt
When changing from switched mode to auto-switched mode, specialconsiderations must be made as the timer's reset point will changebetween the two modes.
Each of the three events (Commutation,Demagnetization, and Zero Crossing ) has a corresponding timingregister. These registers are not actual timer/counters but rathercontain time values that are related to the central timer.
The timing registers are called timers in the sense that they set ormeasure a length of time based on the time base of the central timer.The Commutation timer sets a time when the controller should step tothe next phase.
When the central timer matches the time value in the Commutationtimer, a commutation event occurs. The Demagnetization timer sets atime value when the controller should expect the current in the unusedphase to have decayed after a commutation event.
When the central timer matches the time value in the Demagnetizationtimer, a demagnetization event occurs. The Zero Crossing timer measuresa time value when the controller detects a zero crossing event. When azero crossing event occurs, the value of the central timer when theevent occurred is stored in the Zero Crossing timer register.
At start-up, the motor will begin spinning by controlling the activephase and time duration “manually” for each step. A commutation eventwill occur when the programmed step time has elapsed.
At that point the central timer is reset and a new value is loadedinto the commutation timer register. The Demagnetization event willthen occur based on the time loaded into the demagnetization timer.
The demagnetization timer will simply be loaded with one-forth ofthe time value used for commutation which should be more than adequatefor most applications. The interrupt service routine:
manages both the Commuation and Demagnetization Events.
Two tables are used to determine which phase outputs are active andhow long each step will take:
const UInt8PHASE_CONFIG[ PHASE_CONFIG_SIZE ]
const Step_sRAMP[ STEP_RAMP_SIZE ].
The PHASE configuration table contains six steps. Each step defineswhich two phases are driven and which phase is used to sense BEMF. Theorder of the elements in the PHASE_CONFIG table are reversed to makethe motor spin in reverse.
The second table, RAMP, contains the “stepping blind” parameters.This table contains an array of structures. The step's structure isused to contain the step time and its associated pre-scaler.
Once the central timer is started, the pre-scaler adjustments arelimited to one count (either up ordown ). This puts some limitation on the RAMP table. RAMP tablepre-scale values cannot change more than one count between tableentries.
The actual step time is calculated based on the peripheral clockspeed, the pre-scale value, and the time value to be loaded into thecommutation timer. The example used assumes a 4MHz peripheral clock.
The step pre-scaler (ratio setting) is set to 6. This provides atime-base of 32 microsecond/count with the timer ((26+1)/4MHz). Thefirst time value of the ramp table is 150. This calculates to a firststep time of 4.8ms (150 x 32 microseconds).
The ramp table uses a constant pre-scale value to make the step timecalculations easier. The pre-scaler value may need to be changed(usually deccremented) if the motor needs to be stepped faster,requiring a finer time scale.
The ramp table in the example has an exponentially fasterprogressing step times. The “shape” of the ramp table may either belinear, exponential, or something in between. Some experimentation maybe necessary to determine what table shape works best for the targetmotor.
During the switched mode, the PHASE and RAMP tables areindependently stepped through. The Commutation timer is loaded with thestep time from the RAMP table and determines if the pre-scaler needs tobe adjusted from the pre-scaler values of the same table. TheDemagnetization timer is loaded every time a C-event occurs withone-fourth of the commutation time.
Since the RAMP and PHASE tables are of differing sizes, each tableis individually tracked. The PHASE table is looped as the phases drivenin a repeating pattern. The RAMP table is stepped through until areliable BEMF is detected.
If the end of the RAMP table is reached and suitable BEMF has notbeen detected, then a serious error has occurred. Typically, BEMF isdetectable within 3-5 steps of the RAMP.
During the first four steps of the RAMP table, any BEMF detectionsare ignored. This is to prevent spurious BEMF zero crossing events frombeing counted. After the fourth step of the RAMP, the zero crossinginterrupts are enabled.
The number of zero crossing events to be ignored is based on themotor driven, some experimentation may be necessary – just as somemotors will require more speed to obtain a reliable zero crossing pointthan others.
Therefore, the RAMP table step time, acceleration rate, and thenumber of ignored zero crossings will need to be optimized for a givenmotor.
The interrupt routine:
manages the Zero Crossing Event.
During the switched mode of operation the Z-event interrupt routinecounts the number of zero crossings detected and the C-event interruptalso checks for a Z-event for every C-event.
If the Z-events are not consecutive, the C-event interrupt clearsthe zero crossing counter and the entire process begins again. Once 12consecutive zero crossings have been detected, the process of changingto the auto-switch mode begins.
The optimum number of zero crossings before the running motor isstable and is ready for auto-switched mode will depend upon the targetmotor.
The process to enter the auto-switch mode occurs over two steps. Thefirst step prepares for the change to the auto-switch mode, and itprepares to switch the central timer over the control of the zerocrossing time.
When the minimum number of required consecutive zero crossings haveoccurred, the commutation timer is adjusted to place the nextcommutation event half way between the next zero crossing time. This isdue to the change over in the way the central timer is reset.
As stated above, while in the auto-switched mode,, the central timeris reset on each zero crossing event, just after storing the centraltimer value of when the zero crossing occurred.
The second step actually enables the auto-switched mode and performssome final housekeeping duties. These housekeeping activities includeresetting a stabilization counter, setting the commutation weightingfactor register to a fixed value, and initializing the zero crossingtime buffer.
Once in the auto-switched mode, the zero crossing event interruptroutine simply maintains the last six zero crossing time values in acircular buffer. Since there are six steps in one electricalrevolution, the buffering of the last six zero crossing times will makeit possible to determine the rotational speed of the motor.
The stabilization timer is used to allow the motor to run a fewrotations to stabilize before the duty cycle is allowed to be changed,resulting in a motor speed change. The commutation weighting factorregister is used to determine what percentage of the zero crossing timeis used to delay a commutation event.
The commutation delay value can vary with motor speed and can beadjusted based on the information contained within the zero crossingtime buffer. The delay values and any variations with motor speed willdepend upon the target motor.
Most of the work for the auto-switched mode is done during thecommutation event. The commutation event must also manage thedemagnetization time. This is performed by an index into a softwaredemagnetization table. This table is constructed using the centraltimer pre-scaler value as an index.
For a given pre-scaler value, the software demagnetization time isadded to the commutation time. Typically, a motor will require lessdemagnetization time as the motor spins faster (lower pre-scale value)because the current is lower.
The commutation event must also check for an overflow of thedemagnetization time. Once the demagnetization time has beencalculated, the commutation interrupt routine sets the commutationdelay register to determine the next commutation time based on thecurrent or previous zero crossing.
The example software is designed to accommodate an asymmetricalmotor with respect to zero crossing times. The commutation eventinterrupt routine checks for the next zero crossing direction (risingor falling) and compensates accordingly.
The commutation event interrupt routine loads the next commutationweighting factor based on the zero crossing direction. The actualcalculation of the weight factor value is performed outside of theevent to save time in the commutation event handler. The routine tocalculate the weighting factor is
The Set_Duty function waits until after the stabilization time andthen starts to calculate the commutation weighting (delay) factorsbased on the current motor speed. The routine segments the motor speedsinto five areas.
These speed areas are determined based on the linearity of themotor's weighting factors. The weighting factor is interpolated withrespect to motor speed.
For a starting point with a target motor, the areas can be dividedequally along the motor's full operating speed range with a commonweighting factor for all ranges. From this point, any speeddependencies can be observed and the speed ranges adjusted.
To adjust the weighting factor to their optimum values, the motorphases are monitored. The ideal waveform is to have the trapezoidalwaveform symmetric about its center. The motor speed is changed toenter into one of the desired speed ranges and the waveforms monitored.The rising and falling weighting factors are changed as necessary tomake the waveforms balanced or symmetric.
The final aspect in the auto-switched mode is the pre-scaleradjustment. The motor control cell automatically adjusts the pre-scalevalue based on the value of the zero crossing time. The motor controlcell attempts to keep the zero crossing time somewhat in the middle ofthe zero crossing range.
If the zero crossing time gets to be too large, the motor controlcell increments the pre-scaler value to divide the zero crossing timein half. Similarly, when the zero crossing time is too small, the motorcontrol cell will decrement the pre-scaler value to multiply the zerocrossing time by two.
This happens automatically without software intervention. Aninterrupt routine can be triggered when the pre-scaler is adjusted toallow any other zero crossing/pre-scaler based times to be adjusted asnecessary.
At this point, the motor is basically being controlled automaticallyby the zero crossing, demagnetization, and commutation event handlers.
Tuning and Debugging Considerations
The motor control cell has the capability to echo the status of thecommutation, zero crossing, and demagnetization events. Unfortunately,the pin locations for these signals are fixed by hardware andfrequently overlap with other board functions.
The solution is to use two general purpose I/Os pins and use a fewlines of software to relay the information to the pins. The commutationand demagnetization events use a single pin and the zero crossing eventhas its own pin.
For the commutation/ demagnetization pin, the idea is to set the pinhigh when a commutation event occurs and clear the pin low when ademagnetization event occurs.
When the commutation/ demagnetization pin is shown on anoscilloscope with a phase voltage signal, it is simple to determine ifenough or too much demagnetization time being allowed for that motorspeed.
The falling edge of the commutation/ demagnetization pin must occurafter the actual motor demagnetization event but not so long that thezero crossing detection is significantly delayed.
The zero crossing pin needs only to change its level each time azero crossing event occurs. This will provide an indication as to whenthe zero crossing is occurring with respect to the commutation anddemagnetization events.
These pins are vital when tuning a motor for the first time. Duringthe switched mode phase of the motor start-up, the commutation eventscan be seen via these signals.
These events are directly related to stepping through the RAMPtable. The acceleration will be seen as continually shortening steps inthe table. The demagnetization time can also be seen as the motor isbeing accelerated. The zero crossing events should start to occurwithin a few steps of the ramp table.
If the zero crossings do not occur, perhaps the motor is not beingaccelerated fast enough to generate enough BEMF to be detected. Oncethe zero crossing events are being detected, they should coincideconsistently with the commutation events. If the zero crossings aresomewhat inconsistent, perhaps the motor is being accelerated too fast.
When using debugging software, it is important to note that once themotor is spinning, breakpoints should not be used. If breakpoints areused while the motor is spinning, the code execution will be stoppedand the motor will no longer step through the phases. This may leavethe system with the output drivers active and draw large amounts ofcurrent, possibly destroying the driven MOSFETs.
With this, we have a complete sensorless brushless motor controlsystem. Until now, most people thought that sensorless brushlesscommutation could only be done using a 16 bit or 32 bit machine.
Designers today are being surprised at how inexpensively they canimplement sensorless brushless control using a low cost 8 bit machine.The magic is in the micro's motor control peripheral. The result is acost-efficient sensorless brushless control system that works reliablyover a very large speed range.
David Swanson is a principalengineer in the