16 Quadrature Encoder Interface (QEI)

Note:
  1. This data sheet summarizes the features of the dsPIC33CK512MPT608 family of devices. It is not intended to be a comprehensive resource. For more information, refer to the “Quadrature Encoder Interface (QEI)” (www.microchip.com/DS70000601) in the “dsPIC33/PIC24 Family Reference Manual.”
  2. Some registers and associated bits described in this section may not be available on all devices. Refer to Memory Organization in this data sheet for device-specific register and bit information.

The Quadrature Encoder Interface (QEI) module provides the interface to incremental encoders for obtaining mechanical position data. 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, three output channels, Phase A (QEAx), Phase B (QEBx) and Index (INDXx), provide information on the movement of the motor shaft, including distance and direction.

The two channels, Phase A (QEAx) and Phase B (QEBx), are typically 90 degrees 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. Figure 16-1 illustrates the Quadrature Encoder Interface signals.

The Quadrature signals from the encoder can have four unique states (‘01’, ‘00’, ‘10’ and ‘11’) that reflect the relationship between QEAx and QEBx. Figure 16-1 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 x Counter (POSxCNTH/L) registers for each Change-of-State (COS). The counter increments when QEAx leads QEBx and decrements when QEBx leads QEAx. Table 16-1 shows an overview of the QEI module.

Figure 16-1. Quadrature Encoder Interface Signals

Table 16-1 shows the truth table that describes how the Quadrature signals are decoded.

Table 16-1. Truth Table for Quadrature Encoder
Current Quadrature StatePrevious Quadrature StateAction
QAQBQAQB
1111No count or direction change
1110Count up
1101Count down
1100Invalid state change; ignore
1011Count down
1010No count or direction change
1001Invalid state change; ignore
1000Count up
0111Count up
0110Invalid state change; ignore
0101No count or direction change
0100Count down
0011Invalid state change; ignore
0010Count down
0001Count up
0000No count or direction change

Figure 16-2 illustrates the simplified block diagram of the QEI module. The QEI module consists of decoder logic to interpret the Phase A (QEAx) and Phase B (QEBx) 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.

The QEI module consists of the following major features:

  • Four Input Pins: Two Phase Signals, an Index Pulse and a Home Pulse
  • Programmable Digital Noise Filters on Inputs
  • Quadrature Decoder providing Counter Pulses and Count Direction
  • Count Direction Status
  • 4x Count Resolution
  • Index (INDXx) Pulse to Reset the Position Counter
  • General Purpose 32-Bit Timer/Counter mode
  • Interrupts generated by QEI or Counter Events
  • 32-Bit Velocity Counter
  • 32-Bit Position Counter
  • 32-Bit Index Pulse Counter
  • 32-Bit Interval Timer
  • 32-Bit Position Initialization/Capture Register
  • 32-Bit Compare Less Than and Greater Than Registers
  • External Up/Down Count mode
  • External Gated Count mode
  • External Gated Timer mode
  • Interval Timer mode

Figure 16-2. Quadrature Encoder Interface (QEI) Module Block Diagram
Note:
  1. These registers map to the same memory location.