You are on page 1of 41

How Brushless Motors Work (BLDC Motors)

This motor could be characterized as the modern kind of DC motor. The letters BLDC means Brush-Less Direct Current. So, these motors have no brushes. If you do not know what the brushes are, then you should first read the article about How Brushed DC motors are made and how they operate. It is better to start learning from the simplest motors.

How are the Brushless DC (BDLC) motors made?

PC fans use BLDCs for their silent operation and reliability

The controller circuit for PC fans is so small, it can fir on the back side of the motor!

The brushless motor, unlike the DC brushed motor, has the permanent magnets glued on the rotor. It has usually 4 magnets around the perimeter. The stator of the motor is composed by the electromagnets, usually 4 of them, placed in a cross pattern with 90o angle between them. The major advantage of the brushless motors is that, due to the fact that the rotor carries only the permanent magnets, it needs of NO power at all. No connection needs to be done with the rotor, thus, no brush-commutator pair needs to be made! This is how the brushless motors took their name from. This feature gives the brushless motor great increament in reliability, as the brushes wear off very fast. Moreover, brushless motors are more silent and more efficient in terms of power consumption. A brushless motor has yet another major difference from the brushed motors. In the theory of operation of the brushed DC motors with permanent magnets, i explain how the commutator is made and how the coils changes polarity during rotation. But brushless motors have no commutator nor brushes. Thus, there is actually no way of knowing where each time the rotor is. Well actually they do know. There are several ways to find out where the rotor is. Sometimes they use rotary encoders along with their controllers and they know exactly the angle that the rotor is. Others use pairs of Hall sensors while most of them use just one Hall sensor. You can learn more information about the Hall sensor in this page. The Hall sensor is placed in an appropriate position. It can sense if in front of it is the North or the South pole. The Hall sensor will then transmit this signal to the controller of the motor. The controller will then switch on or off the appropriate coils needed in order to provide the torque. And that's the way it goes... As you understand, this is a major drawback of brushless motors. They need of a controller circuitry to operate. Yet when reliability is required, this motor is the most suitable. The following video demonstrates exactly how a typical (and very popular type) of a brushless motor is made:

How the brushless motors work?

The trick of operation in BLDC motors is the Hall sensor that is attached to the stator. It faces the magnets perpendicularly and can distinguish if the North or South pole is in front of it. The following image shows this Hall senor. The photo is taken from a PC fan (yes, PC fans do have BLDCs!):

If you want to learn how the PC fans operate, follow this link. To better understand the operation of the Hall sensor in respect to the rotor position, i will show you an animation with only 2 magnetic poles and 2 coils. The magnetic poles are both South poles:

The Hall sensor is this little component under the right electromagnet. When it senses the South pole, it keeps the coils turned off. When the sensor senses no magnetic field (or could be also the South pole), then it turns on the coils. The coils have both the same magnetic polarity which is North. So they pull the opposite pole and torque is then created. If you put a probe to the Hall sensor and watch the signal, then you will discover that during a full rotation of the rotor, the Hall sensor is two times HIGH and two times LOW. The waveform on oscilloscope would be like this one:

Yet another great advantage for the brushless motors. This very signal that is used to control the coils, can be used as is for measuring the speed of the motor! It can also be used to see if the motor is functional or not! Actually, this signal is exactly the one that comes out from the third wire from the PC fans that have 3 (or 4 wires)! These fans do not have any extra circuitry to measure the speed of the motor. They use the signal from the Hall sensor. Each revolution will generate 2 pulses. With a simple frequency measuring circuitry, someone can measure precisely the rpm of the motor.

A real brushless motor has 4 coils

I explained above the operation principle of a brushless motor with 2 coils and 2 permanent magnets. Yet, in real life, BLDCs have usually 4 coils and 4 magnets. Also, the Hall sensor is able not only to see if a magnetic field is in front of it, but also to distinguish if this is the North or the South pole. This is how a real BLDC motor looks like:

Around the perimeter of the rotor, there are 4 magnets in N-S-N-S patten. Also, there are 4 coils. The windings of the coils are not all of the same direction. 2 neighbor coils can never have the same magnetic polarity. The coils are connected in pairs, either each one with it's opposite coils, or there in two pairs or neighbor coils like shown on the above drawing.

The simplest operation cycle is, according to the pole that is in front of the Hall sensor, the controller will turn on or off the appropriate coil pair. The following animation demonstrates this cycle of operation:

And when the Hall sensor is between the two poles?

I had this question myself. What will happen if the rotor is stopped in a position where the Hall sensor is exactly between two different poles? Look for example the following drawing:

It may happen... Now the Hall sensor cannot sense exactly which pole is in front of it. Well, this is actually not a big deal... Suppose that the sensor senses the wrong pole and gives power to the wrong coils. What will happen? For a fraction of a millisecond the motor will try to rotate the wrong way. But a few degrees of rotation will bring the correct pole in front of the Hall sensor and it will immediately change the coils. Thus, the motor will then turn on the correct rotation. But what if the motor controls a critical load and this backwards rotation, even if it is under 5 o must NOT occur? There is a solution for this, but it requires the use of another Hall sensor. The second sensor will be placed with 45o difference from the first one:

Now, even if the first Hall sensor cannot get a proper reading, the second Hall sensor can clearly distinguish the magnetic pole. The controller will accept as "correct reading" the one that comes from the sensor with the most intense signal.

The Sensorless BLDCs

Yet another variation of the brushless motors. Using a Hall sensor will result in an increase of the overall price of the motor. Moreover, there are situations that a sensor cannot be used, as for example in submersible pumps, or in applications where the wiring must be kept to minimum. In such applications, the sensorless BLDC can be used instead. The operation of such motor is based on the BEMF effect. The BEMF (Back Electro-Magnetic Force) is inducted by the movement of a permanent magnet in front of a stator coil. There are two problems that must be solved for the proper operation of the motor. First of all, the rotation direction. As no sensor is used, the controller cannot know where the rotor is stopped at any time. Thus, the rotation direction that the motor will start is -at least for the first degrees of rotation- coin toss. The other problem is the zero detection. The controller does not know when to change the polarity of the coils, as there is no sensor to sense when the permanent magnet pole crosses a specific point. There are special designed controller chips to solve these problems. The chips will use the characteristics of the BEMF and the voltage generated on the coils from the BEMF effect. For example, the current produced on a coil due to BEMF will change its polarity, if the rotation of the permanent magnet is changed. Also, the amplitude of the produced waveform is proportional to the speed of the rotors, and the phase of the waveform depends on the position of the permanent magnet in respect to the coil. Yet, this is not the proper article to discuss about sensorless BLDCs in details.

