Site hosted by Angelfire.com: Build your free website today!

 

About Me

 

Downloads

 

Guestbook


Using Decoders

So you built the stepper motor driver, but you want to drive 5, 6...10...16 motors! Using my controller board, I will use two pins of the parallel port for signal lines (direction and trigger). I can drive four motors on 8 pins of the DATA port. I can also use the CONTROL port for additional motors but there's only additional room for two. We'll try to get around these limitations.

There's a way to control 8 motors by using 3 pins of the DATA (378H) port which we will use for "addressing" and two for the signal lines. We will have to add another component to our controller, a 3-line to 8-line decoder/demultiplexer (74LS138). The existing design of the controller will also be slightly modified by making use of pin 5 of CD4516 Binary counter, it will be used as enable/disable control.

Click here to view the schematic. I've also included a sample program written in Visual Basic 6 for this schematic. I advise you to read this article carefully for you to be able to understand what I did on the program.

The decoder has 3 input lines and 8 output lines. The output pins will have one and only one pin in lo state at any given combination of input. This makes it as an ideal "switch" for our controller. All the output pins of LS138 are active low and notice also that pin 5 of CD4516 is active low. The pins normally have +V on it which is their OFF state. Applying ground or 0V puts them in their ON state.

We can directly connect a single output pin from LS138 to pin 5 of 4516. Each of the 8 output lines of LS138 will be connected to its own CD4516.

Let's assume that we're going to use 3 pins of the DATA port for addresses and 2 pins for signal. Pins d7, d6 and d5 will be our 'address' pins and pin d1 will be 'direction' while pin d0 will be 'trigger'. The motors will be represented as m1, m2 ... m8. Here's a summary of the addresses of the motors.

d7
d6
d5
m1
m2
m3
m4
m5
m6
m7
m8
0
0
0
On
Off
Off
Off
Off
Off
Off
Off
0
0
1
Off
On
Off
Off
Off
Off
Off
Off
0
1
0
Off
Off
On
Off
Off
Off
Off
Off
0
1
1
Off
Off
Off
On
Off
Off
Off
Off
1
0
0
Off
Off
Off
Off
On
Off
Off
Off
1
0
1
Off
Off
Off
Off
Off
On
Off
Off
1
1
0
Off
Off
Off
Off
Off
Off
On
Off
1
1
1
Off
Off
Off
Off
Off
Off
Off
On

Table 1 (Addresses)

d1
Direction
0
clockwise
1
counter-clockwise

Table 2 (Direction)

Now the DATA port which we'll represent as:

d7 d6 d5 d4 d3 d2 d1 d0

If you want to move motor m4 in a counter-clockwise direction then you must set the address, direction, trigger on, trigger off in this order.

Address

According to Table 1, m4's address is d7=0, d6=1 and d5=1. The DATA port will look like this:

0 1 1 0 0 0 0 0

Direction

Now, according to Table 2, Pin d1 must be set to 1 for clockwise movement:

0 1 1 0 0 0 1 0

Trigger on

Set the trigger pin d0 = 1:

0 1 1 0 0 0 1 1

The value of DATA port in hex will be 63H. Using Visual Basic for example, we now have to send the value to the DATA port. Recall that the hardware address of the DATA port is 378H. Hex values must be prefixed with &H in Visual Basic syntax.

OUT &H378, &H63

Trigger off

The trigger off must follow trigger on after an arbitrary time interval that must not be less than 1.67 milliseconds (the stepper motor's speed limitation).

0 1 1 0 0 0 1 0

OUT &H378, &H62

Turning the trigger off is necessary to prepare for the next movement.

You realize that by using this method, you can only move one of the eight motors at any one given time. 16 motors can be controlled by adding another LS138 and using the remaining 3 pins of the parallel port. But the parallel port cannot drive so many motors so you'll need to amplify the signals from your direction and trigger pins (using two transistors or LS244).

Also, by further simplifying Table 1 and 2, we can arrive at these conclusions: the trigger pin can only have a value of 0 or 1; the direction pin can have a value of 0 or 2; the motors will be assigned to the addresses on the following table.

Address
Motor
0H
1
20H
2
40H
3
60H
4
80H
5
A0H
6
C0H
7
E0H
8

Table 3 (Summarized addresses)

All that we have to do now is to add ADDRESS + DIRECTION + TRIGGER then send the value to the port. This is what I've done on the sample program.

If you want to move motors simultaneously then all you have to do is create an array of boolean variables that will represent each motor. You have to loop through this array to check which are in TRUE/Enabled then send the equivalent output value (address+direction+trigger) to the port. Its like time-sharing your resources. Of course there are better ways of doing this like creating User Defined Types in Visual Basic to make it object-oriented and more flexible but this would be overkill.

You can download the datasheet of 74LS138 from Fairchild.


Another way...

It is even theoretically possible to control an unlimited number of motors using just 1 DATA pin and Ground of the parallel port (duh). But then again, it is not theoretically feasible for high speed applications. We have to implement a data network-like "packet" style of data transfer. All controller boards will be connected in series so a break in the line will render everything useless. We need to add a debouncer to every input of the decoder board. The number of motors we can control will depend on the size of the "packet" in bits. A 4-bit address will enable us to control 15 motors (60 bits per packet) and an 8-bit will control 255 motors (2040 bits per packet). Again, we'll only use 1 pin. But we need to synchronize the motors so we have an option to use another pin of the DATA port or install a timer circuit on each controller board. Using another pin is much cheaper and ensures that everyone will be in sync.

If you're wondering why we can only control 15 motors in a 4-bit packet its because we need to use the first number (0000) as an 'off' state for all the motors.

Our component count on the controller board will substantially increase. We need to add a 4-register and a comparator to each board. Now each comparator can handle 4 bits, so an 8-bit packet would mean 2 comparators, 16-bit = 4 comparators. If a comparator sounds daunting to you, then basic AND gates will do fine but your board design will suffer.

I stole this idea from the DMX512 standard implemented in professional stage lighting equipment. This is the protocol they use to control robotic stage lights which you commonly see in concerts, TV shows, etc. Although my implementation is nowhere near the robustness of DMX512, it will still do in amateur applications.

The first time I applied this idea was on a wireless chat system for my friends in college. I made my on very stupid encoding/decoding scheme. Using Visual Basic, I would send out only the address of the board. To give you a better idea, let's say we will control 3 motors. A 2-bit addressing scheme will be sufficient and our packet will be 6 bits in length.

Packet
Motor
00
off
01
m1
10
m2
11
m3

Table 1B (Motor addresses)

What I did was to count from 01 to 11 to make the three motors move. Say I want to move m1, m2 and m3 then I would send six consecutive signals to the parallel port like 0, 1 ,1, 0, 1, 1 and then kill the signal by sending 0. I just sent 01, 10 and 11 in one line (serial). If I wanted to make m1 and m3 move and not m2 then I'll send 0, 1, 0, 0, 1, 1. There are still three packets 01, 00 and 11. 00 was used as a filler so the decoder circuit will now that m2 must not move. To make the motors move continuously, we have to send the packets in a loop 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1.

Got the idea?

I use a header signal before sending the packets. The header signal is always 1 and it is prepended to the packet to be sent. Let's say our packet is 011011, we have to add 1 at the beginning making the first packet equal to 1011011. Using this header signal is only necessary when no motors are moving and the packets coming from the parallel port are all 0. Consider this as a wake up signal to let the decoder boards know to start their counting.

(Timing diagram to be included)


pao7/4/2k2
Home
Top
    Email