dsPIC30F Family Reference Manual
DS70063C-page 16-14 © 2004 Microchip Technology Inc.
16.5.3 Using Index to Reset Position Counter
When QEIM<0> = 0, the index pulse is utilized for resetting the position counter. For this mode
the position counter reset mechanism operates as follows: (See Figure 16-9 for related timing
details).
• The position count is reset each time an index pulse is received on the INDEX pin.
• If the encoder is travelling in the forward direction e.g., QEA leads QEB, POSCNT is reset
to ‘0’.
• If the encoder is travelling in the reverse direction e.g., QEB leads QEA, the value in the
MAXCNT register is loaded into POSCNT.
Figure 16-9: Reset by Index Mode-Up/Down Position Counter
16.5.3.1 Index Pulse Detection Criteria
Incremental encoders from different manufacturers use differing timing for the index pulse. The
index pulse may be aligned to any of the 4 quadrature states and may have a pulse width of
either a full cycle (4 quadrature states), a half cycle (2 quadrature states) or a quarter cycle
(1 quadrature state). Index pulses of a full cycle width or a half cycle width are normally termed
‘ungated’ and index pulses of a quarter cycle width are normally termed ‘gated’.
Regardless of the type of index pulse provided, the QEI maintains symmetry of the count as the
wheel reverses direction. This means the index pulse must reset the position counter at the
same relative quadrature state transition as the wheel rotates in the forward or reverse
direction.
For example, in Figure 16-9, the first index pulse is recognized and resets POSCNT as the
quadrature state changes from 4 to 1 as highlighted in the diagram. The QEI latches the state of
this transition. Any subsequent index pulse detection will use that state transition for the reset.
As the wheel reverses, the index pulse again occurs, however the reset of the position counter
cannot occur until the quadrature state changes from 1 to 4, again highlighted in the diagram.
00E3
POSCNT
QEA
QEB
UPDN
count_clock
00E4 00E5 00E6 0000 0001 0002 0003 0004 0005 0003 0002 0001 0000 00E6 00E5 00E4 00E0
POSCNT set to
0000
Recognize Index
POSCNT set to MAXCNT
Generate QEI Interrupt
Generate QEI Interrupt
00E3 00E2 00E10004
Recognize Index
Wheel
Reverses
INDX
1
2 3 4 1 2 3 4 1 2 2 1 4 3 2 1 4 3 2 1 4 3 2
Quadrature
State
Note: The QEI index logic ensures that the POSCNT register is always adjusted at the
same position relative to the index pulse, regardless of the direction of travel.