●●●●
BY THOMAS KIBALO
ENHANCED USER INTERFACE
FOR THE 16-BIT MICRO
NTER
This is the seventh in a series of articles describing the capabilities for the 16-Bit
Micro Experimenter (Experimenter for short) and its associated hardware
features (see previous articles in even months, starting with Dec ‘09). In this
article, we will look at enhancing the Experimenter user interface with a rotary
encoder using the PIC24F timer peripheral set and its interrupt capability. The
timer peripheral is a significant component in the PIC24F peripheral arsenal.
With the PIC24F timer, we can count external pulses or optionally count the
internal 16 MHz PIC24F CPU clock as a timing source. All timer operations
occur in hardware with a minimal need for software intervention — a really
powerful capability to incorporate into Experimenter applications.
There is a lot of ground to cover here, but no worries, because we’ll supply code examples and schematics,
as well as a mini-kit to help with these examples. As stated
in earlier articles, all software will be kept to general level
functional calls. However, some basic familiarity with C
language syntax is required, as we will be incorporating
some of the ‘C’ code libraries introduced in earlier Nuts &
Volts articles that discussed
the 16-bit Experimenter.
output signal is the result of the opening and closing of
switches internal to the rotary encoder as its turns. To
insure that digital signals are generated, the switch outputs
are tied through pull-up resistors to + 3. 3 VDC, and the
common is connected to ground. If a switch is open, a
high voltage is generated; if closed, zero or low voltage is
generated.
Understanding the
Rotary Encoder
Let’s look at the rotary
encoder and understand its
operation. Most modern
home and car stereos use
mechanical rotary encoders
for volume. They are also used
in a variety of home
appliances — like ovens — for
temperature and timing
settings. The rotary encoder is
different from a potentiometer
in that the encoder can
undergo full rotation without
limits. It is also different from a
potentiometer in that we have
two outputs: A and B. Each
32 December 2010
Now let’s imagine that
the encoder internal shaft has
two cams: one for A and one
for B. Each cam has 12
“detent” or protrusions along
its circumference that provide
360 degrees/12 or 30 degree
resolution with each detent.
As a cam turns, each detent
opens or closes a switch to
generate a waveform (see
Figure 2). The A and B cams
are placed 90 degrees from
each other. Because of this
placement, as the encoder
shaft turns, the A and B
output waveforms are 90
degrees out of phase (again
look at Figure 2).
The microcontroller
■ FIGURE 1. The Experimenter
with rotary encoder.