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.
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-Oxide-Semiconductor 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 won’t 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.
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!
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:
This third point can be seen from the following two graphs. One shows the worst case on-off 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.
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:
Let’s 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 = 70µH
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 Ω.
A graph can be drawn for this particular motor:
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 39µH as being one of the lowest.
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 wasn’t 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.
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!
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.
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:
When the triangle waveform voltage is greater than the DC level, the output of the op-amp 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.
f = 1/(2.PI.R.C)
but it doesn’t 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.
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.
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
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.
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 low-power 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
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
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.
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 design-safe 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.
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.
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.
Let’s 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....
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
SGS Thomson produced a good document about current limiting in a
full bridge circuit.
DC motor driving including methods of speed regulation.
Driving DC motors
Good ones are "Current Ratings of Power Semiconductors", "Paralleling HEXFET® power MOSFETs", "Gate Drive Characteristics and Requirements for HEXFET® power MOSFETs", and "The Do's and Don'ts of Using MOS-Gated Transistors", all of which are included at the following site:
A converter for the above project to convert an analogue in signal into direction and PWM signals: