
Using a Stepper Motor from a Floppy Drive
=========================================

This file describes how to drive a stepper motor cannibalised from a floppy
drive using - you guessed it - the parallel port on an IBM PC.

A good source of cheap stepper motors is busted floppy drives. Unlike some 4
wire stepper motors, the motor has two separate windings with four wires - the
first winding with red and blue wires and the second with white and yellow
wires.

I got mine out of an old 5 1/4" 360K floppy drive. It is one of those chunky,
squarish ones. It operates at 12V and needs 80mA. It is a 3.6 degrees per step
or a 100 step per rotation motor. The other one in my collection is a tiny,
round stepper from a 3 1/2" 1.44MB floppy drive. It operates at 5V and I don't
know its current requirements. The label on it says it is an 18 degrees per
step or a 20 step per revolution motor. I will try this one next.

This type of motor is driven by energising the coils in each direction in turn.

An H-bridge driver is required for each coil. This makes driving the coils a
little more complicated compared to other four wire motors. The sequence to
rotate the motor is shown below. A + indicates the coil is energised in one
direction, - indicates energising in the reverse direction and a . indicates no

energising.

      Coil 1(R&B) + . - .
      Coil 2(Y&W) . + . -

I have used the L293 chip connected to an IBM PC parallel port. This chip has
two H-bridge drivers. Other alternatives may be using a discrete transistor
circuit or 4 LM386 audio amplifiers(some day!). The L293 is not too hard to
find(?) and makes it possible to implement the driver using just 1 IC and a few

other components for just under 20 bucks(1 buck = 0.73 US cents).

The signals given to the L293 to get the right signals at the stepper coils as
shown above is shown below.

      CE1      1 0 1 0
      INP1     0 0 1 1
      INP2     1 1 0 0
      CE2      0 1 0 1
      INP3     0 0 1 1
      INP4     1 1 0 0

      OUT1     0 . 1 .
      OUT2     1 . 0 .
      Coil 1   + . - .
      OUT3     . 0 . 1
      OUT4     . 1 . 0
      Coil 2   . + . -


Schematic Diagram
-----------------

                  +------+------+---+------------+---+---O +12V
                  |      |      |   |            |   |
                +----------+   _|_ _|_          _|_ _|_
                | Vs    Vss|   /_\ /_\   D1-4   /_\ /_\
                |    IC1   |    |   |            |   |
                |   L 293  |    |   |   Y     R  |   |
    D5(6) ------|INP1  OUT1|----+-------+     +--+-----------+
    D4(5) ------|INP2      |    |   |  (_    (_  |   |       |
                |          |    |   |   _) M  _) |   |       |
    D6(7) ------|CE1       |    |   |  (     (   |   |       |
                |      OUT2|--------+---+     +------+---+   |
                |          |   _|_ _|_  W     B _|_ _|_  |   |
                |          |   /_\ /_\   D5-8   /_\ /_\  |   |
    D2(3) ------|INP3      |    |   |            |   |   |   |
    D1(2) ------|INP4      |    +---+-----+------+---+   |   |
                |          |              |              |   |
    D3(4) ------|CE2   OUT3|-----------------------------+   |
                |          |              |                  |
  Gnd(18) ---+--|S3        |              |                  |
             |  |          |              |                  |
             +--|S4    OUT4|---------------------------------+
             |  | S1 S2 GND|              |
             |  +----------+              |
             |     |  |  |                |
             +-----+--+--+----------------+---O Gnd


Parts List
----------
IC1     L293
D1-8    1N4001


L293
----
I know of about three different varieties of L293 - L293B is a 16 pin DIP rated

at 1A without diode protection, L293D(?) is a 16 pin DIP rated at 0.6A with
diode protection and L293E is a 20 pin DIP rated at 1A without diode
protection. The current requirement for the stepper motor is modest and L293D
is the best option. The diodes D1-D8 will then not be required. I could get
only an L293E and that is what I ended up using.

    Function          L293B/D       L293E
    --------          -------       -----
      CE1                1             1
      INP1               2             2
      OUT1               3             3
      S1                 -             4
      GND               4,5           5,6
      S2                 -             7
      OUT2               6             8
      INP2               7             9
      Vs                 8            10
      CE2                9            11
      INP3              10            12
      OUT3              11            13
      S3                 -            14
      GND             12,13         15,16
      S4                 -            17
      OUT4              14            18
      INP4              15            19
      Vss               16            20


Interface Routines
------------------
The bit patterns to be output on the parallel port once the connections are
made as given in the schematic diagram are 29H, 0DH, 32H, 16H. I am assuming
the LPT1 port at 0x378 is being used. The routines to step the motor forward
and backward by one step are given below. Swap the wires to the motor around to

get the direction of rotation right and to adjust the zero position.

    unsigned char StepBits [ 4 ] = { 0x29, 0xd, 0x32, 0x16 } ;
    int StepInx = 0 ;

    ForwardStep()
    {
        if ( ++StepInx == 4 )
            StepInx = 0 ;
        _outp ( 0x378, StepBits [ StepInx ] ) ;
    }

    ReverseStep()
    {
        if ( --StepInx < 0 )
            StepInx = 3 ;
        _outp ( 0x378, StepBits [ StepInx ] ) ;
    }

Source code for an MS-DOS program with a graphical interface should accompany
this document. It is in C++ and was compiled using Microsoft Visual C++ 1.5. It

uses the extended graphics library and needs a VGA. An executable is also
provided.

Permission is hereby granted to make copies for personal use. Distribution for
non-profit is permitted provided the author is notified by email.


Prashant Bhandary
prashb@rta.oz.au
4 Mar 95

