Stepper Motor Controller Objectives: --Gain familiarity with stepper motors --Build and understand a simple stepper motor controller --Learn the function of a shaft encoder --Design a circuit to use the motor, encoder, and an emitter/detector

Part A Electric motors are used everywhere, from golf carts, vacuums, CD players, to toys, Mars Rovers, and industrial robots. The simple motor you perhaps learned about in General Physics runs on DC power from two power leads. By reversing the polarity of the power, the rotation can also be reversed. More complicated motors run on AC power instead.

In some applications it is desired to precisely control just how far the shaft turns, for example in the open/close drive circuit for a CD player. With simple DC or AC motors, this could be accomplished simply by turning the power on and off at the right times, perhaps using external "limit switches" which mechanically sense the position of the driven parts. However, this is not a very flexible or programmable method.

A "stepper motor", is a type of motor specifically designed to be driven in precisely defined rotational "steps" rather than in continuous rotation. Typically it requires 100 or more steps to complete one shaft rotation. The amount of rotation ("angular displacement) is then controlled electronically by counting the number of steps through which the motor is driven.

A stepper motor can have between 5 and 8 leads, and any number of steps per one full turn. If you have any questions not answered below about stepper motors, Easy Step’n by David Benson should be available in the lab for you to peruse.

The theory is this: a pattern of four separate electromagnetic coils is constructed inside the motor (observe the four coils to the right of the main schematic). This pattern is repeated in a circular manner depending on the number of desired steps. To “step”, these coils are energized in a pattern, which attracts the poles of the center magnet attached to the shaft. The actual firing sequence is coil 1, 3, 2, and then 4. We then energize coil 1 again, but why should this keep us turning in the same direction and not return us to our starting shaft position? Remember that the coil pattern is repeated many times inside the motor. The field from the coil 1 next to coil 4 is stronger than the field from our starting coil 1! If in the course of building this circuit you do get a situation where the shaft doesn’t spin but just oscillates back and forth, you should realize you are not energizing the coils in the proper pattern.

For simplicity’s sake (I hope) and so that we can work in a more linear fashion, we shall make the following definitions. To turn these coils on and off we will use four switches. We wish to be able to flip these switches in the order 1, 2, 3, 4 so we let switch 1 work coil 1, switch 2 work coil 3, switch 3 work coil 2, and switch 4 work coil 4. You could of course use manual switches, but we are going to digitize and automate the whole process,

1 so these switches are going to be (hopefully no surprise by now) transistors! We shall use the 74175 again to create the cycling signal to be sent to these switches, and a new chip (for you), the DG403, to allow the stepper motor to be turned in either direction. Next I shall present the final schematic, then we shall discuss all its parts, and then we shall build and test it. After this we shall turn our attention to the shaft encoder, a device which will independently count shaft rotations, and then the emitter/detector, a very simple circuit that you should be able to use to make all this apparatus do something, albeit not to useful.

The first thing of note here are the four diodes to the right hand side. To understand these, please read H & H section 1.31 page 52, and also Easy Step’n page 13, if available. The above circuit has been run without these diodes, and despite H & H’s claim, the transistors did not die. It is certainly better to be on the safe side though! Once the circuit is up and running, you will notice it will not work above a certain input step pulse frequency. This is perhaps due to the fact the diode “lengthens the decay of current through the inductor” (H & H).

Next we need to discuss what the 74175 does. This is, surely, a series of four D-latches which all share a single clock and reset*. Suppose we turn this into a ‘tail bitter’, that is the output of 1 goes to the input of 2, the output of 2 goes to the input of 3, the output of 3 goes to the input of 4, and finally the output of 4 goes to the input of 1. This is really just the shift register of H & H section 8.26 (and also discussed in lecture), with the last output fed back to the first input. So, say this is setup (and we will get to the how in just a bit) with the output of latch 1 a 1 and all the others 0’s. With the first clock input, this one will move to latch 2, with all others being 0. Next clock pulse, this moves to latch 3,

2 with all others being zero. The next pulse brings it to 4, and the next to 1 again, restarting the cycle. Simply put, these outputs are also fed to the bases of the four transistors, turning these switches on and off in this cycle as well.

If one wires up the ‘175 in this manner and then switches on power, it will be seen all outputs go to 1. We first, then, need to bring reset* low to clear them. Then we need to bring reset* high again. Supply the input of latch 1 with 5V (this also supplies 5V to the output of latch 4, but since it is an output, it does not ‘listen’ to this.) Supply a clock pulse so this input is realized by latch 1 on its output. Now remove the 5V supplied to latch 1’s input. We have achieved the initial conditions mentioned in the preceding paragraph. We will call this ‘priming’ the circuit. As we now send a steady train of clock pulses, this high output will travel around the ‘175 in a loop.

There is a little more though…As mention in Easy Step’n pages 16 – 18, if we have a slightly different pattern looping around we can get more torque from the motor. Simpler/Less Torque Complex/More Torque Switch Number Switch Number 1 2 3 4 1 2 3 4 on - - - on on - - - on - - - on on - - - on - - - on on - - - on on - - on There are two ways to achieve the second pattern. The first is to proceed as above, but not to remove the 5V to the latch 1 input until two clock pulses have been sent. With the first pulse, latch 1 sets its output to 1; with the second pulse this output is realized by latch 2, and latch 1 again takes in the 5V as an output of 1.

The second method is to initially, after resetting of course, apply 5V to the inputs of both latch 1 and 2, and then remove this after only one clock pulse. Notice the two diodes coming from the middle 555 to the inputs of latches 1 and 2 in the circuit above? They carry the 5V priming signal, implying we have used this second technique. These diodes are absolutely necessary, otherwise the ‘on’ signal coming from 4 to 1 and from 1 to 2 will get gobbled up by the 555 instead of the inputs on the ‘175, and thus we would lose our signal and end the loop. (Another explanation is that after priming, the output of the 555 goes to 0, and it is easier for the 555 to maintain the 0V than it is for the ‘175 to maintain the 5V, so again we lose our signal. The diode puts a wall between these 0V and 5V signals).

Speaking of the 555, why do we have three of them in our circuit? They handle the automatic priming. When you build this circuit, you will first do this manually, and hopefully thus realize it would be nicer to automate it! Some things to consider: the ‘175 needs to be primed regardless of whether we receive an external step pulse or not. Therefore one of the 555’s is used to generate the single clock pulse needed for priming (in conjunction with the XOR and AND). Also, recall how we first needed to reset the ‘175? One 555 does this. The last 555 supplies the initial 5V signal to latches 1 and 2, which is then removed. I know, what a complex mess! Before we enlighten you, first let

3 us consider how a 555 gives a single pulse. The two pins TRG* and THR (trigger* and threshold) are the key. Before the capacitor connected to each 555 charges, TRG* is low, thus causing the output to go to 5V (high). When the capacitor charges to 2/3 of 5V, THR is now high, which brings the output to low (0V). The only way to bring the output back to high would be to send 0V to TRG*, which we do not allow since we leave no means for the capacitor to discharge. Therefore, the 555 gives us an initial brief high signal, then low forever after. Now we show a diagram that explains how we need the signals to come (polarity wise) and at what time. First we need to bring reset low and then high before anything else happens. This is the simplest thing and requires one 555, with the signal ran through an inverter. The next thing that happens in time is a clock pulse goes to the ‘175 to latch 5V on latch 1 and 2. Then we must remove this 5V signal (otherwise every latch would fill up with a high signal). But how do we send this single clock pulse? It involves both the latch signal, clock signal, the external step pulse signal, and an XOR and AND. Consider the external step pulse signal. Either we could be receiving no pulses, or very high frequency pulses. In either case, we do not want to listen to these until the signal to the latches has gone low. So we send the inverted output of the latch signal and the external step pulse signal to an AND gate (shown above as a NAND going into a NOT, using the chips at hand, the 7400 and 7404). Until the latch signal goes low (and its inverted counter part goes high), the output of this AND will be zero. We send this signal and the inverted output of the clock 555 (remember, these 555’s give us a high to low signal naturally—here we want a low to high) to an XOR (part 7486). So we have this: the latch signal is high, which means the AND output is low. The clock output is low to start. So the XOR puts out a low signal. Next, the clock output goes high, and so does the XOR’s. This causes the ‘175 to load the priming on the first two latches. This clock signal to the XOR now stays high until the power is turned off. The external step pulse may be sending signals or not, but we are not listening to it yet. Next, the latch signal goes low, and its inverted signal to the AND goes high. The AND will now oscillate in tandem with the external step pulse. As the AND oscillates, the XOR sees as its input 11 10 11 10 11 10 … and therefore sends out 0 1 0 1 0 1 … to the ‘175. If you have paid attention, you will see that a high to low transition on the external step pulse now causes the stepper to advance. If this is not desired, this step pulse signal could be put through an inverter.

In the schematic, the same capacitor value has been used for each 555. The variation in timing comes from the choice of resistor. Using the same resistors values shown but smaller capacitors caused the circuit to cease working. Either we exceeded the speed possible from the 555, or the speed of the ‘175. You may feel free to use larger capacitors in your own circuit, but nothing too much smaller.

So we have explained the whole circuit, except for the purpose of the DG403. The DG403 is an analog switch. More explicitly, it is a pair of two single throw double pole switches. More to follow, but first consider this: the firing sequence on the switches is 1 2 3 4 ... To go in reverse, it should be apparent the cycle is 4 3 2 1 … Look:

4 Forward: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 Reverse: 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 This requires a good deal of switching (1  4, 2  3, 3  2, 4  1). Now look at this: Forward: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 Reverse: 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 All we have done is to shift the reverse sequence one position to the right. This makes no difference to the motor—its only concern is the sequence, not the starting point. So this simplifies things. Now all we need is (2  4, 4  2).

Now back to the DG403. Each switch contained inside has two inputs (which we will tie together) and two outputs. Another switch control lets the input signal pass to one or the other of the outputs, but never neither or both. To make both switches work in tandem, we tie their switch controls together. To the input of the first we send 2, with its first and second outputs going to 4 and 2, respectively. To the input of the second, we send 4, with its first and second outputs going to 2 and 4 respectively. With a control signal of 0V, the second output of each switch is used, so 2  2 and 4  4. With a control signal of 5V, the first output of each switch is used, so 2  4 and 4  2. We now control the direction of our motor with one signal. Much more information on the DG403 can be found from its datasheet, as well as a rather explanatory schematic of the switching function. Here the signal sent through the analog switch DG403 is a 0V/5V digital signal, but as the name implies, it could switch any sort of analog signal. Quite a useful little chip.

The last thing to comment on is the stepper motor itself. If not broken or lost, there should be a blue stepper motor in the laboratory, a SLO-SYN SS25-1001. This is a five wire motor with no wiring diagram! Well, I have done the work for you: Wire Use _ White Power Green Coil 1 Green/White Coil 2 Red Coil 3 Red/White Coil 4 Perhaps another stepper motor is to be used. For full details on deciphering the wires look in Easy Step’n. A simple primer is this: for a five wire motor, the wire that connects to all the rest is the power (check with a DVM or continuity tester). Besides this, there should be two pairs of connected wires. These are coil pairs 1 – 2 and 3 – 4. The correct labeling of these can be found by connecting to the finished driver circuit and changing connections until the motors spins properly. For six and eight wire motors,

5 refer to Easy Step’n but know that they can all be connected to the driver we will build here, merely by tying certain wires together to again achieve a count of five.

Now your work begins: 1) As always, we will achieve the full circuit by building and testing it in parts. First we will concern ourselves with the ‘175. Run power and ground to a ‘175 and tie all the outputs to the next input, as indicated above. Also tie the outputs, in order, to the digital logic LED’s at the right of your board.

