Difference between revisions of "Adding an Encoder to Your Gearmotor"

From Mech
Jump to navigationJump to search
Line 1: Line 1:
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.
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 **
<b>Optical Encoder</b>


Instead of making an encoder, as discussed below, you could buy an incremental optical encoder from [http://www.usdigital.com/ US Digital] for about $20. The [http://www.usdigital.com/products/e4p/ 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!)
Instead of making an encoder, as discussed below, you could buy an incremental optical encoder from [http://www.usdigital.com/ US Digital] for about $20. The [http://www.usdigital.com/products/e4p/ 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!)

Revision as of 17:32, 22 January 2007

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!)

You can use your battery pack and a 7805 voltage regulator to get a 5V supply for this exercise. (Note - 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.)

  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.