73
XMEGA A [MANUAL]
8077I–AVR–11/2012
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 (QINDX) can be used. This gives an indication
once per revolution.
6.7.2
QDEC Setup
For a full QDEC setup, the following is required:
Two 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:
1. Set up a QDEC index (QINDX).
2. Select a third pin for QINDX input.
3. Set the pin direction for QINDX as input.
4. Set the pin configuration for QINDX to sense both edges.
5. Select QINDX as a multiplexer input for event channel n+1
6. Set the quadrature index enable bit in event channel n.
7. Select the index recognition mode for event channel n.
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.
Set the period register of the timer/counter to ('line count' * 4 - 1), the line count of the quadrature encoder.
Enable the timer/counter without clock prescaling.
The angle of a quadrature encoder attached to QDPH0, QDPH90 (and QINDX) can now be read directly from the
timer/counter count register. If the count register is different from BOTTOM when the index is recognized, the
timer/counter error flag is set. Similarly, the error flag is set if the position counter passes BOTTOM without the
recognition of the index.