TORQUEING OF STEPPING MOTORS
By MIKE COOK
THIS seems to be the Year of the Robot. What with the BBC TV
series "Computers in Control" and the upsurge of computer
add-ons of various forms, all designed to produce movement in
response to computer control.
There is a plethora of buggies that scurry about the floor,
robot arms that make a sudden grab for you or plotters that will
draw out high resolution pictures in as many colours as you have
felt tip pens.
In all this work the single most popular method of producing
movement is by means of a stepping motor. Although this is not
the only way of generating movement on demand, it does have many
advantages.
You probably already own a couple. There is one in your disc
drive and two in most printers.
These motors have been around for many years but only recently
have there been low cost computers to take full advantage of their
special features.
So this month we have a look at stepping motors and how to drive
them.
A normal motor starts to rotate when you apply a voltage to
it and slows down and stops when that voltage is removed. If you
want to control its speed you usually have to resort to gears.
Although there are various electronic methods of motor speed
control these are usually used to make small adjustments, while
it is gears that get the speed in the right order of magnitude.
The problem is that for a conventional motor to run efficiently
it has to run at around 300 rpm.
The amount of turning power, or torque as it is known, is the
way a motor's power is measured. With gears, as the speed is reduced
the torque is increased - a very happy state of affairs.
However most electronic motor control reduces the speed as well
as the torque.
When it comes to controlling a conventional motor with a computer
the motor takes some time to get up to its final speed. So it
is difficult for the computer to "know" how many revolutions
it has turned through.
It is normal therefore to include some form of feedback arrangement
so the computer can sense the motor's position.
However this feedback is not needed with stepping motors, which
is why they are such a natural for use with computers.
A stepping motor, as its name implies, works not by continuously
rotating but by moving in a series of small steps. Each time the
motor receives a pulse it moves through a fixed angle. The size
of this angle depends mainly on the design of the motor.
Motors are usually classified by how many steps are taken to
complete one revolution - ranging from 4 to 200 steps per revolution.
Another way of expressing this is to quote the size of angle
of each step.
As stepping motors are difficult to get hold of The Micro User
is offering Stepping Motor Experimenting Kits as Body Build Packs
Nos. 12 and 13 (see Page 157 for the order form). These include
a motor as well as the electronics to drive it.
The stepping motor we have used has a step angle of 7.5 degrees.
It is the same type as is used in some of the commercial devices
advertised in these pages.
Let's see what makes a stepping motor tick. If you have a coil
and pass a current through it you will generate a magnetic field.
This will behave just like any other magnet and will attract other
magnetic material to it.
Suppose we have a permanent magnet suspended above four coils.
If we pass current through two of the coils the magnet will be
attracted towards both and will settle somewhere between the two.
This is shown in Figure la.

Figure I: The principle of a stepping motor
We have an arrangement, which will be explained later, to prevent
the magnet getting too close to the coils.
Now supposing we remove the current from coil 1 and turn on
coil 3, as in Figure Ib.
The magnet will move towards the two coils that are exerting
a magnetic force and will come to rest between coils 2 and 3,
as in Figure Ic.
We can repeat the process with coil 2 going off and coil 4 coming
on, as shown in Figures Id and Ie.
If we look what has happened to our magnet we will see that
it has moved in a straight line in response to our switching currents
in the coils.
This is the principle of the stepping motor, only instead of
movement in a straight line we have a circular movement.
This is obtained by having several coils, each wired as one
of four circuits, distributed in a circle. We call this the stator
of a motor because it does not move.
In the centre of the circle we have a drum bearing a number
of small magnets. The drum is known as the rotor — it's the part
that rotates.
The magnets are not actually separate magnets but are bumps
or poles on a large central magnet.
As the rotor is on bearings and the poles are distributed evenly
around it, the poles can never come in contact with the coils.
Figure II shows a small section of a stepping motor. Only coil
1 is shown wired up, for clarity, but you can see that every fourth
coil is connected together.

