Designing a MCU-driven permanent magnet BLDC motor controller: Part 2 -

Designing a MCU-driven permanent magnet BLDC motor controller: Part 2

Having reviewed the basics of BLDC motor control in Part 1, the design effort canbegin.. The first quest is to select a microcontroller. Looking in themarketplace there are several microcontrollers that might be able to dothe job.

One comes to mind that has the brushless motor peripheral set builtin for just such a task we have before us, the ST7MC family of micros.As a result the following design of a simple brushless motor controlwill be based on the ST7MC motor control microcontroller and someadditional supporting hardware.

Using a different microcontroller will mean some changes in how BEMF is sensed and how differenttimers are used. In general the same tasks discussed here using theST7MC can be ported over to other, less adapted to this application,micros.

Even the most basic of control modules have four basic components,brains (a micro), muscles (outputs), senses (inputs), and some sort ofvoltage regulation (for the micro).

Figure10. Basic Three Phase Motor Control Block Diagram.

This circuit will drive each phase winding bi-directionally, sensezero crossings, discern when to commutate, and then perform thecommutation. Other options include taking input commands andtranslating them into speed or current control information.

To drive the phases bi-directionally, a 3 phase inverter isimplemented using FET pre-drivers and 6 MOSFETS. The inverter is themuscles of the system. For the brains, the ST7MC motor control microwas selected.

This micro has a built-in 3 phase brushless controller cell makingthis job fairly simple to implement. The software passes the cell a fewparameters and the cell does most of the work.

Figure11.The schematic

The Brains
The schematics shown have several things that probably need someexplanation. Other stuff such as the reset circuit or the oscillatorneeds little or no explanation. Each function will be explained as towhy it is there and how it will be used to drive a brushless motor.

The ICP Interface provides a method of flashing (programming) themicro while in the application circuit. The Speed command input circuitjust buffers the input commanded voltage to protect the micro fromadverse or damaging voltages.

This input is designed to interpret a PWM duty cycle so it isconnected to an input capture timer pin. There is an op-amp built intothe micro for the purpose of sensing over-current (these are realizedin pins OAP, OAN, and OAZ). R30 is a current sensing resistor. It isattached to the Inverter low-side MOSFETs .

The inverter is driven by ports MC00 through MC05. These pins areconnected to the three FET pre-driver ICs. The motor BEMF voltages aresensed by the ports MCIA, MCIB, and MCIC.

Also included is an external reference voltage set up on MCCREF.Resistors R17-R19 connect the micro directly to the phase outputs forthe purpose of sensing the zero crossing events. Resistors R10, 11, and13 are used switch the type of BEMF sensing – low-side or high-side ofthe PWM.

The Brawn
The inverter consists of three bootstrap MOSFET pre-drivers, theMOSFETs, and the relevant supporting circuitry. The bootstrap ispreferred to a charge pump because a charge pump can inject EMI into asystem.

The limitation a bootstrap system has is keeping the upper MOSFETgate charged in DC conditions. For a brushless system, there willalways be commutation, and thus, a charging source for the high-sidegates.

The Voltage regulator is a simple 5V regulator with a power on resetfunction. Some extra resistors are placed to provide a battery voltageinput to one of the micro's A to D converter pins.

A 15V zener diode (D6) is needed to protect the L6387 from voltageexceeding 17V. The L6387 supply must not exceed its absolute maximumvoltage of 17V. This added protection may not be necessary if adifferent FET pre-driver is chosen.

The Software
The software is broken down into functional blocks depending on whatstate in the cycle the motor is in. First there is the alignment phase.During alignment, the rotor is forced to a known position. Then, inswitched mode, the rotor is stepped blindly like a stepper motorcausing the rotor to the ramp-up in speed while BEMF is monitored.

Finally, there is the auto-switched mode when there is enough BEMFto reliably detect a zero crossing. The auto-switched mode is brokendown into different speed ranges to accommodate the differing timingneeds for optimum commutation.

Alignment Phase
Since the rotor position is not known, it must be placed in a positionthat can be reliably used as a reference point. The controller alignsthe rotor to a known position by powering two phases. That is, bypulling one phase to supply and one phase to ground. There are twothings to worry about.

The first is motor resistance. There is very little motor resistancein a non-spinning motor. This translates to a huge amount of currentflow and resulting torque, which leads to the second issue.

Too much torque applied all at once can cause the rotor to oscillateas it pulls into position way too quickly. The steady state point oftwo-phases-on is the lowest torque point in the rotational position.

