46.1 Overview
The Quadrature Encoder Interface (QEI) module provides the interface to incremental encoders for obtaining mechanical position data and velocity. Quadrature encoders, also known as incremental encoders or optical encoders, detect position and speed of rotating motion systems. Quadrature encoders enable closed-loop control of motor control applications, such as Switched Reluctance (SR) and AC Induction Motors (ACIM).
A typical quadrature encoder includes a slotted wheel attached to the shaft of the motor and an emitter/detector module that senses the slots in the wheel. Typically, four output channels, Phase A (QEAx), Phase B (QEBx) and Index (INDXx) and Home (HOME) provide information on the movement of the motor shaft, including distance and direction.
The two channels, Phase A (QEA) and Phase B (QEB), are typically 90º out of phase with respect to each other. The Phase A and Phase B channels have a unique relationship. If Phase A leads Phase B, the direction of the motor is deemed positive or forward. If Phase A lags Phase B, the direction of the motor is deemed negative or reverse. The Index pulse occurs once per mechanical revolution and is used as a reference to indicate an absolute position. The following figure illustrates the Quadrature Encoder Interface signals. On power-up, the machine needs to orient itself to a known reference point. The QEIIC register is loaded with the “home” position. The position counter is configured via the PIMOD bits to initialize the position counter on the first index event following a home event. The home and index events occur and the contents of the QEIIC register are loaded into the Position Counter (POSCNT) register.
The quadrature signals from the encoder can have four unique states
(‘01
’, ‘00
’,
‘10
’ and ‘11
’) that
reflect the relationship between QEA and QEB. The following figure illustrates these states
for one count cycle. The order of the states get reversed when the direction of travel
changes.
The quadrature decoder increments or decrements the 32-bit up/down Position Counter (POSxCNT) for each Change-of-State (COS). The counter increments when QEA leads QEB and decrements when QEB leads QEA.

The following table shows the truth table that describes how the quadrature signals are decoded.
Current Quadrature State | Previous Quadrature State | Action | ||
---|---|---|---|---|
QEA | QEB | QEA | QEB | |
1 | 1 | 1 | 1 | No count or direction change |
1 | 1 | 1 | 0 | Count up |
1 | 1 | 0 | 1 | Count down |
1 | 1 | 0 | 0 | Invalid state change, ignore |
1 | 0 | 1 | 1 | Count down |
1 | 0 | 1 | 0 | No count or direction change |
1 | 0 | 0 | 1 | Invalid state change, ignore |
1 | 0 | 0 | 0 | Count up |
0 | 1 | 1 | 1 | Count up |
0 | 1 | 1 | 0 | Invalid state change, ignore |
0 | 1 | 0 | 1 | No count or direction change |
0 | 1 | 0 | 0 | Count down |
0 | 0 | 1 | 1 | Invalid state change, ignore |
0 | 0 | 1 | 0 | Count down |
0 | 0 | 0 | 1 | Count up |
0 | 0 | 0 | 0 | No count or direction change |
Block Diagram illustrates the simplified block diagram of the QEI module. The QEI module consists of decoder logic to interpret the Phase A (QEA) and Phase B (QEB) signals, and an Up/Down Counter to accumulate the count. The counter pulses are generated when the quadrature state changes. The count direction information must be maintained in a register until a direction change is detected. The module also includes digital noise filters, which condition the input signal.