dsPIC33A Quadrature Encoder Interface (QEI) Peripheral
Overview
This page covers the dsPIC33A Quadrature Encoder Interface (QEI) module, which is used to read position and speed from incremental encoders in rotating systems. The QEI module has four input pins for two-phase signals (QEA and QEB), an index pulse, and a home pulse, all with digital noise filtering. It supports 4X quadrature counting, 32-bit position and velocity counters, and can reset the position counter with the index pulse.
The QEI can operate in several modes: Standard Quadrature mode (detecting direction and position from QEA and QEB), External Up/Down Count mode, External Gated Count mode, and Internal Timer mode. It also includes a velocity counter, index pulse counter, and interval timer for measuring slow speeds.
The module uses digital filters to reject noise on the input signals, ensuring reliable operation in noisy motor environments. The QEI generates a single interrupt with multiple sources, such as counter overflows, compare matches, and index or home events.
Typical applications include measuring the position, direction, and speed of motors or machines. The QEI decodes the encoder’s out-of-phase signals to provide accurate motion feedback for control systems.
Features
- The QEI module provides the interface to incremental encoders for obtaining mechanical position data
- Detects the position and speed of rotating motion systems
- Four input pins with the capability to filter the noise on its input: two phase signals, an index pulse, and a home pulse input
- Provides counter pulses and count direction
- 4X Quadrature Count mode
- Index pulse to reset the position counter
- 32-bit counters
- Velocity counter
- Position counter
- Index pulse counter
- Interval timer
- External counter modes:
- Up/Down Count mode
- Gated Count mode
- Gated Timer mode
- Interval Timer mode to count slow quadrature pulses
The quadrature signals from the encoder can have four unique states (‘01’, ‘00’, ‘10’ and ‘11’) that reflect the relationship between QEA and QEB. If QEA leads QEB, the direction of the motor is deemed positive or forward. If QEA lags QEB, the direction of the motor is considered negative or reverse. The index pulse occurs once per mechanical revolution and is used as a reference to indicate an absolute position.
Peripheral Architecture
Counter Modes
The QEI operates in four counter control modes:
- Quadrature mode
- External clock count with External Up/Down mode
- External clock count with External Gated mode
- Internal Timer mode
Quadrature Count Mode
- The inputs QEA and QEB are 90 degrees out of phase.
- QEA/EXTCNT and QEB/DIR/GATE inputs are decoded to generate count pulses and direction information to control the position counter and velocity counter. The counters count on every phase change.
- The index counter counts when a valid edge is detected on the index input.
External Count with External Up/Down Mode
- QEAx/EXTCNT input is considered as an external count signal.
- QEBx/DIR/GATE input provides the count direction information
- This is applicable for the position, velocity counter and index counter.
External Count with External Gated Mode
- QEAx/EXTCNT input provides the count signal
- QEB input gates the count signal from the QEA input for the position counter, and the velocity counter. GATEN bit in QEIxCON register controls the gate operation
GATEN | QEB | Counters |
---|---|---|
HIGH | HIGH | Counts QEA input |
HIGH | LOW | Gates QEA input |
LOW | X | Counts QEA input |
Internal Timer Mode
- This mode defines the QEI counters as general-purpose timers that use the internal peripheral clock.
- The QEB input gates the counting of the position and velocity counters.
- The INDEX input gates the counting of the index counter.
- The HOME input gates the counting of the interval counter.
Use Case of Counters
- Position counter
- Operated in different initialization modes and it can be reset or initialized with a known value depending on initialization mode
- Velocity counter
- Used to read the counter value at regular intervals
- Reading the counter causes it to reset
- Index counter
- Counts the number of index pulses
- Interval Timer
- Used to measure the time interval between each decoded quadrature count pulse when the motor operates at a very low speed
Digital Filter
- Digital noise filters:
- Are used to reject noise on the incoming index and quadrature phase signals, and
- Reject low-level noise and large, short-duration noise spikes that typically occur in motor systems.
- The filtered output signals can change only after an input level has the same value for three consecutive rising clock edges.
- The filter clock can be configured to determine the low-passband of the filter.
Interrupts
The QEI has only one interrupt. Different interrupt sources are:
- Position Counter overflow or underflow event
- Velocity Counter overflow or underflow event
- Position Counter initialization process complete
- Position Counter greater than or equal compare interrupt
- Position Counter less than or equal compare interrupt
- Index event interrupt
- Home event interrupt
Example Application
This example shows a rotating encoder.
- Rotation results in the generation of signals that are out of phase by 90 degrees.
- The signals are connected to QEI input pins.
- QEI decodes the signals to provide information on direction and the number of phase changes.