How PC Fans Work

The vast majority of PCs has at least one of them. They carry the heavy load to keep your PC cool and functional, either by providing fresh air in the box, or by forcing the hot air to leave a hot surface by pushing cool air. Read the following article to learn how the BLDC PC Fans operates...

What is inside a PC fan?

There are may types of PC fans that are assembled in different ways. In this article, i will explain the basic and most common fan type. The fan that i study is a 3-wire 4 coils 80mm fan rotating at 2200 rpm. Then i will explain some other common fans.

First of all i had to disassemble the fan. I am not the right person to disassemble something for the first time due to lack of patience. During the disassembling, i broke some parts of the housing and a fin. Still i did not find any way of easy disassembling. I suppose that the fan i chosen (and maybe many others) are NOT to be disassembled and re-assembled. Anyway, let's see what's inside a PC fan:

A victim in the name of science

Removing the fins from the housing, the controller is revealed

The rotor, the stator and the controller

It is more than obvious that the PC fan is not rotated from a simple DC motor. It has the permanent magnets fixed on the rotor, the stator carries the coils, there are no brushes, it has a controller... the sun is shining... it is of course a brushless motor. I have written a detailed theory about brushless motors. You can find it in the "Theory of operation of brushless motors" page.

Some different PC fan types

As long as the motor is concerned, i suppose that all PC fans use brushless motors. There are several reasons that a brushless motor should be used, among them is the reliability, the power efficiency and the rpm feedback. So the motor type would not be the proper way to categorize PC fans. Instead, i will categorize them with the most obvious characteristic: their connector. There are actually 3 different types of PC fans. Those with a 2-pin connector, those with a 3-pin connector and those with a 4-pin connector. Let's see them one by one:

2-wire PC Fans

A 2-wire PC fan

These fans have usually a male-female molex 4-pins connector from where their power supply is drawn.

These are the oldest and most simple PC fans. Only two wires comes out out of the fan controller, the positive and the negative. Giving power to the fan, it will rotate at full speed. The internal diagram of a typical two-wire fan is as follows:

The connector of a 2-wire fan has a red and a black cable. The red cable goes to the positive of the power supply and the black to the negative. Usually, for more flexibility, they have a male-female 4-wire molex power connector. In one end of the connector the fan is connected in parallel with the 12V (YELLOW - BLACK). Therefore, the fan is powered normally and the cable of the PSU can be used to power another device.

3-wire PC Fans

A 3-wire PC fan

Yet another 3-wire PC fan with different wire colors

A very common type of PC fan. These fans introduced the "tacho" for the first time. The first two wires are the power supply of the fan. The third wire, comes directly from the output of the Hall sensor. This output generates 2 pulses per one revolution of a fan. The fan is then connected to the motherboard. From the third wire, the motherboard can "read" the tacho of the fan and see if the fan is running and with how many RPMs! It is a great innovation! If the motherboard sees no pulses or very low rpm, then the characteristic buzzer sounds to inform the operator that something is not ok. The internal diagram of a typical three-wire fan is as follows:

It seems that for once more, the manufacturers did not have the same wire provider, or their wire providers did not have the same colored-plastic provider... Two fans with 3-wire connectors may not have the same wire colors. Thus, instead of using the colors to distinguish the function, better go with the connector that is standard. No matter what color the cable has, it will be plugged in the same motherboard connector! So,as you look from the key-side of the connector, number 1 is the most left pin :

1: Negative power supply 2: Positive power supply 3: Tacho

BLACK: Negative RED: Positive YELLOW: Tacho

BLACK: Negative YELLOW: Positive GREEN: Tacho

4-wire PC Fan
This is the most modern type of PC fan. This fan is designed to be controlled with a PWM signal and increase or decrease its RPM. All fans actually can be controlled with PWM, but this particular type can also provide tacho feedback simultaneously, something that the 3-wire fan cannot do -under normal circumstances. The 3-wire fan powers the Hall sensor and the controller from the same line that the coils are powered. Thus, if someone tries to send PWM pulses to the coils of a 3-wire fan, the same pulses will arrive at the controller. The

controller will then malfunction, because it needs constant current to operate. As a result, the third wire will not provide correct readings. Unlike the 3-wire fans, the 4-wire fans have a slight change that eliminates this problem. The controller and the Hall sensor are always powered with constant current. A transistor (fet) is placed before the coils. The base of the transistor is actually the fourth wire. So, the PWM pulses are driving the transistor. The coils receive these pulses through the transistor, but the controller along with the Hall sensor are not affected at all. This change can be seen in the internal diagram of a typical 4-wire fan:

Usually, the diagram is more complicated than this. This is to give you an idea about the principle of operation of the PC PWM Fans (as used to be called). The controller actually checks the PWM input pulses and sends pulses to the transistor accordingly. If the PWM Duty cycle is bellow a threshold value, then the fan either shuts down, or it remains in a stable 'LOW" rpm. There are also fans that even with 0% duty cycle, they keep on running at this 'LOW' speed. This is usually done in critical applications that even if the external controller fails to operate, the internal fan controller will bypass the signal and will keep the fan running. As for the pinout... Just do not trust the colors. As you look from the key-side of the connector, number 1 is the most left:

1: Negative power supply 2: Positive power supply 3: Tacho 4: PWM control

BLACK: Negative YELLOW: Positive GREEN: Tacho BLUE: PWM Control

BLACK: Negative RED: Positive YELLOW: Tacho BLUE: PWM Control

Can I connect a 3-wire fan to a 4-wire connector?

Yes you can. If you notice the pinout of the fans, the 3 first pins are the same for the 3 and 4 wire fans. Also, the keys are the same for both connectors. The 4-wire connector has smaller back-key to accept the smaller 3-wire fan connector keys. The fan will always run at full speed (as the control pin will not be used), but the rpm feedback (tacho) of the fan will operate normally and the motherboard will read the rpm normally.

Can I connect a 4-wire fan to a 3-wire connector?

A 4-wire fan connected to a 3-wire connector. No problem!

