Adding an Encoder to Your Gearmotor

From Mech
Revision as of 12:42, 3 January 2007 by Lynch (talk | contribs)
Jump to navigationJump to 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.

Instead of making an encoder, you could buy an incremental optical encoder from US Digital for about $20.

You can use your battery pack and a 7805 voltage regulator to get a 5V supply for this exercise.

  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.
  3. We could send the two pulse trains from the LS7183 to an up-down binary counter that increments with an edge (rising or falling) on one line and decrements with an edge on the other. See the datasheet, for example. Instead, let's just display the output of the LS7183 using two LED's. Use one LED for each of the signal outputs of the LS7183, so each LED turns on and off as its signal pulses low and high. Many LED's require about 20 mA to be visible and bright, so choose a resistor that will give you the right amount of current through the LED. Keep in mind that the LS7183, like many logic chips, does not source or sink sufficient current to light an LED, so you will need some kind of "buffer" to increase the current. Two possibilities are the DS2003 Open Collector Inverter and the ULQ2003A Open Collector Inverter.

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.