Adding an Encoder to Your Gearmotor

From Mech
Jump to: navigation, search

Before doing this exercise, read about how a Rotary Encoder works. In this exercise, you will modify your gearmotor to add an encoder that allows you to keep track of how far your motor has rotated. This encoder is based on the use of magnets and Hall effect sensors instead of a codewheel with lines and optical emitter/detector pairs, but the idea is the same.

Optical Encoder

Instead of making an encoder, as discussed below, you could buy an incremental optical encoder from US Digital for about $20. The E4P encoder has a codewheel that just pushes on to any rotating shaft of the right diameter. Choose your encoder by the size of the shaft, whether it needs to pass all the way through the encoder or not, and the number of counts per revolution you want. You can easily burn out the encoder if you hook it up wrong, so be careful!)

Magnetic Encoder

You can use your battery pack and a 7805 voltage regulator to get a 5V supply for this exercise. Note that a 7805 needs about 1.5 volts of "headroom." That is, to provide a regulated 5.00V output, you need to provide it with about 6.5V or more. If you provide it ~6V, it will give you ~4.5V. Fortunately most logic devices will work on 4.5V. Typically they claim to work from 4.5V-5.5V, but in fact they will work on 6.0V too. So you have lots of options.

  1. Modify your gearmotor to add an encoder based on a ring magnet and Hall effect sensors. See Adding a rotation encoder to a gearmotor. Use your oscilloscope to see the 0-5V pulses from the two Hall sensors as you rotate the motor (either manually or by applying voltage). How many pulses do you see for each rotation of the output shaft of the gearmotor? Make sure you understand why. If the pulses do not look clean, you can use a 74HC14 Hex inverting Schmitt trigger to clean up the pulses. This chip uses hysteresis so that small voltage jitters on the input pulses (from the Hall sensors) are not seen in the digital outputs.

  2. Now we're going to change those two pulse trains (the A and B channels of the encoder) into one signal that pulses when the encoder rotates clockwise and another signal that pulses when the encoder rotates counterclockwise. The chip that does this for us is the LS7183. Hook up the LS7183 as shown on the datasheet. Choose Rbias according to the maximum frequency of encoder pulses you might ever see (based on the fastest the motor can rotate). Try setting the chip in x1, x2, and x4 counting modes, and look at the two pulse streams coming out of the LS7183. Make sure you understand the 3 different counting modes, and that the pulse streams you see make sense. You can see the pulses on a scope. They are SHORT pulses though, so if you use them to make an LED flash you won't see it.

  3. You can trigger a 555 timer chip on the low-going short pulses, and set the RC time constant such that the 555's output stays high for 1/100 second. The 555 is capable of supplying large currents. That's plenty of time and current for a nice flash from an LED.

  4. We could send the two pulse trains from the LS7183 to an up-down binary counter. An up-down conuter has one input that increments the count on a rising or falling edge, and another input that decrements. See the LS7183 datasheet, for examples.

  5. The LS7184 differs from the LS7183: instead of having pulse outputs for "count up" and "count down", it has one output for "count" and another for "up vs. down.". The latter stays high or low indefinately (until the direction of rotation changes), so that's a signal you can visualize with an LED.

    LEDs are dim at 1mA and bright at 20mA. Choose a resistor that will give you the right amount of current through the LED. Keep in mind that the LS7183/4 will only source or sink about 1mA, so you may want some kind of buffer to provide a larger current. Logic chips vary widely in their output current capabilities. Often inverters are used in this buffering role.



You can use the H-bridge control circuit from your previous exercise to drive the motor at different speeds and see the motor speed represented by the frequency of the LED flashes. You can also turn the motor by hand.

Personal tools