Yes (and no). Although the connector is larger, the keys of the 4-wire fan have the same distance as the 3-wire connector. The fan will operate at full speed all the time, as the 4 th wire from the PWM control will be on air. The motherboard will normally read the rpm feedback from the fan tacho. Now, i am not quite sure about the internal connectivity of the 4-wire fans. No matter how may fans i tested, and no matter how many sites i visited, i found no clue that this configuration will fail. This means that the PWM control line must have an internal pull-up resistor, so that when the pin is unconnected, the control FET will be kept always ON. There could be a manufacturer though that maybe felt like making something different, and either he removed this resistor or replaced the FET with different channel than normal. I do not know why anyone would do this! But i have not find anywhere a norm that declares if the fan MUST operate or not with the 4 th wire unconnected. Anyway, what you only have to do is to test it. Either plug it in and see what happens, or give power yourself to the first 2 pins (negative and positive). If it rotates, then no problem!

The Stellaris PWM module provides a great deal of flexibility. It can generate simple PWM signals, such as those required by a simple charge pump. It can also generate paired PWM signals with dead-band delays, such as those required by a half-H bridge driver. The following example shows how to initialize the PWM Generator 0 with a 25-KHz frequency, and with a 25% duty cycle on the PWM0 pin and a 75% duty cycle on the PWM1 pin. This example assumes the system clock is 20 MHz. 1. Enable the PWM clock by writing a value of 0x0010.0000 to the RCGC0 register in the System Control module. 2. Enable the clock to the appropriate GPIO module via the RCGC2 register in the System Control module. 3. In the GPIO module, enable the appropriate pins for their alternate function using the GPIOAFSEL register. 4. Configure the Run-Mode Clock Configuration (RCC) register in the System Control module to use the PWM divide (USEPWMDIV) and set the divider (PWMDIV) to divide by 2 (000). 5. Configure the PWM generator for countdown mode with immediate updates to the parameters. Write the PWM0CTL register with a value of 0x0000.0000. Write the PWM0GENA register with a value of 0x0000.008C. Write the PWM0GENB register with a value of 0x0000.080C. 6. Set the period. For a 25-KHz frequency, the period = 1/25,000, or 40 microseconds. The PWM clock source is 10 MHz; the system clock divided by 2. This translates to 400 clock ticks per period. Use this value to set the PWM0LOAD register. In Count-Down mode, set the Load field in the PWM0LOAD register to the requested period minus one. Write the PWM0LOAD register with a value of 0x0000.018F. 7. Set the pulse width of the PWM0 pin for a 25% duty cycle. Write the PWM0CMPA register with a value of 0x0000.012B. 8. Set the pulse width of the PWM1 pin for a 75% duty cycle. Write the PWM0CMPB register with a value of 0x0000.0063. 9. Start the timers in PWM generator 0. Write the PWM0CTL register with a value of 0x0000.0001. 10. Enable PWM outputs. Write the PWMENABLE register with a value of 0x0000.0003.

The PID controller software running on the LM3S6432 requires the following

An input, here a potentiometer, to set the absolute speed at which the motor should run o An interrupt to measure the motor speed o A periodic interrupt to works out the difference between the actual measured speed and the required speed o Some way of converting the speed error into a variable duty ratio PWM to give a controllable average voltage at the motor. If the motor runs at 600rpm when the PWM drive to the motor is at a 50% duty ratio, increasing this to 60% will make the motor try to run faster. Reducing the duty ratio to 40% will slow the motor down. In a very simple "open loop" speed controller, the program, the potentiometer on analog channel 0 is read to yield a value between 0-1023 (10-bits). This value is then fed into the PWM unit to allow the motor speed to be varied. In the real world, this type of controller is not very useful. While it allows the motor speed to be set, it does not allow for changes in load and a basic flaw is that the absolute speed is not known unless an external

Closing The Loop The closed-loop controller is a very common means of keeping motor speed at the required "setpoint" under varying load conditions. It is also able to keep the speed at the setpoint value where for example, the setpoint is ramping up or down at a defined rate. The essential addition to the previous system is a means for the current speed to be measured. In the example, a three bladed vane was attached to the motor shaft. An infra-red LED was obscured from the view of a photodiode by the vane blades so that a series of pulses with a frequency proportional to motor speed is now available. In this "closed loop" speed controller, a signal proportional to the motor speed is fed back into the input where it is subtracted from the setpoint to produce an error signal. This error signal is then used to work out what the magnitude of controller output should be to make the motor run at the required setpoint speed. For example, if the error speed is positive, the motor is running too fast so that the controller output should be reduced and vice-versa. The clever part is how the Output drive is worked out....

At firssight it might be imagined thatsomething simple like "if the errspeed is negative, multiply it by some scale factor (usually known as "gain") and set the output drive to this lethe voltage applied to the motor is proportional to the error speed. In practice, this approach is only partially successfor the following reason: if the motor is at the setpoint speed under no load there is no error speed so the motor freeruns. If a load is applied, the motor slows down so that a positive error speed is produced. The output increases by a proportional amount to try and restore the speed. However, as the motor speed recovers, the error reduces and so therefore does the drive level. The result is that the motor speed will stabilise at some speed below the setpoint at which the load is balanced by the error speed x the gain. If the gain is very high so that even the smallest change in motor speed causes a significant change in drive level, the motor speed may