Figure II: A stepping motor
You can also see that the number of coils in the stator is four
times the number of poles on the rotor, and this number determines
the angle of each step.
A stepping motor can therefore be precisely controlled by switching
the currents in each of its four coils. So a stepping motor has
five wires coming out of it, one for each coil and one common
connection.
The coils take far more current than can be produced by the
computer. This means we have to build something to convert our
logic voltage output to the currents needed.
The simplest way to do this is to use four VMOS power FETs.
These devices were explained in the Body Build article in the
August 1983 issue of The Micro User.
Figure III shows the general arrangement. You can see from this
that the stepping motor usually requires more than the normal
5 volts, and this is applied to the motor through the common coil
connector.
Figure III: Control of a stepping motor
Most motors will operate with between 12 and 24 volts, although
some can use 120 or even 240 volts. The FETs shown will happily
switch voltages of up to 60 volts.
Each of the FETs is controlled by one bit on the user port and
should be connected up using Body Build packs 1 and 2 or something
similar. Therefore by putting a logic 1 on the user port output
we can switch the coil on.
By outputting the correct sequence of logic levels we can make
the motor rotate.
If we refer back to Figure I and write a logic 1 for each coil
that is on and a logic zero for each coil that is off, we get
the sequence of numbers to present to our motor. This will be
3, 6, 12, 9.
Note the last one is not shown in Figure I, but it is needed
to wrap round smoothly to the start of the sequence again.
Before we see how this can be generated by the computer let's
look at another possible sequence of pulses that we can use to
drive our motor.
Consider Figure IVa. This shows the motor in the same position
as Figure Ia. Now if we leave only one coil on, the magnet (pole)
will go directly over it. This is shown in Figure IVb.
Figure IV: Half stepping a motor
If we now switch on coil 3, the magnet will move between the
two (see Figure IVc).
If we extend this sequence we will find that it takes twice
as many steps as the first sequence. This results in the motor
moving through only half the angle for each step - known as half
stepping the motor.
The degree of precision is greater, but as you might expect
there is a price to pay - the motor's torque is reduced. As there
is one coil on for half the time, you are putting less power into
the motor. Therefore you get less power out.
With the full step sequence there are two coils on all the time.
However in some circumstances it is a useful trick to know.
Any software must present the correct sequence to the motor.
The easiest way to do this is to hold the sequence in an array
and set up a counter to keep track of the next element in the
array to be outputted.
A program to do this is shown in Listing I on Page 152.
Listing I
The procedure to output the next bit pattern in the sequence
is from line 280 to 350.
It is passed two variables. The first, "ROUND", is
a logic variable to tell the procedure which way to step through
the sequence.
The second variable is used in a delay loop to control the speed
of the motor. The delay loop is executed first and then D% is
set depending on the direction you want to go.
Line 310 moves N% on to the next sequence in the pattern. The
logical AND instruction ensures that if N% is 7 and we add one
we will get 0. Also if N% is 0 and we subtract one we will get
7.
This effect is known as the number "wrapping around".
The AND instruction was explained in the August 1983 issue of
The Micro User.
In order to show off the stepping motor procedure the rest of
the program makes the motor rotate backwards and forwards.
When I show this to my students I have a small Union Jack on
a cocktail stick which I attach to the motor. The computer enthusiastically
waves the flag, which is a good thing for a British computer.
As you can see, the motor does not run very fast. But by simplifying
the program it is possible to get it working at top speed. However
top speed is something that is very variable.
We have seen that torque is the pulling power of a motor. In
a stepping motor the torque is inversely proportional to speed.
That means the slower it goes the more power it has.
In fact it has maximum torque when it is stopped. You can test
this by trying to force the motor to turn by hand.
You will find this harder to do when it is stopped - but still
has two coils on -than when it is running fast. If we try to make
it go too fast the motor will not have enough torque to turn itself,
let alone a load, and so will stall.
When you approach stalling speed you will notice the motor start
to miss steps and make a stuttering sound. This maximum speed
of the motor from a standing start is called the "pull-in''
speed.
If the motor is running it can be accelerated to a speed slightly
faster than the pull-in speed. So if you want to run stepping
motors at full tilt you have to start them relatively slowly.
One way to achieve more torque, and thus a greater speed, is
to increase the current through the coils. This means increasing
the voltage used to drive it.
At some point you will reach a limit imposed by the DC current
rating of the coil. In fact you can go even faster than this by
employing a little trick.
When you switch a coil on initially there is no current flow
as the change in current in the windings induces a magnetic field.
This field then induces a voltage back in the coil, but in a direction
to oppose the current flow.
If this process was 100 per cent efficient you could never get
any current to flow in a coil, but fortunately it is not. The
result is that when the coil is switched on it takes a time for
the current to build up.
If you are stepping the motor fast, the current will not have
built up to its full amount before the coil is switched off again.
This accounts for the strange fact that a stepping motor takes
more current when it is stopped than when it is moving.
The trick in getting a faster rise time of current is to increase
the voltage even more. However this will exceed the maximum DC
current through the winding and so a resistor should be inserted
in each coil line to limit the current.
When calculating the value of the resistor make sure to allow
enough wattage as the resistor will get warm.
The inductive part of the resistor/coil combination is thus
proportionally smaller and so there will be a faster rise time
of current in the coil, allowing a faster speed to be achieved.
The only snag with the type of control I have described so far
is that it requires four computer output bits to drive the motor.
We can make a saving in this number if we generate the sequence,
not with software, but with hardware. Then we need only two bits
to control our motor - one to specify direction and one to tell
it to step.
We can control seven motors from the user port as long as we
only want to move the motors in one direction at a time.
Alternatively, if we want full simultaneous control of each
motor we can drive four from the user port.
You can generate the required sequence with two JK flip-flops
and a data select IC. This can be fed to the same power FET drives
as shown previously.
However there is an IC which will do the whole job for you -
and it is cheaper than individual components. The circuit diagram
is shown in Figure V.

