Part Info:
Mechanical Encoders | Digi-Key / 3315C-1-006-ND | $2.59 each |
We have the part the corresponds to the diagram on the left. Terminal "C" is common to both "A" and "B". Let's consider just A and C for a moment (B and C will be identical). Internally, the encoder can be thought of as a switch between A and C that closes 6 times per revolution. The degrees over which it is closed is exactly the same amount as open. In otherwords, the output is a square wave with a 50% duty cycle (when considering state graphed against degrees). In otherwords still, consider that the A channel is divided into twelve 30 degree segments. Each segment alternates between switch-closed and switch-open. So there are six pulses, but there will be a transition every 30 degrees.
Channel B is exactly the same, but the transitions are offset half the width of a pulse, or 15 degrees of rotation (see diagram above). So, using both channels, there is a transition every 15 degrees, increasing the counts per revolution (CPR) to 24. Furthermore, because of this offset, you can tell what direction the encoder is turning by which rising edges (or falling), A or B) come first.
To interface the encoder to the Handy Board, connect it between the sensor port and ground, following the same directions and diagram in the Handy Board manual as if you were attaching a regular switch.
On the software side, the easiest thing to do is use the Handy Board Shaft Encoder Libraries, available here. These take advantage of the inturrupt features of the 68HC11 Microcontroller to monitor the encoders in the background while your program operates. Be sure to read the documentation and use the specified sensor ports.
Lastly, easiest is not ideal. The HB Shaft Encoder Libs don't support two channel encoders which means you can use one channel, but you'll only get half the resolution. These libraries could be rewritten to use two channel encoders. There might be other clever alternatives also.