Motor Controllers: See My Tutorial
Motor Controllers: See My Tutorial
In this tutorial I will introduce various motor controller circuits for DC motors
and stepper motors (uni-polar and bi-polar). Where appropriate I will give an
idea of guideline costs - based on prices at Digikey as of summer 2008. These
costs will assume that you are adding the controllers to an existing robot project
and so will exclude the costs of the motors, wiring, soldering equipment, circuit
board etc and focus purely on the cost and capability of the crcuit.
Each controller has an Eagle schematic but the implementation ie strip board,
matrix board, hand crafted PCB is up to you. For those unfamiliar with Eagle
then I suggest that you download the free/light version.
1 - Introduction
Why do I need a controller?
it will fry your microcontroller. Why? Well the pins on your microcontroller are
only capable of supplying a few milli-amps of current (they are designed for
driving other logic chips) - but your motor (being a big physical 'thing')
requires a lot of power to make it move. The purpose of a motor controller is to
convert the small powered signals from your micro-controller into more
powerful signals that can drive motors. Given that 'Power = Amps * Volts' and
'Volts' is a fixed number then the power required is proportional to the current
required. The more current then the more power. But power generates heat. And
this is why you will 'fry' your controller. It will try to generate lots of current in
order to drive the motor but this current will create heat, and since your
controller has no heatsink, then it will melt !!
Stall current
Motors will require more current when they are under stress. So if you hold
your robot in the air and allow the motors to turn then, because there is no
resistance, they will need the smallest amount of current,. Now put your robot
on the floor: and the weight of the robot will create friction and so the motors
require more power to overcome this. Now if your robot is going up a steep hill
or, worse, has hit a solid wall and is therefore trying to turn the motors but the
wall prevents it from doing so then the motors are under the maximum amount
of stress. This latter scenario is known as the 'stall current' and you need to
make sure that your circuit doesn't get fried by this peak requirement. You can
measure this 'stall current' with your multimeter by connecting the motor to
your battery so that it turns and then hold the axle to stop it from turning. This
'stall current' is a very important value to measure for DC motors as it dictates
the maximum current that your motor driver needs to provide. Without it your
robot may work fine until it hits a wall and then 'hey presto', the current goes up
and your circuitry melts!
Alien
If the above is too technical then think about the Alien movie where Sigourney
Weaver gets into that robot suit that makes her 'extra strong'. That suit is a
'motor controller' - it converts her puny (but lovely!) movements into a much
more powerful movement.
Stages
Think of your electronics in this way:1. The micro-controller works at 5 volts and small current. It is enough to drive
other 'chips' but not motors. I call this the logic stage - as all of the electronics
will work in this world. The logical world.
2. Motors work in another world of high current, higher voltages, heat, current
spikes etc. The real/physical world.
3. You need something that sits in-between these worlds that converts microcontroller signals into something more powerfull that can control a motor. This
is a motor controller.
1. Spin clockwise
2. Spin anti-clockwise
3. Free wheel (ie coast to a halt)
4. Brake (ie try to stop immediately)
Other variations are that we probably also want to control the speed of the
motor as well as the direction (clockwise/anti-clockwise) so that its not just 'full
steam ahead' or 'full steam in reverse'. This always creates a challenge - as the
more control you require tends to increase the number of precious output pins
that you require for each motor. So we need to maintain flexibility whilst
minimising the number of processor pins.
This diagram shows that each motor requies a 2 pin connection to your microcontroller via JP1, and provides 3 outputs to the motor controller stages.
Pin 1 - is used to Enable or Disable the motor controller chip. Whenever the
controller is disabled then it is in 'coast' mode. So if we ask the motor to go in a
particular clockwise direction then we can use this pin to set the speed that it
turns. If it aways high then the motor rotates at full speed. If it is always low
then the motor is disconnected and so doesn't turn. By using PWM we can
control the speed of the motor from 100% to 0% duty cycle. So pin 1 is the
'throttle' or 'accelerator'.
Pin 2 - Sets the direction of the motor - Forward or Reverse. If this input is high
then Input 1 is high, which turns on the transistor so Input 2 is low. This makes
the motor turn one way. If this input is low then Input 2 is low, the transistor is
off and so input 2 is high, and the motor turns the other way. But the cool thing
is that if this pin is disconnected then Input 1 and Input 2 are both in the same
state which means that the motor will brake. How do you 'disconnect' a wire
that is soldered in - all we do is change the micro-processor pin to be an input
pin and the built in resistors make this wire 'disconnected'.
Pin2
Description
High Output
High
High Output
Low
Low (Any)
High
Coast
Input
Any
Brake
The transistor Q1 does not have to be a BC108 it can be ANY general purpose
NPN transistor.
3 - DC Motors
There now follows various circuits for driving DC motors. The circuit most
suitable for your project will depend mainly on the current consumption of your
motors.
This controller is limited by the abilities of the L293D:- it can provide 600mA
per motor or a maximum of 1.2 amps for a micro-second.
Each motor requires two pins from the micro-controller and this uses the 'tristate switch' stage mentioned earlier.
Cost
This requires one tri-state switch per motor;
one L293D for every two motors. The L293D costs about $4.30
So about $6 in total - for driving two motors
NB I now recommend that you use an SN754410 instead of the L293D. This is
a direct plug in replacement and has the advantage it can provide 1A rather than
600mA and it also costs about 98 cents !!!
Either: use the previous 600mA circuit but replace the L293D with a Texas
Instruments SN754410 which is a direct pin for pin replacement. This is the
preferred solution as the chip costs 98 cents and you dont need the additional
diodes.
This circuit is similar to the 600mA version except that:1. It uses the 'L293' rather than the 'L293D'
See http://focus.ti.com/lit/ds/symlink/l293.pdf
2. This chip allows a higher current of 1 amp per motor but requires us to add
the diodes at the output stage. These should be fast, ie Schottky, diodes that can
cope with the 1 amp current and a reverse voltage greater than, or equal to, the
voltage of your motors. The motor voltage is still limited to 36v.
Costs
This requires one tri-state switch per motor;