Datasheet
2010 Microchip Technology Inc. DS39616D-page 163
PIC18F2331/2431/4331/4431
17.2.2 QEI MODES
Position measurement resolution depends on how
often the Position Counter register, POSCNT, is
incremented. There are two QEI Update modes to
measure the rotor’s position: QEI x2 and QEI x4.
TABLE 17-4: QEI MODES
17.2.2.1 QEI x2 Update Mode
QEI x2 Update mode is selected by setting the QEI
Mode Select bits (QEIM<2:0>) to ‘001’ or ‘010’. In this
mode, the QEI logic detects every edge on the QEA
input only. Every rising and falling edge on the QEA
signal clocks the position counter.
The position counter can be reset by either an input on
the INDX pin (QEIM<2:0> = 001), or by a period match,
even when the POSCNT register pair equals MAXCNT
(QEIM<2:0> = 010).
17.2.2.2 QEI x4 Update Mode
QEI x4 Update mode provides for a finer resolution of
the rotor position, since the counter increments or
decrements more frequently for each QEA/QEB input
pulse pair than in QEI x2 mode. This mode is selected
by setting the QEI mode select bits to ‘101’ or ‘110’. In
QEI x4, the phase measurement is made on the rising
and the falling edges of both QEA and QEB inputs. The
position counter is clocked on every QEA and QEB
edge.
Like QEI x2 mode, the position counter can be reset by
an input on the pin (QEIM<2:0> = 101), or by the period
match event (QEIM<2:0> = 010).
17.2.3 QEI OPERATION
The Position Counter register pair (POSCNTH:
POSCNTL) acts as an integrator, whose value is propor-
tional to the position of the sensor rotor that corresponds
to the number of active edges detected. POSCNT can
either increment or decrement, depending on a number
of selectable factors which are decoded by the QEI logic
block. These include the Count mode selected, the
phase relationship of QEA to QEB (“lead/lag”), the
direction of rotation and if a Reset event occurs. The
logic is detailed in the sections that follow.
17.2.3.1 Edge and Phase Detect
In the first step, the active edges of QEA and QEB are
detected, and the phase relationship between them is
determined. The position counter is changed based on
the selected QEI mode.
In QEI x2 Update mode, the position counter
increments or decrements on every QEA edge based
on the phase relationship of the QEA and QEB signals.
In QEI x4 Update mode, the position counter
increments or decrements on every QEA and QEB
edge based on the phase relationship of the QEA and
QEB signals. For example, if QEA leads QEB, the
position counter is incremented by ‘1’. If QEB lags
QEA, the position counter is decremented by ‘1’.
17.2.3.2 Direction of Count
The QEI control logic generates a signal that sets the
UP/DOWN
bit (QEICON<5>); this, in turn, determines
the direction of the count. When QEA leads QEB,
UP/DOWN is set (= 1) and the position counter
increments on every active edge. When QEA lags
QEB, UP/DOWN is cleared and the position counter
decrements on every active edge.
TABLE 17-5: DIRECTION OF ROTATION
QEIM<2:0>
Mode/
Reset
Description
000 — QEI disabled.
(1)
001 x2 update/
index pulse
Two clocks per QEA
pulse. INDX resets
POSCNT.
010 x2 update/
period
match
Two clocks per QEA pulse.
POSCNT is reset by the
period match (MAXCNT).
011 — Unused.
100 — Unused.
101 x4 update/
index pulse
Four clocks per QEA and
QEB pulse pair.
INDX resets POSCNT.
110 x4 update/
period
match
Four clocks per QEA and
QEB pulse pair.
POSCNT is reset by the
period match (MAXCNT).
111 — Unused.
Note 1: QEI module is disabled. The position
counter and the velocity measurement
functions are fully disabled in this mode.
Current
Signal
Detected
Previous Signal
Detected
Pos.
Cntrl.
(1)
Rising Falling
QEA QEB QEA QEB
QEA Rising x INC
xDEC
QEA Falling x DEC
xINC
QEB Rising x INC
xDEC
QEB Falling x INC
xDEC
Note 1: When UP/DOWN
= 1, the position counter
is incremented. When UP/DOWN
= 0, the
position counter is decremented.