- Discrete LEDs
- Dot/Bar LEDs
- Matrix LEDs
- 7-Seg LEDs
- LCDs
- Switches
- KBDs
- Sensors
- Motors
- Analog
-
Comm
- Serial -- Software
- Serial -- Hardware
- RS-232 via the MAX3232
- I2C -- EEPROM
- I2C -- DS1307 Real Time Clock
- 1-Wire -- DS18B20, Powered, Single-Drop
- 1-Wire -- DS18B20, Powered, Multi-Drop
- 1-Wire -- DS18B20, Parasitic, Multi-Drop
- TI Link Protocol -- Calculator Demo
- Infrared Communication
- MIDI -- Output Demo
- MIDI -- Input Demo
- MIDI to Analog Synth
- Miscellaneous
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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment