Welcome to 520 Motor repository
2.2 Timer captures encoder data
13. The timer captures the encoder data
13. The timer captures the encoder data 13.1. Experimental purpose 13.2. Configuration pin information 13.3. Analysis of the experimental flow chart 13.4. core code explanation 13.5. Hardware connection 13.6. Experimental effect
13.1. Experimental purpose
Use the timer encoder mode function of STM32 to capture the encoder data.
13.2. Configuration pin information
- Import the ioc file from the Motor project, name it Encoder, and then the related driver of serial port 1.
According to the schematic diagram, the two encoders of the four motors are respectively connected to channel 1 and channel 2 of timer 2 3 4 5. The motor M1 corresponds to the timer TIM2, M2 corresponds to TIM4, M3 corresponds to TIM5, and M4 corresponds to TIM3.

- Taking the timer TIM2 as an example, the setting methods for TIM3, TIM4, and TIM5 are the same. Select Combined Channels mode as Encoder Mode encoder mode.

- In the settings, change the Encoder Mode to Encoder Mode TI1 and TI2, set it to quadruple frequency, and other parameters are shown in the figure below.

The final chip configuration pins are shown in the figure below:
![image</div><!--]--><!--]--><div class=](http://www.yahboom.net/public/upload/upload-html/1668590099/./image-20220311154742986.png)