Gray Code Encoder


This exercise shows how to read a rotary Gray code encoder. The unit I'm using in the photo here came from Mouser Electronics twenty years for some project I never got around to building. It's made by CTS, so probably it or some close equivalent is still available. The encoder puts out a four-bit binary number in Gray code format, depending on the angle of the shaft. It doesn't have detents, so the rotation is smooth, like a potentiometer; I'm not so sure I like that, though.

The demonstration is straightforward. A Gray code number is read (off of Port A) and then displayed on the LEDs (on Port B). Additionally, a toggle switch lets you choose whether to see the selected number in Gray format or in pure binary format.


Observe that the encoder uses positive logic, so is driven by +5V and develops the output number across pull-down resistors.

The PIC Micro Pascal code is trivial. But if you're still learning the language, be sure to note how the Gray code to pure binary number translation is maintained in a constant array and accessed by indexing. Indexed arrays are a piece of cake in Pascal.

Click to get the source code.
Click to get the schematic PDF.

Next Project: Rotary Incremental Encoder

No comments:

Post a Comment