2) Run two ~500 resistors from the dip switches on your board to ground. From the high side of these connect to reset* and D1 (input to latch 1). Run the TTL signal from the frequency generator to the clock.

3) With the generator set to its lowest frequency and reset* held high, turn on the power. All the LED’s will probably light. Flip the reset* switch off and on to clear them. Now send the signal to D1. Recall this is also tied to latch 4’s output, so you will see LED 4 light. Now slowly increase the frequency until LED 1 is lit. Turn off the input to D1. You should now be able to increase the frequency as much as you want and see the light cycle from 1 … 4. (Sometimes when you move the frequency range select switch, the ‘175 loses the current state is was in. I have not tracked this down, but it may be due to a power spike or a short frequency burst that is too quick for the chip to follow. If this happens, just re-prime the circuit).

4) Repeat step 3, but this time let LED 1 and 2 both light before you remove the input to D1. This is our high motor torque case. Again, these two lights should cycle as shown in the table on page 3.

5) Repeat step 3 yet again, but this time run a signal to D1 and D2. Now LED 3 and 4 will light since latch 3 output is tied to D2. Let only one clock pulse through and then remove this signal. The result should be the same as in step 4.

6) Next, we will add in the transistors. I again choose the 2N2222, but any NPN transistor should work, since it is just a switching function here. Recall, the cycle sequence is linear on the switches, so the output of latch 1 (Q1) goes to the base of transistor 1, Q2 to transistor 2, and so on. I used 33 resistors from emitter to ground to help limit current and keep transistor running temperature down. If a stepper motor is not available, you may tie the positive side of 4 LED’s to 5V, and have the negative side run through a 200-600 resistor and then into the collector of one of the transistors. This is a fine way to check for broken transistors. If the motor is available, you may now wire it in, remember to run coil 2 to transistor 3 and coil 3 to transistor 2. When using the motor, do not forget the inductive kick back diodes. The IN4004 or IN5817 should work fine.