oscillate or "hunt" slightly . This basic strategy is known as "proportional control" and on its own has only limited use as it can never force the motor to The next improvement is to introduce a correction to the output which will keep adding or subtracting a small amount to the output until the motor reaches the setpoint, at which point no further changes are made. In fact a similar effect can be had by keeping a running total of the error speeds observed for instance, every 25ms and multiplying this by another gain before adding the result the proportional correction found above this term is based on what is effectively the integral of the error speed. Thus far we have a scheme where there are two mechanisms trying to correct the motor speed which constitutes a PI (proportional-integral) controller. The proportional term is a fast-acting correction which will make a change in the output as quickly as the error arises. The integral takes a finite time to act but has the ability to remove all the steady-state speed error. A further refinement uses the rate of change of error speed to apply an additional correction to the output drive. This means that a rapid motor deceleration would be counteracted by an increase in drive level for as long as the fall in speed continues. This final component is the "derivative" term and it is a useful means of increasing the short-term stability of the motor speed. A controller incorporating all three strategies is the well-known Proportional-Integral-Derivative, or "PID" controller. For best performance, the proportional and integral gains need careful tuning. For example, too much integral gain and the control will tend to over-correct for any speed error resulting in oscillation about the setpoint speed. Several well-known mathematical techniques are available to calculate optimal gain values, given knowledge of the combined characteristics of the motor and load, i.e. the "transfer function". However, some simple rules of thumb and a little experimentation can yield satisfactory results in practical applications. What The Gains Do Integral Gain: Ensures that under steady state conditions that the motor speed (almost) exactly matches the setpoint speed. A low gain can make the controller slow to push the speed to the setpoint but excessive gain can cause hunting around the setpoint speed. In less extreme cases, it can cause overshoot whereby the speed passes through the setpoint and then approaches the required speed from the opposite direction. Unfortunately, sufficient gain to quickly achieve the setpoint speed can cause overshoot and even oscillation but the other terms can be used to damp this out. Proportional Gain: Gives fast response to sudden load changes and can reduce instability caused by high integral gain. This gain is typically many times higher than the integral gain so that relatively small deviations in speed are corrected while the integral gain slowly moves the speed to the sepoint. Like integral gain, when set too high, proportional gain can cause a "hard" oscillation of a few Hertz in motor speed. Derivative Gain: Can be used to give a very fast response to sudden changes in motor speed. Within simple PID controllers it can be difficult to generate a derivative term in the output that has any significant effect on motor speed. It can be deployed to reduce the rapid speed oscillation caused by high proportional gain. However, in many controllers, it is not used. Basic Considerations The main PID controller routine was designed to be fairly general purpose and hence modular. Whilst here it is used to control a DC motor, it could be re-deployed to other situations where some parameter has to be controlled to a set value under varying conditions. The actual control software is located in a single function and its major inputs and output are held in a structure. Although it was designed originally for a specific job it is really only intended as an example of the basic techniques involved and to allow those with no control system knowledge to experiment with a simple PID system.

The routines that gather the inputs and process the output are kept in separate functions in another module. The Keil C166 v4.01 compiler was used but it should not prove too difficult to port it to the rather less common Tasking compiler, or indeed the 8-bit C505 or C515. For simplicity and to allow the easy modification of the important PID gain parameters, the C167's 10-bit analog to digital converter was used to derive 10-bit resolution inputs from simple trimmer potentiometers. The PWM used to drive the motor was chosen as 10-bits so that motor speed can be defined to approximately 0.1%, sufficient for most practical application. At this resolution, the C167 CAPCOM unit generates a 2.4kHz carrier which does produce some audiable motor winding ringing. The C167's high resolution dedicated PWM unit could have been used to increase this to a supersonic 19.5kHz but to allow easy porting to other C167 variants this route was not taken. Fortunately the use of a 10 bit resolution on the inputs and output makes some of the arithmetic easier! The C167 IO pins are allocated as per: P2.0 CAPCOM channel 0 - optical chopper encoder input P2.1 CAPCOM channel 2 - PWM drive output P5.0 analog channel 0 - setpoint input P5.1 analog channel 1 - derivative gain input P5.2 analog channel 1 - proportional gain input P5.3 analog channel 1 - integral gain input Designing The PID Controller Routine The PID control problem has to be converted from a theoretical continuous process into a real "discrete" system running on a microcontroller. What this means in practice is that the measuring of the setpoint and motor speed and the calculation of the output is only performed a regular interval. In the context of a microcontroller, this might correspond to some code run from a timer interrupt. The PID controller can thus be expressed as: Output = Proportional Gain * (error_speed) + Integral_gain * S (previous_error_speeds) + Derivative_gain * (error_speed - last_error_speed) This is quite easy to implement as a C interrupt function. The timer 3 interrupt is easy to configure to produce a regular interrupt event, with timer 2 acting as a reload register. The period of the interrupt determines the effective sampling rate of the PID controller. The service routine introduces the small refinement to the basic control strategy in the form of a "deadband". This stops the controller trying to constantly correct very small speed errors which in fact can trigger instability. /*** Work out current error speed ***/ this_error = PID.setpoint - PID.feedback_input ; /*** Check for error speed being less than deadband width ***/ temp = this_error ; // Is error speed negative if(N) { temp = -temp ; // Get absolute value } /* Is error speed within deadband? */ if(temp <= Deadband_Width) { this_error = 0 ; // Within deadband so zero error speed } A trick is used to quickly find the modulus of the potentially signed error speed which involves checking the C167's own N (negative) flag directly and if set, negate the result. For strict 'C' portability, this sort of technique is a bit suspect but could easily be replaced by the proper ISO-C abs() function. The proportional term is very easily calculated but the complication with this and in fact all terms, is catering for overflows. The PID controller was written to be fairly general purpose and so was based on signed 16 bit arithmetic. Here, the maximum value is 32767 (0x7FFF) and the minimum -32768 (0x8000). Unfortunately there is no quick way of checking for the term exceeding this condition so a long compare had to be made to see whether the output value had gone out of limits. Under these circumstances, the value is simply set equal to the appropriate positive or negative limit. This limiting of a parameter to a maximum value is known as "saturation". fineon_C167_Family.pdf

Speed Controllers
V3.03 5-Oct-2005

1. Introduction
The purpose of a motor speed controller is to take a signal representing the demanded speed, and to drive a motor at that speed. The controller may or may not actually measure the speed of the motor. If it does, it is called a Feedback Speed Controller or Closed Loop Speed Controller, if not it is called an Open Loop Speed Controller. Feedback speed control is better, but more complicated, and may not be required for a simple robot design. Motors come in a variety of forms, and the speed controller's motor drive output will be different dependent on these forms. The speed controller presented here is designed to drive a simple cheap starter motor from a car, which can be purchased from any scrap yard. These motors are generally series wound, which means to reverse them, they must be altered slightly, (see the section on motors). Below is a simple block diagram of the speed controller. We'll go through the important parts block by block in detail.

2. Theory of DC motor speed control