Figure V: A hardware sequence generator circuit
The Mullard SAA1027 works with high level logic and therefore
the logic levels out of the computer have to be boosted by the
transistors Tl and T2. This IC can be connected directly to the
stepping motor's coils with any supply between 9.5 and 18 volts.
To drive this all you have to do is to set the logic level for
the required direction and give a pulse to the step line.
This is shown in Listing II and essentially does the same as
Listing I but is designed for the new hardware circuit. Also any
one of seven motors can be specified.
Listing II
The direction line on all the stepping motor circuits should
be wired up to bit 0. The step line should be wired to any output
bit 1 to 7.
The program asks you which motor you want to use and line 130
converts this to a number with the appropriate bit on the user
port set to a logic one.
You can see the procedure for stepping the motor is a lot simpler.
After the delay, line 280 outputs the direction indicator D% and
sets the step line high.
The next line keeps the direction indicator the same and puts
the step line low again.
If you want to control more than one motor you can have a step
and direction line for each motor. In this way the motors are
entirely independent.
The program needed to drive four motors independently and simultaneously
is a little involved and best left for another time.
However if you want a crack at it you could use the event timer
to initiate a background task. This would decrement a counter
for each motor and output a pulse to those motors whose counters
had reached zero.
In this way a Basic program could just store numbers into those
counters to get the motors moving.
Two Body Build kits are available this month, one using the
computer to output the sequence and the other using the SAA1027
stepping motor driver chip.
I could have laid out a small printed circuit for each kit,
but as you will probably be incorporating the motors into your
own devices it would not have been worthwhile. So the kits contain
components only this month. The full contents can be found in
the component lists below.
Finally, you will need a power supply to drive the motors. If
you are just running one or two you can use the external power
socket on the underside of the computer. You can get the sockets
from advertisers in this magazine.
If you are planning to use more, or you already have your discs
plugged in, you will have to buy or make a supply. The type of
supply made for CB radio transmitters is usually reasonably priced
and should do an adequate job.
Having now got the tools, you can devise your own projects in
the fascinating world of computer control and robotics.
Remember the slogan: "If it moves it's probably a stepping
motor". No? Well, see you next month.
Component list Body Build Pack 12:
ID 35 35014 stepping motor,
4 VN10KM VMOS power FETs.
Component list Body Build Pack 13:
ID 35 35014 stepping motor,
SAA1027 stepping motor drive IC,
2 BC182 transistors,
4 20K resistors,
100R resistor,
150R 0.5W resistor,
0.1 uF disc ceramic capacitor,
16 pin IC socket.
• Packs 12 and 13: Components to control stepping motors in
two different ways.
Pack 12's version uses the micro to control the stepping sequence.
Pack 13 uses a dedicated stepper motor driver chip, allowing
the user port to control more motors.