7) Verify that the motor turns properly, and that this is based on the driving clock frequency. If you wish, you can wire a debounced switch to the ‘175’s clock instead of the frequency generator. Be aware at high frequencies, the motor will cease to turn. But

6 that is okay. The stepper motor is used for fine control more than for speed. More than 5V can be ran to the diodes and motor power wire for greater torque, but be advised this will probably overheat the transistors in this configuration. 5V is enough for our purposes here.

8) Now we wish to add directional control. Make sure you have the datasheet with the pinout of the DG403 handy. Tie the switch control pins together and to another dip switch (equipped with a resistor). This will be our direction switch. Each switch control pin controls two lower switches, only one which is closed at any time. Tie the inputs on these together (for both sets). To these inputs, bring Q2 and Q4. Look at both normally closed outputs. Tie the one with input Q2 to transistor 2, and the one with input Q4 to transistor 4. Tie the normally open outputs in the reverse of this.

9) Verify the operation of the DG403, namely that the motor will reverse direction properly, without hanging up. Question: why do reverse the signals between the ‘175 and transistors, and not between the transistors and coils? The current would be too much for the DG403

This part is optional, based on the instructor’s wishes and the time you have available.

10) Now we will add the automatic primer circuit. I recommend using a larger capacitor value than specified, since this will aid in debugging. When it works, then you can use smaller ones.