The speed of a DC motor is directly proportional to the supply voltage, so if we reduce the supply voltage from 12 Volts to 6 Volts, the motor will run at half the speed. How can this be achieved when the battery is fixed at 12 Volts? The speed controller works by varying the average voltage sent to the motor. It could do this by simply adjusting the voltage sent to the motor, but this is quite inefficient to do. A better way is to switch the motor's supply on and off very quickly. If the switching is fast enough, the motor doesn't notice it, it only notices the average effect. When you watch a film in the cinema, or the television, what you are actually seeing is a series of fixed pictures, which change rapidly enough that your eyes just see the average effect - movement. Your brain fills in the gaps to give an average effect. Now imagine a light bulb with a switch. When you close the switch, the bulb goes on and is at full brightness, say 100 Watts. When you open the switch it goes off (0 Watts). Now if you close the switch for a fraction of a second, then open it for the same amount of time, the filament won't have time to cool down and heat up, and you will just get an average glow of 50 Watts. This is how lamp dimmers work, and the same principle is used by speed controllers to drive a motor. When the switch is closed, the motor sees 12 Volts, and when it is open it sees 0 Volts. If the switch is open for the same amount of time as it is closed, the motor will see an average of 6 Volts, and will run more slowly accordingly. As the amount of time that the voltage is on increases compared with the amount of time that it is off, the average speed of the motor increases. This on-off switching is performed by power MOSFETs. A MOSFET (Metal-OxideSemiconductor Field Effect Transistor) is a device that can turn very large currents on and off under the control of a low signal level voltage. For more detailed information, see the dedicated chapter on MOSFETs) The time that it takes a motor to speed up and slow down under switching conditions is dependant on the inertia of the rotor (basically how heavy it is), and how much friction and load torque there is. The graph below shows the speed of a motor that is being turned on and off fairly slowly:

You can see that the average speed is around 150, although it varies quite a bit. If the supply voltage is switched fast enough, it wont have time to change speed much, and the speed will be quite steady. This is the principle of switch mode speed control. Thus the speed is set by PWM Pulse Width Modulation.

2.1. Inductors
Before we go on to discuss the circuits, we must first learn something about the action of inductive loads, and inductors. Inductors do not allow the current flowing through them to change instantly (in the same way capacitors do not allow the voltage across them to change instantly). The voltage dropped across an inductor carrying a current i is given by the equation

where di/dt is the rate of change of the current. If the current is suddenly changed by opening a switch, or turning a transistor off, the inductor will generate a very high voltage across it. For example, turning off 100 Amps in 1 microsecond through a 100 microHenry inductor generates 10kV!

2.2. PWM frequency

The frequency of the resulting PWM signal is dependant on the frequency of the ramp waveform. What frequency do we want? This is not a simple question. Some pros and cons are:

Frequencies between 20Hz and 18kHz may produce audible screaming from the speed controller and motors - this may be an added attraction for your robot!

RF interference emitted by the circuit will be worse the higher the switching frequency is. Each switching on and off of the speed controller MOSFETs results in a little power loss. Therefore the greater the time spent switching compared with the static on and off times, the greater will be the resulting 'switching loss' in the MOSFETs. The higher the switching frequency, the more stable is the current waveform in the motors. This waveform will be a spiky switching waveform at low frequencies, but at high frequencies the inductance of the motor will smooth this out to an average DC current level proportional to the PWM demand. This spikyness will cause greater power loss in the resistances of the wires, MOSFETs, and motor windings than a steady DC current waveform.

This third point can be seen from the following two graphs. One shows the worst case onoff current waveform, the other the best case steady DC current waveform:

Both waveforms have the same average current. However, when we work out the power dissipation in the stray resistances in our motor and speed controller, for the DC case:

and for the switching case, the average power is

So in the switching waveform, twice as much power is lost in the stray resistances. In practice the current waveform will not be square wave like this, but it always remains true that there will be more power loss in a non-DC waveform.

Choosing a frequency based on motor characteristics One way to choose a suitable frequency is to say, for example, that we want the current waveform to be stable to within p percent. Then we can work out mathematically the minimum frequency to attain this goal. This section is a bit mathematical so you may wish to miss it out and just use the final equation. The following shows the equivalent circuit of the motor, and the current waveform as the PWM signal switches on and off. This shows the worst case, at 50:50 PWM ratio, and the current rise is shown for a stationary or stalled motor, which is also worst case.

T is the switching period, which is the reciprocal of the switching frequency. Just taking the falling edge of the current waveform, this is given by the equation

is the time constant of the circuit, which is L / R. So the current at time t = T/2 (i1) must be no less than P% lower than at t = 0 (i0). This means there is a limiting condition:


Lets try some values in this to see what frequencies we get. A Ford Fiesta starter motor has the following approximate parameters: R = 0.04 L = 70H We must also include in the resistance the on-resistance of the MOSFETs being used, say 2 x 10m, giving a total resistance of R = 0.06 . Percentage 1 5 10 20 50 A graph can be drawn for this particular motor: frequency 42 kHz 8.2 kHz 4 kHz 1900 Hz 610 Hz

Looking at the above graph, a reasonably low ripple can be achieved with a switching frequency of as little as 5kHz. Unfortunately, motor manufacturers rarely publish values of coil inductance in their datasheets, so the only way to find out is to measure it. This requires sensitive LCR bridge test equipment which is rather expensive to buy. However, from the 4QD site, they quote the Lynch motor with an inductance of 39H as being one of the lowest.

3. Speed control circuits

We will start off with a very simple circuit (see the figure below). The inductance of the field windings and the armature windings have been lumped together and called La. The resistance of the windings and brushes is not important to this discussion, and so has not been drawn. Q1 is the MOSFET. When Q1 is on, current flows through the field and armature windings, and the motor rotates. When Q1 is turned off , the current through an inductor cannot immediately turn off, and so the inductor voltage drives a diminishing current in the same direction, which will now flow through the armature, and back through D1 as shown by the red arrow in the figure below. If D1 wasnt in place, a very large voltage would build up across Q1 and blow it up.

It may help to introduce some terminology here. The Motor Driver Terminology page defines some terms.

4. Regeneration
In this circuit, energy can flow only one way, from the battery to the motor. When the speed demand of the motor drops suddenly, the momentum of the robot will drive the motor forwards, and the motor will act as a generator. In the circuit above, this power cannot go anywhere. Although this isnt a problem, it is desirable that this power be put back into the battery. This is called regenerative braking and needs some extra components. The following circuit allows regenerative braking:

