Quadrature Encoder Counter (QEP)
Purpose
Counts edges generated by a quadrature encoder
Library
STM32
Description
The Quadrature Encoder Counter counts edges which are generated from a quadrature encoder. The \(A\), \(B\), and \(I\) outputs of the encoder are connected to the input GPIOs of the microcontroller.
The block output c represents the current counter value, port i represents the index pulse, and port ic outputs the latched counter value from the previous index pulse.
The counter counts up or down depending on the sequence of input pulses. The counter value will increase when the direction of rotation results in the rising edge of \(B\) following the rising edge of \(A\) and will decrease in the opposite direction of rotation. For each rising and falling edge of the \(A\) and \(B\) encoder output signals the counter will increment or decrement. Therefore the Maximum counter value must match the number of line pairs of the encoder multiplied by the number of counted edges per line pair minus 1. As an example, an encoder with 1024 line pairs would have a maximum count of 4095 since the QEP module counts all edges of \(A\) and \(B\) (4 edges per line pair).
Once the counter reaches the value specified in parameter Maximum counter value it is reset to zero on the next detected edge in the positive direction. Vice versa, the counter is set to Maximum counter value when it is zero and detects an edge in the negative direction. If connected and configured by the Mode parameter, the counter is also reset when the rising edge of the index input is detected.
Parameters
Main
- TIM unit
Selects the timer unit used.
- Maximum counter value
The counter is reset to zero when it has reached the Maximum counter value and detects an input edge in the positive direction. The counter is set to the Maximum counter value when it is zero and detects an input edge in the negative direction.
- Mode
Selects whether the counter should be reset by a positive pulse on the index input or on overflow only. Three different modes are available:
Free running: The counter is reset on overflow only. Output ports i and ic are not available, and the output \(I\) of the encoder is not required.Free running with index capture: The counter is reset on overflow only. In addition, the index pulse is captured and the latched counter value from the previous index pulse is made available at the output port ic.Reset by index pulse: The counter is reset by a positive pulse on the index input.
Channel A
- Port
Selects the port of the channel A input.
- Pin
Configures the pin of the channel A input.
- Polarity
Selects if the
Rising edgeorFalling edgedefines the start of a pulse.- Input characteristic
Specifies whether an internal pull-up or pull-down resistor is connected to the digital input. If
high impedanceis selected no internal pull resistor is connected.
Channel B
- Port
Selects the port of the channel B input.
- Pin
Configures the pin of the channel B input.
- Polarity
Selects if the
Rising edgeorFalling edgedefines the start of a pulse.- Input characteristic
Specifies whether an internal pull-up or pull-down resistor is connected to the digital input. If
high impedanceis selected no internal pull resistor is connected.
Index
- Port
Selects the port of the index pulse input.
- Pin
Configures the pin of the index pulse input.
- Polarity
Selects if the
Rising edgeorFalling edgedefines the start of an index pulse.- Input characteristic
Specifies whether an internal pull-up or pull-down resistor is connected to the digital input. If
high impedanceis selected no internal pull resistor is connected.