11) First, just set up the 3 555 times with their resistors and capacitors. Now, two at a time, look at their output on the oscilloscope. You will need to turn on and off the power to the board to see anything.

12) Now, run the resetting 555 (with the 20k resistor) through a NOT and to reset* on the ‘175. Turn on power and verify it does clear the ‘175. Make sure it has gone high by trying to finish the priming manually.

13) Finally, the last two 555’s are to be connected. It really only works properly when all the connections are made, so we can’t break it down into smaller steps. You can put the scope to the output of the XOR to check see if the priming clock pulse is getting through properly, and you can check the output from the NAND and XOR to see if the external clock signal (function generator) is getting through properly once the priming is completed. As always, verify the chips you are using work properly standing alone (test apart from the circuit), and if one is bad toss it away.

NOTE: Since you have gotten this far and have more to do, or if you have gotten stuck and need to move on, this stepper motor driver has been solder together and put in a metal housing for your benefit (Ask your TA for access). This will allow you to clear your breadboard for the next part (and this may also be used in Phys 215 if needed for an experiment). This board is the exact circuit shown above, and therefore sometimes suffers loss of signal when used with the breadboard’s function generator, as described

7 above. Power off, wait, and power on to reset it. If more than 5V is needed to run a motor, be very careful with this board since the only way to do that is increase the supply to every circuit element. This may either blow the IC’s (which are easily replaced, just pop one out and put another in) or the transistors (harder to replace – must be soldered).

Part B Shaft Encoder We can count the number of pulses we send to the motor, and keeping track of the direction also, we should know the shaft position at any given time. But say this shaft is turning a second shaft through means of a linkage that may introduce some slippage. We would want to be able to detect the radial position of this second shaft independently. A shaft encoder is a device that lets us do just this. The innards of this use a form of emitter/detector with a disk painted with evenly spaced spokes. A light signal is emitted, bounced off the disk, and detected. Let us say there are 100 black lines on the disk. From one black line to the next (where light is absorbed), we know the shaft has moved 1/100 of 360.

The shaft encoder we have available for you is the Bournes

Part C Emitter/Decoder + free design project

8