by John Schimmel
December 6, 2005 related project - Ramps by Wlodek Koss, Tristan Perich, John Schimmel
A rotary encoder is used to measure rotation and provide a digital output. It looks just like a potentiometer but can spin freely in both directions. There are a few different types of encoders, some mechancial, some optical but all produce there output with a similar rotating pattern - this pattern is what gives encoders a bad name. The pattern involved gives the encoder a resolution, the Grayhill model above gives 128 steps per rotation. You can get encoders at places like jameco and digikey, I used the Grayhill Series 61R 5-Pin from Digikey, it was about $40.
The 61R has 5 Pins, another version the 61K has 4 pins they both operate the same way.
- 2 pins for digital output
- 1 pin for +5 volts
- 1 pin for common ground
How it works
This sensor report is not finished but great information is on Wikipedia
This image shows an encoder with 3 contact points (rings)
There are two contact points on the Grayhill encoder, 2^2 = 4 positions for the encoder to be in
Attached to the shaft of an encoder is a patterned disc. A mechancial encoder would look for a variation in several contact points as the shaft was turned, in smaller more "relative" encoders the spinning disc is a group of transparent radial lines like a bike wheel on a dark disc. As light shines through the radials a photodiode on the other side can detect angular movements.
The problem with encoders is that some contacts get to the next step before the other contacts on the ring. The problem is smoothed out with Gray code. Gray codeis a binary numeral system where two successive values differ in only one digit.
This code is from http://www.picbasic.co.uk/forum/showthread.php?t=778 The code is avoid the alignment problem by cutting the resolution in half. In our project, it was unnoticeable.