Issue
152 March 2003
Using
Rotary Encoders as Input Devices
WORKING
EXAMPLES
Figure
2 is a diagram of a circuit that’s designed to interface
two rotary encoders and four switches to the host microcontroller
using a PCF8574. I’ve tried two different types of encoders,
each of which requires different program code. Both
types cost less than $5.
|

(Click
here to enlarge)
|
Figure
2—As you can see, with this circuit you can interface
two rotary encoders and up to four optional switches
to an AVR microcontroller. Although the microcontroller
isn’t shown, note the port lines that enable the
interface. |
The 24-position Bourns ECW1J-B24- BC0024 encoders are
smooth, quiet, and can be turned quickly. However, the
ones I received didn’t come with a nut, and it’s a Metric
M9 × 0.75 thread. Figure 1 shows the state of the switches
connected to terminals A and B. Note that the vertical
dashed lines represent the detent positions. The datasheets
for these encoders refer to them as both quadrature
output and Gray code output.
The
waveforms are identical to the quadrature output signals
that I’ve already described, and a complete 2-bit Gray
code sequence is sent out for each move from one detent
to the next. In addition, both the A and B channel switches
are open circuit when they’re at rest in any detent
position. A high output results when they’re as they
are in Figure 2. The microcontroller must constantly
check the two encoder output lines to see which of the
two Gray sequences occurs when the encoder is moved
either CW or CCW.
The
36-position Grayhill 25LB10-Q encoder doesn’t turn as
smoothly and is a bit noisier, but it comes with a nut—the
standard 3/8" nut used on analog potentiometers.
Its output is strictly a 2-bit Gray code. At each detent
position there is a unique Gray code available at the
outputs that repeats itself every four positions, as
shown in Table 1. If you were not able to use an interrupt-driven
method of reading the encoder, this type of output would
be somewhat easier to handle (in terms of response time)
than the Bourns encoder. The four general-purpose switches
shown in Figure 2 are connected to the upper four bits
of the PCF8574.