Pulling a rotor into position too quickly will cause it to overshootand oscillate. This is especially the case if there is not a lot offriction in the system. Just turning these switches full-on can causethe rotor to oscillate and draw enormous amounts of current.

Depending on the motor / system being driven, the alignment phase isa gradual stepping up of the stator current. This is done by PWM-ingthe stator current with an increasing duty cycle until the rotor is ina known position.

This gently moves the rotor into position without a lot ofmechanical overshoot / oscillation and limits the current in the motor.If there is a lot of “stick-tion” or static friction in the motorassembly, the algorithm can be modified to provide a high current pulsefor a few milliseconds to break the rotor free.

Once the rotor is freed, the current can then be dropped back downand slowly ramped up to the hold position prior to starting. Thesoftware routine which controls the alignment ramp-up is


This routine is a two-state state machine. The first stateinitializes some RAM variables, determines the maximum PWM duty cyclebased on battery voltage, and places the motor control cell into directaccess mode.

The direct access mode allows setting up the output registers forthe starting position. Once the outputs are set to the desired startposition, the direct access mode is exited.

The second state of the state machine controls the ramp-up and holdstages of the alignment phase. This part of the state machine increasesthe PWM duty cycle until the maximum duty cycle is reached.

The maximum duty cycle is maintained until the hold timer expires,ending the alignment phase. This routine is graphically depicted by theflowchart in Figure 12 below .

Figure12. Start-up algorithm.

The BEMF voltage seen on the unused phase can be used to determinehow long the alignment time should be. Zooming in on the lower voltageof the unused phase with the oscilloscope will show some dampeningoscillations. These oscillations must settle before the micro startsinto the “Stepping Blindly” , or switched, mode.

Figure13. Start-up alignment phase.

The PWM duty cycle and the battery voltage are factors that must beconsidered when determining the alignment time. The battery voltage andPWM duty cycle are inversely related.

That is, with higher battery voltages, the PWM duty cycle should belower and vice versa. The intent is to minimize the oscillations for agiven voltage range. This can be found in the software under thefollowing function:

UInt16Determine_VBAT_PWM( void )

This function scales the PWM duty cycle based on the battery voltagemeasured by the A/D converter. The PWM duty cycles for a given range,and the battery voltage points can be adjusted to minimize thealignment oscillations for a given system.

Switched and Auto-Switched Mode
Once the rotor is put into a “known” position, the controller can nowstart stepping through the phases in a known direction at apredetermined increasing rate continually looking for BEMF. There is agradual increase in commutation speed as the rotor begins to rotatefaster with each step.

At some point, there will be adequate rotation to generate enoughBEMF to sense. At that point, the control algorithm can switch fromblindly stepping and searching for BEMF to auto-switch mode using BEMFzero crossings as a rotor position reference.

The controller software monitors three events which occur duringrotor rotation. These three events are Commutation, Demagnetization,and Zero Crossing. These events always happen in a set sequence.

The Commutation event (C-event) occurs when the controller steps tothe next phase. The act of commutating to the next step will cause avoltage spike in the just-turned-off phase to appear due to the windinginductance.

For a low-side driven phase, the spike is positive – a diode abovethe supply voltage. For a high-side driven phase, the spike is clampedto just below ground. The voltage is limited by the intrinsic diodes ofthe inverter MOSFETS.

The voltage spike will remain as long as the current in that phaseis decaying. The controller waits until this inductive current hasdissipated before monitoring this phase for BEMF.

Otherwise, this inductive spike looks like a zero crossing event hasalready occurred and messes up everything. This wait time is theDemagnetization event (or D-event).

Figure14. Relationship between Commutation, Demagnetization, and ZeroCrossing Events.

The next event in the sequence is the Zero Crossing event (orZ-event). The controller monitors the unused phase to determine whenthe BEMF crosses zero (or near zero) Volts. This event tells thecontroller where the rotor is.

With timing based on rotor speed, the controller determines when toperform the next commutation (or C-event). The controller repeats thesequence of C-event, D-event, Z-event (and back to C-event) to keep therotor spinning.

To read Part 1, go to Dealing with the basics
Next in Part 3: Motor control timingconsiderations

David Swanson is a principalengineer in the Automotive Business Unit of STMicroelectronics. He has a BSEE from North Carolina State University and holds severalautomotive-related patents. Kurt Perski is a Microcontroller FieldApplications Engineer with STMicroelectronics, whose professionalinterests focus on embedded software design.

Leave a Reply

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