ELM ELM406P

ELM406
Rotary Decoder - 3 wire 2x Interface
Description
Features
The ELM406 is an 8 pin integrated circuit that is
used to convert the output from a rotary encoder into
three signals (chip select, clock 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 ELM406, as this is all
performed within the integrated circuit. After
debouncing the encoder signals, the ELM406
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 ELM406 provides 2x decoding of a rotary
encoder signal. If your application requires 4x
decoding, please see the ELM407 (it is identical to
the ELM406 in every respect, except that it provides
4x decoding).
•
•
•
•
•
•
•
•
Low power CMOS design
Wide supply range – 2.0 to 5.5 volts
Complete debouncing of the encoder inputs
No external filtering needed
2x decoding
Can generate a write sequence
Startup delay timer
High current drive outputs
Connection Diagram
PDIP and SOIC
(top view)
Applications
•
•
•
•
Digital audio potentiometer controls
Variable voltage or temperature circuits
Positioning controls
Tuning circuits
VDD
1
8
VSS
A
2
7
CS
B
3
6
Clk
Write
Enable
4
5
U/D
Block Diagram
VDD
A
2
VDD
ELM406DSA
Direction
Decoding
B
3
Rotary
Encoder
Debounce
Circuit
Output
Logic
Debounce
Circuit
Write
Enable
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
7
CS
6
Clk
5
U/D
4
1 of 9
ELM406
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 Clk output when
the rising edge of the CS output occurs. If pin 4 is
high, the Clk output will be held high during the CS
transition, which generates an EEPROM write for
many digital potentiometer chips.
U/D (pin 5)
This ‘Up/Down’ output changes with the direction of
encoder rotation. For a clockwise movement (the A
input appears first, followed by the B), this output will
be set high before the CS output (pin 7) is switched
low. For counter-clockwise movement, the output will
be set low prior to the Chip Select going low. The
U/D output does not change state when the CS and
Clk pulsing is complete - it remains at the level it was
just prior to the CS going low.
Clk (pin 6)
A low ‘Clock’ pulse is output at this pin 200 µsec after
the CS output has gone low. The pulse is normally
400 µsec wide, and is typically used to cause the
controlled device to change state based on the level
at the U/D pin. If pin 4 is at a high level, the Clk pulse
will be reduced in length to 200 µsec, and the CS
pulse width extended to 600 µsec, so that Clk is at a
high level while the CS output transitions from the
active low level to the quiescent high level. This will
cause the setting to be written to memory for many
devices.
CS (pin 7)
This output provides a ‘Chip Select’, or enable
function. As the rotary encoder shaft rotates, a series
of clock pulses are generated at pin 6. Just prior to
these pulses appearing, the CS output will go low,
and stay at that level for 400 µsec. This changes a
little if the Write Enable input is at a high level. 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.
ELM406DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
2 of 9
ELM406
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............................... ELM406P
150 mil SOIC..................................... ELM406SM
Outline Diagrams
The diagrams at the right show the two package
styles that the ELM406 is available in. The first shows
our ELM406P product, which is an ELM406 in a
300 mil DIP package. This is a standard through hole
type dual inline package. The ELM406SM is our
surface mount version of the ELM406. 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
ELM406P
2.54
6.35
max
10.92
ELM406SM
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.
ELM406DSA
Note: all dimensions shown are in mm.
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
3 of 9
ELM406
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 ELM406 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
ELM406DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
4 of 9
ELM406
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 ELM406 uses electronic means to
remove the bounce.
Figure 2. Actual Rotary Encoder waveform
ELM406DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
5 of 9
ELM406
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 ELM406 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 ELM406 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
ELM406 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
ELM406DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
6 of 9
ELM406
Output Waveforms
Once the ELM406 has some bounce-free signals
to work with, it can generate outputs based on them.
The logic to decode the motion of an encoder
shaft 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 ELM406 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 ELM406 is a series of pulses, as
shown in Figure 4 (a representative pulse has been
enlarged and is shown in Figure 5). When the encoder
is moving in a clockwise direction, the pulses will be
generated with the U/D output at a high level, while a
counter-clockwise rotation of the shaft results in pulses
generated with the U/D output at a low level. The
direction assumes that the encoder is a standard one,
where the ‘A’ signal leads the ‘B’ for a clockwise
rotation. Note that an Up output is always a result of a
change in A followed by a change in B, while a Down
output results from a change in B followed by a
change in A.
Figure 4 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 ELM406 must see a change on one of
the rotary encoder inputs followed by a change on the
other input.
Figure 6 on the next page shows how the output
sequence changes when the Write Enable input (pin 4)
is at a high level. In this case, the Clk output returns
high after only 200 µsec, and the CS output remains
low for an extra 200 µsec. This will result in a write of
the wiper position to non-volatile memory for many ICs
(for example, the ON Semiconductor CAT5112, or the
Intersil X9C102).
Note that the ELM406 uses what is known as 2x
decoding of the signals. This means that for each
A ‘wiggle’ or vibration causes B to change,
but A does not, so the pulse is ignored
A Input
B Input
debounce
delay
CS
Clk
U/D
Figure 4. Output signals (pin 4 = 0V)
ELM406DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
7 of 9
ELM406
Output Waveforms (continued)
motion of the shaft between the detents, when the ‘A’
and ‘B’ outputs go through one complete cycle, there
will be two output signals. The other type of decoder
that is very common is the 4x decoder, as used by the
ELM407. We do not currently offer a product for 1x
decoding - if you require that, you will need to use the
ELM401 and decode the signal with your own logic.
CS
CS
Clk
400 µsec
U/D
this will be low for a
counter-clockwise motion
Figure 5. Up or Clockwise Output
Clk
200 µsec
U/D
Figure 6. Up Output, with Write Enabled
Design Considerations
There are a few details to consider when using the
ELM406 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
ELM406 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Ω
pullup, and TTL thresholds, this means capacitor
ELM406DSA
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 ELM406 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 and the Clk outputs are active low, this may cause
a problem if your controlled circuit is ready too fast. If
you require that pins 6 and 7 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 ELM406 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
8 of 9
ELM406
Example Application
Figure 7 below shows how the ELM406 might be
used with a digital potentiometer (in this case, a Dallas
Semiconductor/Maxim DS1804).
Pullup resistors of 10 KΩ are used with the rotary
encoder to provide voltages for the A and B inputs.
Power for the ELM406 and the DS1804 has been
supplied from a common source (it must be between
2.7V and 5.5V for the DS1804), and a small capacitor
has been added to ensure that the supply is filtered.
The DS1804 data sheet does not recommend any
value for the size of this capacitor (0.01 µF is fine for
the ELM406), but some digital potentiometers do
specify a larger capacitor size (typically 0.1 µF). You
may need to increase the size of the capacitor,
depending on the chip that you use.
The ELM406 output lines are directly connected to
the DS1804 inputs, but we have added two 10 kΩ
pullup resistors to ensure that the Chip Select and the
Clock lines rise to the VDD level as quickly as possible
after power up. This may not be absolutely necessary
(as the 3 wire port of the DS1804 is not active for
about 50 msec after powerup), but it does not hurt to
add it – other chips may not have such a start up
timer.
That’s about all there is to using the ELM406.
Connect pullup resistors to your rotary encoder,
connect the encoder signals to the ELM406, then
connect the ELM406 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Ω
VDD
10 KΩ
1
8
2
7
3
6
1
4
5
2
10 KΩ
VDD
A
B
rotary
encoder
3
C
4
8
DS
1804
H
7
L
W
6
5
Figure 7. Connecting the ELM406 to an DS1804
ELM406DSA
Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
9 of 9