ELM ELM408

ELM408
Rotary Decoder - 2 wire Interface
Description
Features
The ELM408 is an 8 pin integrated circuit that is
used to convert the output from a rotary encoder into
two signals (chip select, and up/down) that can be
used to control various devices. The low power
CMOS technology used ensures that only a very
small current is required over the entire 2.0 to 5.5
volt operating range.
There is no need for external filtering or
debounce circuits with the ELM408, as this is all
performed within the integrated circuit. After
debouncing the encoder signals, the ELM408
determines the direction of shaft rotation, and then
generates the appropriate outputs. A write sequence
can also be generated if the Write Enable input is at
a high level when the outputs are generated.
The ELM408 provides both 2x and 4x decoding
of a rotary encoder signal. See the Output
Waveforms section for more information.
•
•
•
•
•
•
•
•
Low power CMOS design
Wide supply range – 2.0 to 5.5 volts
Complete debouncing of the encoder inputs
No external filtering needed
2x and 4x decoding
Can generate a write sequence
Startup delay timer
High current drive outputs
Connection Diagram
PDIP and SOIC
(top view)
VDD
1
8
VSS
A
2
7
CS
B
3
6
U/D
Write
Enable
4
5
4x/2x
Applications
•
•
•
•
Digital audio potentiometer controls
Variable voltage or temperature circuits
Positioning controls
Tuning circuits
Block Diagram
VDD
A
2
VDD
ELM408DSA
Direction
Decoding
B
3
Rotary
Encoder
Debounce
Circuit
Debounce
Circuit
Write
Enable
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
7
CS
6
U/D
Output
Logic
4
5
4x/2x
1 of 10
ELM408
Pin Descriptions
VDD (pin 1)
This pin is the positive supply pin, and should always
be the most positive point in the circuit. Internal
circuitry connected to this pin is used to provide
power on reset of the internal logic, so an external
reset signal is not required. Refer to the Electrical
Characteristics section for more information.
A (pin 2)
This input should be connected to what is normally
known as the ‘A’ signal from a rotary (quadrature)
encoder. The signal at this pin should lead (ie
change state before) the signal at pin 3 when the
device is being moved in a clockwise or up direction.
An external pullup resistor is required for the encoder
(a typical value is 10 KΩ), but no external capacitors
are needed (as the internal debounce circuitry
provides the filtering).
B (pin 3)
This input should be connected to what is normally
known as the ‘B’ signal from a rotary (quadrature)
encoder. The signal at this pin should lag behind (ie
change state after) the signal at pin 2 when the
device is being moved in a clockwise or up direction.
An external pullup resistor is required for the encoder
(a typical value is 10 KΩ), but no external capacitors
are needed (as the internal debounce circuitry
provides the filtering).
Write Enable (pin 4)
This input controls the state of the U/D output when
the rising edge of the CS output occurs. If pin 4 is
high, the U/D output will be set high during the CS
transition, which generates an EEPROM write for
many digital potentiometer chips.
4x/2x (pin 5)
This input controls how many sets of output pulses
are generated for each complete cycle of the A and
B inputs. If it is high, the CS and U/D outputs will
sequence 4 times for each (one for each of the four
transitions). If the input is low, only two sets of
pulses are generated.
Note that the ELM408 is not capable of generating
1x decoding (one set of output pulses). If your
application needs this, you may be able to use the
ELM401 and generate them in software.
U/D (pin 6)
The ‘Up/Down’ output serves multiple purposes
when used with a typical digital potentiometer. The
level that it is at when the CS output transitions low
typically sets the ‘mode’ (count up or count down),
while rising edges of the signal are usually used to
generate ‘count’ (ie clock) pulses. Finally, the level
that U/D is at when the CS output returns high will
often determine whether the potentiometer setting is
written to non-volatile memory or not.
CS (pin 7)
This output provides a ‘Chip Select’, or enable
function. It works with the U/D output to provide
various control functions. See the Output Waveforms
section (on page 7) for more information.
VSS (pin 8)
Circuit common is connected to this pin. This is the
most negative point in the circuit.
All rights reserved. Copyright 2011 Elm Electronics.
Every effort is made to verify the accuracy of information provided in this document, but no representation or warranty can be
given and no liability assumed by Elm Electronics with respect to the accuracy and/or use of any products or information
described in this document. Elm Electronics will not be responsible for any patent infringements arising from the use of these
products or information, and does not authorize or warrant the use of any Elm Electronics product in life support devices and/or
systems. Elm Electronics reserves the right to make changes to the device(s) described in this document in order to improve
reliability, function, or design.
ELM408DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
2 of 10
ELM408
Ordering Information
These integrated circuits are only available in either a 300 mil plastic DIP format, or in a 150 mil SOIC surface
mount type of package. To order, add the appropriate suffix to the part number:
300 mil Plastic DIP............................... ELM408P
150 mil SOIC..................................... ELM408SM
Outline Diagrams
The diagrams at the right show the two package
styles that the ELM408 is available in. The first shows
our ELM408P product, which is an ELM408 in a
300 mil DIP package. This is a standard through hole
type dual inline package. The ELM408SM is our
surface mount version of the ELM408. The device
package has a 3.90 mm wide body, and is commonly
called a 150 mil SOIC package.
The drawings shown here provide the basic
dimensions for these ICs only. Please refer to the
following Microchip Technology Inc. documentation for
more detailed information:
• Microchip Packaging Specification, document name
en012702.pdf (7.5MB). At the www.microchip.com
home page, click on Packaging Specifications, or go
to www.microchip.com/packaging
ELM408P
2.54
6.35
max
10.92
ELM408SM
1.27
3.90
6.00
• PIC12F508/509/16F505 Data Sheet, document
41236E.pdf (1.5 MB). At the www.microchip.com
home page, click on Data Sheets, then search for
12F508.
ELM408DSA
Note: all dimensions shown are in mm.
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
3 of 10
ELM408
Absolute Maximum Ratings
Storage Temperature....................... -65°C to +150°C
Ambient Temperature with
Voltage Applied..................................-40°C to +85°C
Voltage on VDD with respect to VSS............ 0 to +6.5V
Note:
Stresses beyond those listed here will likely
damage this device. These values are given as a
design guideline only. The ability to operate to
these levels is neither inferred nor recommended.
Voltage on any other pin with
respect to VSS........................... -0.3V to (VDD + 0.3V)
Electrical Characteristics
All values are for operation at 25°C and a 5V supply, unless otherwise noted. For further information, refer to note 1 below.
Characteristic
Minimum
Typical
Supply voltage, VDD
2.0
5.0
VDD rate of rise
0.05
Power on reset time
9
Average supply current, IDD
Maximum Units
5.5
Conditions
V
V/msec see note 2
18
30
msec
see note 3
0.6
1.1
mA
VDD = 5.0V
0.2
0.3
mA
VDD = 2.0V
VDD = 5.0V
10
mA
VOL = 0.25V
VDD = 3.0V
5.0
mA
VOL = 0.25V
VDD = 5.0V
2.5
mA
VOH = 4.75V
VDD = 3.0V
1.7
mA
VOH = 2.75V
Debounce period
5.5
msec
Startup time delay
50
msec
Internal timing variation
1
Output low current
(sink)
Output high current
(source)
4
%
see note 4
see note 5
Notes:
1. This integrated circuit is based on a Microchip Technology Inc. PIC12F5XX device. For more detailed
specifications, please refer to the Microchip documentation (www.microchip.com).
2. This spec must be met in order to ensure that a correct power on reset occurs. It is quite easily achieved
using most common types of supplies, but may be violated if one uses a slowly varying supply voltage, as
may be obtained through direct connection to solar cells, or some charge pump circuits.
3. The internal reset circuitry stops the ELM408 from doing anything during this period, so that the power
supplies and oscillators have time to stabilize. During this time, all pins behave like inputs.
4. Typical only - the actual period varies with the amount of noise present in the input signal.
5. All filtering, delay, and output timing is based on an internal master oscillator. The frequency of this oscillator
will vary with voltage and temperature. Values shown are typical maximums for 2.0V ≤ VDD ≤ 5.5V, and
temperatures of -40°C to +85°C
ELM408DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
4 of 10
ELM408
Rotary Encoders
A rotary encoder (sometimes referred to as a
quadrature encoder) is a device that produces digital
(on/off) outputs in response to rotary, or circular,
motion. It is often constructed such that it looks very
much like a potentiometer, or audio volume control
(see the picture of a typical device, at the right).
As the encoder shaft is turned, internal contacts
open and close, creating two waveforms that are
ideally separated in phase by 90 degrees (ie ‘in
quadrature’). Actually, you need to provide external
‘pullup’ resistors and a power supply to create these
waveforms, as the contacts themselves can not do
this. An ideal waveform from a rotary encoder would
look like this:
A
B
Figure 1. Quadrature Waveforms
Due to the 90 degree phase difference, when one
waveform changes, the other is always stable. By
noting the direction of the change and the level of the
other input at that time, you can determine the
direction of motion of the shaft.
Rotary encoders are not ideal, however. Due to
their construction, and variations in shaft speed, the
A typical rotary encoder
waveforms are not perfectly square with the 50% duty
cycles shown. Figure 2 shows a captured trace from a
real rotary encoder that is more representative of what
you will typically find. Note that the two ‘scope
channels (1 and 2) represent the encoder outputs A
and B, respectively. The ch 1 (A) waveform leads the
ch 2 (B) waveform, which usually means that the shaft
is turning in a clockwise direction.
The first rising edge of the channel 2 waveform
shows another problem that occurs with moving
mechanical contacts - multiple pulses due to bounce.
When two contacts meet, the moving one will tend to
bounce, like a ball does when it is dropped on the
floor. Each bounce results in an electrical connection
being made, then broken, which will look like multiple
inputs to a fast electronic circuit. Various mechanical
means are used to reduce the amount of bounce, but it
can never really be eliminated. The following section
discusses how the ELM408 uses electronic means to
remove the bounce.
Figure 2. Actual Rotary Encoder waveform
ELM408DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
5 of 10
ELM408
Debouncing Circuits
Any time that two metal surfaces meet, as they do
inside a rotary encoder, there will be a tendency for
the moving one to bounce, which causes the electrical
connection to make and break. The duration of this
bouncing action may be very short, but it is usually fast
enough to cause multiple counts to be recorded by
connected electronic circuits. As the number of
bounces can not be predicted, a means of removing
them is necessary. Circuits that remove the bounce
are usually called ‘debouncing’ circuits.
Many debouncing circuits employ a simple timer to
determine if an input is stable. This generally works
well if the two contacts meet and then remain still. With
a rotary encoder however, one of the contacts meets
the other then usually continues sliding over the
surface of the stationary contact. This will produce
noise while the contact is sliding, occasionally enough
to make it look like there are more inputs.
The ELM408 employs a two stage system to
remove the bounce and the sliding noise from the
input signal. A block diagram of the stages are shown
in figure 3. The first stage is a digital filter circuit that is
used to determine the average value of the waveform
over a time. If a long enough time is chosen, short
duration pulses will have little effect on the overall
average. If the time chosen is too long, however, the
circuit will be slow to respond, and may in fact average
out some legitimate inputs. Choosing the time period
(or time constant of the circuit) is thus very important in
determining how effective the filtering function will be.
We have found that with typical rotary encoder
specifications (usually 3.0 msec of bounce or noise,
maximum), the ELM408 debounce circuit works quite
well.
After the signal has been filtered, it is compared to
some reference levels, and the output of these
comparators are used to control a simple timer. The
timer is used to ensure that the output of the filter is
stable, and not just a momentary transient, while the
use of two comparator levels provides hysteresis, so
that some variation in the filter output can be tolerated.
Once the signals from the rotary encoder have
been debounced, they may be used by the direction
logic circuitry. The following section shows what the
ELM408 is able to produce from these signals.
rotary
encoder
input
3 msec
timer
to
output
logic
tc = 1.7 msec
filter
timer
Figure 3. Internal Debouncing Logic
ELM408DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
6 of 10
ELM408
Output Waveforms
Once the ELM408 has some bounce-free signals
to work with, it can generate outputs based on them.
The output sequences that the ELM408 generates
depends on the direction of shaft rotation, and on the
level at the Write Enable input (pin 4). The direction
logic always assumes that the encoder is a standard
one, where the ‘A’ signal leads the ‘B’ for a clockwise
or ‘up’ rotation. Note that the level at pin 5 only
determines when the sequences are output, and does
not affect the waveshape or timing of them.
Figures 4 to 7 below show the sequences that the
ELM408 can generate. In all cases, the basic time
interval is 200 µsec (if it does not seem apparent).
Figures 4 and 5 show the two types of sequences that
would occur if the Write Enable is low (ie disabled).
The level at the U/D output when the CS signal goes
low determines whether the the controlled device will
count up (level is high), or down (level is low) when the
U/D pin next goes from low to high.
For many digital potentiometers, the level at the
U/D pin when the CS output returns high determines
whether the current setting of the digital potentiometer
is to be stored in non-volatile memory or not. If the
ELM408’s Write Enable input is high, then the U/D
output will be held high during the transition, causing a
CS
CS
200
µsec
U/D
Figure 4. Up (Clockwise) with
Write Enable = Low
CS
U/D
U/D
200
µsec
Figure 5. Down (Counterclockwise) with
Write Enable = Low
CS
200
µsec
U/D
Figure 6. Up (Clockwise) with
Write Enable = High
ELM408DSA
write for many digital potentiometers. The resulting
waveforms are shown in Figures 6 and 7.
The logic to decode the motion of an encoder
shaft, and so decide when to provide output
sequences is not as simple as it would first appear.
Some authorities recommend simply monitoring an
input and when it changes, provide an output based on
the level of the other input. This does not always work,
as the encoder can output multiple signals from only
the ‘A’ or or only the ‘B’ contact if the shaft is moved
ever so slightly when at the detent or at the mid-point
position (between detents). Simply seeing one input
change is not sufficient to say that there is any
significant shaft rotation.
The ELM408 monitors both ‘A’ and ‘B’ transitions,
and determines the outputs based on the sequence in
which the transitions have occurred. This is a better
way to guarantee that the output signals are generated
properly. The internal logic also performs some selfchecking, and monitors for problems such as an output
pulse being initiated before the previous one had
completed, which might occur for some very fast
inputs (the second one will be ignored in this case).
The output of the ELM408 is a series of pulses, as
shown in Figures 8 and 9. The first figure shows 2x
400
µsec
Figure 7. Down (Counterclockwise) with
Write Enable = High
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
7 of 10
ELM408
Output Waveforms (continued)
decoding (there are two sets of output pulses for each
set of waveforms from the A and B inputs), while the
second (Figure 9) shows 4x decoding. In both cases,
the Write Enable input is high, but this has no bearing
on whether the sets of pulses are generated or not.
Figure 8 also shows what happens when the
rotary encoder shaft is ‘wiggled’, generating pulses on
only the A or only the B input - the logic detects this
and ignores them. In order for an output to be
generated, the ELM408 must see a change on one of
the rotary encoder inputs followed by a change on the
other input. The 4x decoding is a little different in this
respect. It will generate one pulse in anticipation of a
change of direction when the same input (A or B)
changes two times in a row. Figure 10 on the next
page shows how this typically works. If the logic to
detect and ignore multiple inputs such as this were not
in place, then multiple outputs could occur due to
vibration (as found in an automobile, or an industrial
setting), and the setting could ‘creep’ with time – even
though the shaft was not actually turned.
Generally, output pulses will occur in groups of
four (between each detent), so resistance values or
settings will repeat consistently as the shaft is rotated
in one direction and then in the other. Depending on
when the shaft changes direction, however, the pulses
may not be generated in groups of four. If your
application demands that the controlled variable must
repeat exactly as the shaft is turned in either direction,
you may prefer to use a 2x decoder setting.
A ‘wiggle’ or vibration causes B to change,
but A does not, so the pulse is ignored
A Input
B Input
CS
debounce
delay
direction changes
U/D
Figure 8. 2x Output signals (pin 5 = Low)
A Input
B Input
CS
direction changes
U/D
Figure 9. 4x Output signals (pin 5 = High)
ELM408DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
8 of 10
ELM408
Output Waveforms (continued)
Change in B (expecting a change in A)
causes the ELM408 to anticipate a change
in direction, and generate a Down output
A changes, meaning that
the shaft is now rotating,
and pulses can be output
Multiple pulses are ignored while
the ELM408 waits for a change at
the A input
The shaft direction
changes again
A Input
B Input
CS
U/D
Figure 10. 4x Decoding with the Input Chattering
Design Considerations
There are a few details to consider when using the
ELM408 to interface to a rotary encoder. The first is
the fact that the signals available from the encoder are
usually only dry contacts closing and opening. You will
need to provide pullup resistors for these signals in
order to use them in a circuit.
The size of the pullup resistor is chosen based on
the encoder specifications. The main concern is the
maximum current carrying capacity, which sets a lower
limit for the pullup resistance. An upper limit for the
resistance is set by the minimum current required for
contact wetting. If you do not provide enough current
through mechanical contacts when they are closed,
they will tend to go open with time. A maximum current
specification is usually in the range of 1 to 10 mA,
while the minimum wetting current would be in the
range of 1 mA. This means that with a 5V supply, a
pullup resistor of 5 to 10 KΩ is typically required.
The second concern is the use of capacitors on
the ‘A’ and ‘B’ signal lines. Many encoder circuits show
these as a way to provide some pre-filtering of the
signal. That is fine, as long as you realize that the
ELM408 inputs are CMOS and do not have Schmitt
trigger waveshaping. This means that you should keep
the rate of change of the input signal as high as
possible to avoid problems (we usually try to maintain
at least 1V/µsec). Typically, with a 5V supply, a 10 KΩ
ELM408DSA
pullup, and TTL thresholds, this means capacitor
values of no more than about 330 pF, while with a
2.0V supply, the limit would be about 100 pF.
One other issue to consider is that during the initial
circuit startup, there is a period (of about 20 msec)
when the ELM408 is being held in a reset state, and
the outputs are in a tristate condition. During this time,
the outputs will sit at the level they were at before
power up (0V) due to stray capacitance having
discharged through the protection diodes. Since the
CS is active low, this may cause a problem if your
controlled circuit is ready too fast. If you require that
pins 7 (and possibly pin 6) go to a high level as quickly
as possible, you may want to install pullup resistors (of
about 10 KΩ) on these pins to ensure that the voltage
rises quickly to VDD.
After the initial 20 msec period, the ELM408 sets
all pins to their quiescent levels, but does not change
any outputs for an additional 50 msec. This ensures
that the external circuits have had adequate time to
initialize, before being presented with signals to
process.
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
9 of 10
ELM408
Example Application
Figure 11 below shows one example of how the
ELM408 might be used with a digital potentiometer (in
this case, a Microchip Technology MCP4011).
Pullup resistors of 10 KΩ are used with the rotary
encoder to provide voltages for the A and B inputs of
the ELM408. Power is supplied from a common source
that we’ve simply labelled VDD (it should be between
2.7V and 5.5V for the MCP4011), and a small
capacitor has been added to ensure that the supply is
filtered. The MCP4011 data sheet recommends using
a 0.1 µF capacitor, so if this is physically very close to
the ELM408, you might be able to eliminate the
0.01 µF one
Pins 4 and 5 of the ELM408 have been connected
to circuit common (VSS) which means that the outputs
will appear as in Figures 4 and 5, and that we are
using 2x decoding. The ELM408 output lines are
directly connected to the MCP4011 inputs, and we
have added a 10 kΩ pullup resistor on the CS line to
ensure that the voltage rises as quickly as possible
after power on.
That’s about all there is to using the ELM408.
Connect pullup resistors to your rotary encoder,
connect the encoder signals to the ELM408, then
connect the ELM408 to the controlled circuit. Use a
common supply for all the devices, and add a small
bypass capacitor across the supply line. The controlled
devices can be digital pots, microprocessors, or almost
any circuit that will accept CMOS signals. Enjoy!
VDD
VDD
VDD
0.01µF
10 KΩ
10 KΩ
A
B
rotary
encoder
1
8
2
7
3
6
4
5
10 KΩ
C
VDD
0.1µF
1
2
3
4
8
MCP
4011
H
7
L
W
6
5
Figure 11. Connecting the ELM408 to a MCP4011
ELM408DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
10 of 10