How to use the Encoders

 

Part Info:

Mechanical Encoders Digi-Key / 3315C-1-006-ND $2.59 each

 

Notes on operation:

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.

Mounting:

1) Get a 2 x 1 stud LEGO Technic brick (Technic = with hole in side). Drill the hole with a 15/64" bit (in tool box).

2) Plastic encoder should thread nicely into the enlarged hole. Take care to thread part in straight (hard to do).

3) Glue or press a LEGO gear onto the shaft. The 16 tooth gear fits tight, no glue, other gears will need glue. Hot glue is NOT great for this application. Use an epoxy or super glue. Take care not to get epoxy in the base of the encoder, it will never work again.

4) REALLY IMPORTANT: after soldering the wires onto the encoder and shrinking the heat-shrink, reinforce the wires at the encoder base with hot glue. The most common encoder failure last year was leads breaking of the encoder bases.