Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Input sensors for position change

Quadrature Encoders
Quadrature Encoders typically consist of a spoked pickup wheel attached to the mechanical
input. The spokes pass through a pair of
optical interruption sensors consisting of:

one led and one light sensor each or


one led and two light sensors or
one light sensor and two modulated leds

which generate a pair of phase shifted output streams. This is called a Quadrature Encoder
because they have 2 pulses spaced 90 degrees apart. The direction of movement is
deturmined by noticing whether the A or B signal stream is leading.

| Reading point
V
___ ___ ___ ___ ___ ___ ___ _
Stream A|___| |___| |___| |___| |___| |___| |___| |___|
___ ___ ___ ___ ___ ___ ___ ___
Stream B__| |___| |___| |___| |___| |___| |___| |___|

Counter-clockwise <--|--> Clockwise

(A;B) Current:
Previous ||(0;0) (0;1) (1;0) (1;1)
|+----------------------
(0;0) | NC CW cCW Err NC=No change
(0;1) | cCW NC Err CW CW=Clockwise
(1;0) | CW Err NC cCW cCW=Counter-clockwise
(1;1) | Err cCW CW NC Err=Error (ignored)

Morgans Reglerteknik, mrt at iname.com says:

To decode Quadrature Encoders: Generally,

Get the two phase bits


Together with the two bits from the last read form a 4-bit word
Use this for a 16 entry goto table
The table will contain 4 each of gotos for count up, count down, no change
(glitch) and error (both phase changed, probably overspeed).

Paul B. Webster says:

If you presume that it will occur due to slow processing, then you must allow that you have
missed the actual direction of that move. In this case it is best to update the "previous" state
with the current one, and wait for the next move. This would most likely happen when the
encoder is moving rapidly and the next move will at least be registered as the correct
direction. For a mouse, this is perfectly reasonable as absolute accuracy is not required in
comparison to smooth movement.
If OTOH, you presume that a simultaneous change in state on both is a noise (debounce)
phenomenon, than it is handled by *not* updating the previous state; when a reasonable
"new" state is eventually detected, the movement direction is determined accordingly. This
means however that if the encoder really *did* move two steps between polling, the next step
will be indicated in the *wrong* direction.

You might also like