Share this

Briefly describe the method of using STM32 timers to control the counting of a quadrature encoder.

2026-04-06 04:12:30 · · #1

As shown in the figure, each TIMER of STM32 has a quadrature encoder input interface. TI1 and TI2 are filtered by input and edge detection to generate TI1FP1 and TI2FP2, which are connected to the encoder module. By configuring the encoder's working mode, the encoder can be used for forward/reverse counting.

As shown in the diagram, the encoder uses both phases A and B, but I only need to count the TI1 signal (first row). I just discovered this error; counting both signals resulted in more than 100 pulses per revolution of the code disk (for a 100-line photoelectric code disk). The encoder's operation can be easily calculated by comparing the two signal levels using the STM32 encoder module.

Below is the code that I have successfully debugged:

Another noteworthy issue is that the STM32's timers are 16-bit, meaning they can only count up to 65535. There are two methods to address this: one is to use a chained approach with two timers to extend the 16-bit count to 32-bit, and the other is to enable the timer's overflow interrupt, where each interrupt represents the encoder rotating a specific angle.

For example, if the encoder has 400 lines, set the ARR register to 400. Each overflow interruption represents one revolution of the motor, and so on.

Furthermore, the detection of input pulses is similar, except that the STM32 uses a dedicated external trigger module, as marked in the purple box in Figure 1. The encoder module is likely an upgrade of this module. Below is the configuration code:

Read next

CATDOLL 146CM Ya TPE (Customer Photos)

Height: 146cm A-cup Weight: 26kg Shoulder Width: 32cm Bust/Waist/Hip: 64/54/74cm Oral Depth: 3-5cm Vaginal Depth: 3-15c...

Articles 2026-02-22