Issue
152 March 2003
Using
Rotary Encoders as Input Devices
by
Brian Millier
Numeric
keypads aren’t the only options for your electronic
instruments. You may save money by choosing the
often-overlooked rotary encoder. Here, you’ll learn
how rotary encoders work, how to connect them to
a micro, and how to read them with the right code.
Start
Quadrature Encoders Two-Bit
Binary Encoders
I Interrupt this Article
The PCF8574
Working Examples
Program Code
Sources and PDF
Rotary
encoders are probably the most reasonably priced option
for electronic instruments that require the frequent
adjustment of various parameters, particularly if the
instrument you’re using contains a microcontroller.
There are many cases when a numeric keypad is the only
way to go, but often a menu-driven display coupled with
buttons and one or more rotary encoders fits the bill.
Many microcontrollers have a multiplexed A/D converter
on board and can be interfaced to a conventional potentiometer
for data entry; however, to get a reasonable resolution,
you’d need a 10-turn potentiometer, which is much more
expensive. Suitable rotary encoders, which cost approximately
$5, are commonly rated for a 200,000-revolution lifetime.
In
this article, I’ll explain how some common rotary encoders
work. Also, I’ll show you how to connect them to a microcontroller
and give you the necessary program code to read them.
WHAT’S
YOUR FLAVOR?
Although
I haven’t completed an exhaustive study, I’ve basically
come across three different styles of rotary encoders:
quadrature output, 2-bit binary (or Gray) coded output,
and multi-bit binary (or Gray) coded output. The first
two types are considered relative-position types because
they report to you when they’ve changed position (and
in what direction), but don’t keep track of the absolute
angular position of the encoder shaft. They’re similar
in concept but different in the way that the detent
is defined. These devices lend themselves to your data
input, because shaft rotation can be used to increment
or decrement a displayed parameter while you watch a
constantly updated display parameter as feedback to
know when to stop turning.
The
third type generally provides a readout of the encoder
shaft’s absolute position, although its full range of
output codes may not correspond to a 360° rotation.
This type of rotary encoder is much more expensive,
and it’s often used to give the position feedback of
motorized servomechanisms. Because it doesn’t really
lend itself to user data input on an instrument panel,
I’ll stop there.