In this circuit, Q1 and D1 perform the same function as in the previous circuit. Q2 is turned on in antiphase to Q1. This means that when Q1 is on, Q2 is off, and when Q1 is off, Q2 is on. In this circuit, when the robot is slowing down, Q1 is off and the motor is acting as a generator. The current can flow backwards (because the motor is generating) through Q2 which is turned on. When Q2 turns off, this current is maintained by the inductance, and current will flow up through D2 and back into the battery. A graph of motor current as the motor is slowing down is shown below:

If you are driving starter motors, or any type of series-field motor, regeneration is harder to make work. For a motor to work as a generator, it must have a magnetic field, generated by the field coil. In a series motor this is in series with the armature coil, so to generate a voltage, a suitable current must be flowing. The current that will flow depends on the load, which during regeneration is the battery, so it depends on how much the battery is charged up - how much current the battery will draw into it. Alternatively, a dummy resistive load can be switched in at the approriate time, but this is all a little too complicated for a robot!

5. Reversing
To reverse a DC motor, the supply voltage to the armature must be reversed, or the magnetic field must be reversed. In a series motor, the magnetic field is supplied from the supply voltage, so when that is reversed, so is the field, therefore the motor would continue in the same direction. We must switch either the field windings supply, or the armature windings supply, but not both. One method is to switch the field coil using relays:

When the relays are in the position shown, current will flow vertically upwards through the field coil. To reverse the motor the relays are switched over. Then the current will be flowing vertically downwards through the field coil, and the motor will go in reverse. However, when the relays open to reverse the direction, the inductance of the motor generates a very high voltage which will spark across the relay contact, damaging the relay. Relays which can take very high currents are also quite expensive. Therefore this is not a very good solution. A better solution is to use what is termed a full-bridge circuit around either the field winding, or the armature winding. We will put it around the armature winding and leave the field winding in series.

6. The full bridge circuit

A full bridge circuit is shown in the diagram below. Each side of the motor can be connected either to battery positive, or to battery negative. Note that only one MOSFET on each side of the motor must be turned on at any one time otherwise they will short out the battery and burn out!

To make the motor go forwards, Q4 is turned on, and Q1 has the PWM signal applied to it. The current path is shown in the diagram below in red. Note that there is also a diodee connected in reverse across the field winding. This is to take the current in the field winding when all four MOSFETs in the bridge are turned off.

Q4 is kept on so when the PWM signal is off, current can continue to flow around the bottom loop through Q3's instrinsic diode:

To make the motor go backwards, Q3 is turned on, and Q2 has the PWM signal applied to it:

Q3 is kept on so when the PWM signal is off, current can continue to flow around the bottom loop through Q4's intrinsic diode:

For regeneration, when the motor is going backwards for example, the motor (which is now acting as a generator) is forcing current right through its armature, through Q2's diode, through the battery (thereby charging it up) and back through Q3's diode:

6.1. Reducing the heat in the MOSFETs

When the MOSFETs in the diagrams above are on and current is flowing through them in a top-to-bottom direction, they have a very low resistance and are dissipating hardly any heat at all. However, when the current is flowing bottom-to-top through the intrinsic diodes, there is a fixed voltage across them - the voltage drop of a diode, about 0.8 volts. This causes quite a large power dissipation (volts x amps). A feature of MOSFETs is that they will conduct current from source to drain as well as drain to source, as long as the Vgs is greater than 10-12 volts. Therefore, if the MOSFETs that are carrying reversed current through their diodes are turned on, then they will dissipate a lot less heat. The heat will be dissipated in the wires and the motor itself instead. This extra switching is performed by the TD340 full bridge driver.

7. Generating PWM signals

The PWM signals can be generated in a number of ways. It is possible that your radio receiver already picks up a PWM waveform from the handest transmitter. If there is a microcontroller on the robot, this may be able to generate the waveform, although if you have more than a couple of motors, this may be too much of a load on the microcontrollers resources. Several methods are described below.

7.1. Analogue electronics

The PWM signal is generated by comparing a triangular wave signal with a DC signal. The DC signal can range between the minimum and maximum voltagesof the triangle wave.

