
51
8210C–AVR–09/11
Atmel AVR XMEGA D
Figure 5-4.
Quadrature signals from a rotary encoder.
shows typical quadrature signals from a rotary encoder. The signals QDPH0 and
QDPH90 are the two quadrature signals. When QDPH90 leads QDPH0, the rotation is defined
as positive or forward. When QDPH0 leads QDPH90, the rotation is defined as negative or
reverse. The concatenation of the two phase signals is called the quadrature state or the phase
state.
In order to know the absolute rotary displacement, a third index signal (QDINDX) can be used.
This gives an indication once per revolution.
5.7.2
QDEC Setup
For a full QDEC setup, the following is required:
• Thw or three I/O port pins for quadrature signal input
• Two event system channels for quadrature decoding
• One timer/counter for up, down, and optional index count
The following procedure should be used for QDEC setup:
1.
Choose two successive pins on a port as QDEC phase inputs.
2.
Set the pin direction for QDPH0 and QDPH90 as input.
3.
Set the pin configuration for QDPH0 and QDPH90 to low level sense.
4.
Select the QDPH0 pin as a multiplexer input for an event channel, n.
5.
Enable quadrature decoding and digital filtering in the event channel.
6.
Optional:
a.
Set up a QDEC index (QINDX).
b.
Select a third pin for QINDX input.
c.
Set the pin direction for QINDX as input.
d.
Set the pin configuration for QINDX to sense both edges.
e.
Select QINDX as a multiplexer input for event channel n+1
f.
Set the quadrature index enable bit in event channel n+1.
g.
Select the index recognition mode for event channel n+1.
7.
Set quadrature decoding as the event action for a timer/counter.
8.
Select event channel n as the event source for the timer/counter.
00
10
11
01
QDPH0
QDPH90
QDINDX
Forward Direction
Backward
Direction
01
11
10
00
1 cycle / 4 states
QDPH0
QDPH90
QDINDX