When the triangle waveform voltage is greater than the DC level, the output of the opamp swings high, and when it is lower, the output swings low. From the graph it can be seen that if the DC level went higher, the pulses would get even thinner. An example circuit for this is shown below. This uses a counter and weighted resistor ladder to generate the triangle wave (in fact it will generate a sawtooth, but you'll still get a PWM signal at the end of it). The actual resistor values which are unavailable (40k, 80k) can be made up with 20k resistors, or close approximations can be used, which may distort the sawtooth somewhat, but this shouldn't matter too much.

The 74HC14 is a Schmitt input inverter, which is connected to act as a simple oscillator. The frequency of oscillation is roughly f = 1/(2.PI.R.C)

but it doesnt matter a great deal within a few tens of percent. This square wave generated feeds the 74HC163 binary 4-bit counter. All the preset and clear inputs of this are disabled, so the outputs, QA to QD just roll around the binary sequence 0000 to 1111 and rollover to 0000 again. These outputs, which swing from 0v to +5v are fed into a binary weighted summer amplifier, the leftmost LM324 opamp section with the 80k, 40k, 20k and 10k resistors. The output voltage of this amplifier depends on the counter count value and is shown in the table below as Amp1 output. The opamp following this just multiplies the voltage by - , to make the voltage positive, and bring it back within logic voltage levels, see the Amp2 output column in the table.

Counter value

Binary value

Amp1 output (Volts)

Amp2 output (Volts)

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

0 -0.625 -1.25 -1.875 -2.5 -3.125 -3.75 -4.375 -5 -5.625 -6.25 -6.875 -7.5 -8.125 -8.75 -9.375

0 0.3125 0.625 0.9375 1.25 1.5625 1.875 2.1875 2.5 2.8125 3.125 3.4375 3.75 4.0625 4.375 4.6875

The final, rightmost, opamp compares the voltage with the demand voltage input, which ranges from 0v to 4.6875v, where 0v represents 0% PWM ratio and 4.6875v represents 100% PWM ratio. This demand voltage may range from 12v to +12v but only the 0 to 4.6875 range will adjust the PWM ratio.

7.2. PWM generator chips

There are ICs available which convert a DC level into a PWM output. Many of these are designed for use in switch mode power supplies. Examples that could be used are: Manufacturer IC Normal use SGS Thomson SG1524,SG1525... SMPS



Signal generation

Alternatively, a MOSFET driver which includes a PWM generator can be used. I know of only one which is not yet released! The SGS Thomson TD340.

7.3. Digital method

The digital method involves incrementing a counter, and comparing the counter value with a pre-loaded register value. It is basically a digital version of the analogue method above:

The register must be loaded with the required PWM level by a microcontroller. It may be replaced by a simple ADC if the level must be controlled by an analogue signal (as it would from a radio control servo). This method is only really practical if a microcontroller is being used in your robot, which can preload the register easily.

7.4. Onboard microcontroller

If you have chosen to use an onboard microcontroller, then as part of your selection process, include whether it has PWM outputs. If it has this can greatly simplify the process of generating signals. The Hitachi H8S series has up to 16 PWM outputs available, but many other types have two or three.

8. Interfacing to the high power electronics

There are two sides to the electronics: the low-power side, and the high-power side. The low power electronics includes any onboard microcontroller, the radio control receiver, and PWM generators. The high-power side includes the MOSFET drivers, the MOSFETs themeselves, and any solenoid or pump drivers that you may have. Basically anything that is switching large currents. The low-power electronic devices may be quite sensitive to noise spikes on the power rails, and may malfunction or even be destroyed. It is a good idea to isolate the lowpower electronics from the high-power electronics using what is known as opto-isolators

or opto-couplers, two names for the same thing! For more information about these, there is a chapter on it here

9. Interfacing to the radio control receiver

Many roboteers will be using commercial radio control sets. The receivers of these generally connect to servos, which respond to the radio signal (which may also be PWM):

You may be able to tap into the PWM signal which comes out of the radio receiver before it goes into the servo, and use this to drive the input to the MOSFET driver. However, this gives you no choice of switching frequency. Alternatively, the potentiometer can generate a voltage to feed into the PWM generator. If you are unsure about your servos, or want to modify them, there is an introduction to them on the Seattle Robotics Society page here. A more advanced method if you have a microcontroller on board the robot is to take the PWM signal from the radio receiver and connect it to a timer input of the micro. The microcontroller should be able to decode this waveform, and generate a proportional analogue output value (if it has ADCs, or if an external ADC is fitted). Another even more advanced method is to send serial communications data through the radio channel. The radio control handset will need to have a microcontroller in. The microcontroller should read the pots and switches on the handset, and send suitable commands out of its UART. This connects to the radio transmitter. At the receiver, the demodulated output is sent to the robot's microcontroller's UART, and the data is decoded. There is a whole chapter on using embedded microcontrollers in a robot here

10. Current limiting

Current limiting is absolutely essential. If the motor is stalled, it can take huge currents which would destroy the MOSFETs very quickly. The form of current limiting presented here is to measure the current that the motor is taking, and if it is above a preset threshold, turn the MOSFETs in the bridge off. If you have a microcontroller on board which generates the PWM ratio, it would be an advantage if the software could detect the over- current status, and reduce the PWM ratio by, say, 10%. A circuit to perform this function is shown below.

This circuit shows just the upper MOSFETs of the bridge being driven for simplicity. The lower MOSFETs are not turned off during a current limit. There is only one sense resistor required for each motor, and that should be connected immediately from the battery positive terminal. Circuit description The voltage dropped across the sense resistor is amplified by U1A, which is connected in a differential amplifier circuit. The gain of this is 480k / 1k which is 480. This is a very large gain because the voltage dropped across the sense resistor will be very small. The output of the differential amplifier is then heavily low pass filtered by RxCx. This is because there will be a lot of noise coming from the motor, and we do not want to limit the current if we don't need to. D13 is present to make sure that no negative spikes can affect the following circuitry. U2B compares the filtered signal with a preset value (represented here by V5), and if the current is too high (i.e. the signal is greater than V5), U2B will turn Q1 and Q2 on which clamps the PWM signals from the PWM generator. This will force the MOSFET driver to turn the MOSFET off. Q1 must be repeated four times, one for each of the MOSFET driver channels, but all four transistors can be driven from U2B. D11, R14 and C4 make sure that the MOSFET doesn't turn back on straight

away, but takes a few milliseconds. This stops the MOSFET being rapidly turned on and off.

10.1. The shunt resistor

The shunt resistor R7 in the cicuit must be a very low value if we want large currents to be able to flow, up to 100 Amps for example. It must not drop too much voltage, thereby robbing power from the motor, and it must be capable of dissipating the power without buring out when large currents are passed through. Some suitable resistors are available from Farnell, code 156-267. These are still too large a resistance (and too low power), so we can place eight in parallel. The power handling capabilty is then increased eightfold, and the resistance decreased eightfold. An alternative is to use a piece of wire of an appropriate thickness and length. This can be calculated using the data on this web site. A simulation of the current limiting part of this circuit is shown in the diagram below. The V5 threshold voltage was chosen to set a current limit of 30 Amps. The square wave is the PWM voltage (MOSFET gate voltage), and the slopey waveform is the drain (motor) current. The spikey bits at the top of the slopey waveform is when the current limiting is switching in and out.

There is an in-depth document here which describes sense resistors in detail. Some circuits you may see sample the current going through the main power MOSFET by placing a much lower power MOSFET in parallel with it. There is a circuit on the 4QD site which does this here. This works OK, but the problem is the actual limiting current is dependant on the value of Rds(on) of the MOSFET. If Rds(on) was only half the value we were expecting it to be, then twice as much current would flow before the

limiting circuit took effect. Also the Rds(on) value depends very much on the current that is passing through the MOSFET, and on the temperature. Any variation in Rds(on) will change the limiting current. The Rds(on) figure is quoted as a maximum value on the datasheet, but it is not a designsafe parameter. This means that it is not within defined limits which are published on the datasheet. For example, CMOS digital logic guarantees that the output voltage, Vo, will be between Vcc-0.5v and Vcc, and that figure can be used to design circuits which rely on that figure. However, with Rds(on), we only know that it will be between 0 and the quoted value. We cannot rely on a minimum value of it, yet it is the minimum value which controls the current limit. Therefore, using a separate shunt resistor is a much safer method. One problem with the circuit presented above is that you may want to provide a larger current during acceleration, or in emergencies. This can be solved by disabling the current limiting using a separate line from any onboard microcontroller, or by adding a circuit which allows an over-current condition for just a short time. The amount of time that this is allowed must be carefully calculated to prevent damage to the MOSFETs, and must take into account the cooling system that you have provided. An alternative to using the op-amp differential amplifier circuit used above is to use an integrated current sense monitor IC. Several companies make these, I have used the Zetex ZXCT1010. Zetex's range of current monitors can be found here.

10.2. Current limited torque speed characteristics

If a DC motor is being driven by a speed controller with current limiting active, what happens to the torque speed characteristic graph? The DC Motors page describes the normal motor torque speed graph, and how the torque of a permanent magnet DC motor is proportional to the current. If the current is limited however, the torque must also be limited, at the value coincident with the limited current on the torque-current graph. The effect that this has on the torque speed graph is shown below:

As the load torque increases, the speed drops - we are following the line in the torque speed characteristic from the left hand side towards the right, drooping down. This is the same as the uncontrolled motor. The motor torque always equals the load torque when the motor is running at constant speed (this follows from Newton's first law - "An object in motion tends to stay in motion with the same speed and in the same direction unless acted upon by an unbalanced force." The motor torque and load torque must be balanced out if the speed is not changing). Let's call the current limit value iL and the equivalent torque value on the torque-current graph at this current is TL. When the load torque exceeds TL, the motor can no longer create an equal and opposite torque, and so the load will push the motor backwards in the opposite direction - we are now following the line as it drops downwards into negative speed. Let's take an example; an opponent's robot is more powerful than ours (or his current limit is set higher), and we are in a pushing match. As each pushes harder, our speed controller reaches its current limit first. Our robot is now pushing at a constant force (since the motor torque is now constant at its highest value). As the opponent pushes harder, our wheels start to rotate backwards, and the pair of robots accelerates backwards at a rate given by Newton's second law: F=ma or a=F/m where F is the difference between the forces of the two robots pushing, and m is the total mass of the two robots.

11. Feedback Speed Control

To stop a robot swerving in an arc when you want it to go forwards, you need to have feedback control of the motor speeds. This means that the actual speed of each wheel is

measured, and compared with all the other wheels. Obviously to go in a straight line, the motor speeds must be equal. However, this does not necessarily mean that the speed demand for each motor should be the same. The motors will have different amounts of friction, and so a stiffer motor will require a higher speed demand to go as fast as a more free-running motor. A block diagram of an analogue feedback speed controller is shown below

The speed demand is a DC voltage, which is fed to the PWM generator for motor A. This drives motor A at a speed dependant on the demand voltage. The speed of motor A is sampled using an optical encoder. This has a frequency output, which is proportional to the speed of the motor. If we assume that motor B is already running at some speed, then the optical encoder on its shaft will be producing a frequency also. The phase comparator compares the two frequencies, effectively comparing the speeds of the two motors. Its output is a signal which gets larger as the two input frequencies get further apart. If the two frequecies are the same, it has a zero output. The integrator adds the output of the phase comparator to whatever its output was before. For example, if the integrator output was previously 3 volts, and its input is 0 volts, then its output will be 3 volts. If its input changed to 1 volts, then its output would change to 2 volts. Lets assume that motor B is running slower than motor A. Then the output of the phase comparator will be positive, and the output of the integrator will start to rise. The speed of motor B will then increase. If it increased to a speed greater than that of motor A, then the output of the phase comparator would become negative, and the output of the integrator would start to fall, thereby reducing the speed of motor B. In this manner, the speed of motor B is kept the same as the speed of motor A, and the robot will go in a straight line (as long as its wheels are the same size!).

This method can be expanded to use any number of wheels. One motor will always be the directly driven one (in this case motor A), and the others will have their speed locked to this one. Note that if the directly driven motor is faster, or more free-running, than the others, then when it is driven at its fastest speed (the PWM signal is always ON), then the other motors will never be able to keep up, and the robot will still swerve. It is best, therefore, to directly drive the slowest motor. An analogue feedback speed controller such as this is quite difficult to make, and keep stable. It is easier to perform this function using software in an onboard microcontroller....

11.1. Software feedback speed control

To perform the same function as described above in software requires that the software has digital representation of the speed of each wheel, and can finely control the width of the PWM signal sent to each wheel. To get the speed of each wheel, an optical encoder must be used as in the analogue method, but the output of it must be sent to the microcontroller. This is achieved using a counter, clocked by the speed controller, which the microcontroller can read, and can clear. At regular intervals, the microcontroller must read the counter, then clear it. The interval depends on the maximum speed of the robot, the diameter of the wheel, the number of slots in the speed encoders disc, and the number of bits of the counter. A complete design using this technique is being worked on and will be presented here when it is complete.

11.2. Speed encoders

To start with, we need a device that will measure the speed of the motor shaft. The best way to do this is to fit an optical encoder. This shines a beam of light from a transmitter across a small space and detects it with a receiver the other end. If a disc is placed in the space, which has slots cut into it, then the signal will only be picked up when a slot is between the transmitter and receiver. An example of a disc is shown below

A suitable encoder is available from Maplin, code CH18U for about 2 each

The encoder transmitter must be supplied with a suitable current, and the receiver biased as below:

This will have an output which swings to +5v when the light is blocked, and about 0.5 volts when light is allowed to pass through the slots in the disc. These voltages are comptible with normal digital circuitry. However, because this device is right next to a DC motor, which generates a lot of electrical noise (since it is switching high currents at the commutator into the inductive windings hence high voltages and sparks!), the output must be low-pass filtered. The phase comparator should have as little noise as possible at its inputs. The cutoff frequency for the filter is determined by how many slots are in the disc, and by how fast the disc (and hence the wheel) is intended to rotate. It is given by the equation

where sw is maximum speed of the wheel in rpm, and n is the number of slots in the disc. The filter can be made from a simple RC circuit as follows:

Then the R and C values chosen such that

For example, if the maximum wheel speed is 10rpm, and there are 12 slots in the disc, then RC = 0.08, so suitable values of R and C might be 8k2 and 10uF. An alternative way to measure the speed is using a magnetic sensing device. If your motor or gearing has steel teeth, then sensors are available that can detect and count these as they go by. The Infineon TLE4942 is such a device. I will not go into this anymore since the datasheet at that link describes how to use the device. Allegro also make many magnetic devices for speed measurement. The Allegro Microsystems website is here