cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder read error

SGian.1
Senior

Hi there!

i start to work with a rotary encoder, i configurate a timer 3:in this way 0693W00000Y93vJQAR.pngand i enable the interrupt .

for read the encoder inside the timer interrupt i write nuber= (TIM3->CNT)>>2;

so when i read the varible the first time i see 0 - 1- 2- 3 afther for three

time show 0 - 1 - 2 and the fourth time 0 - 1- 2- 3 and again 0-1-2 for three time and the fourth time the 0-1-2-3 . I don't understand why please someone can help me ? and someone try to read encoder with DMA ,and in which because i diden't find any tutorial in internet

Thank you soo much

Sergio

3 REPLIES 3

Which STM32?

Set ARR (Period) to 15.

Although I would leave it at its maximum (0xFFFF).

> try to read encoder with DMA

Why? I don't think you need that.

JW

SGian.1
Senior

thanks for the fast replace, please can you tell me why with 15 it works ?

With ARR=12 CNT can count from 0 to 12 and then wraps around to 0. If you observe nuber= (TIM3->CNT)>>2, then when CNT=0..3 --> number=0; CNT=4..7 --> number=1, CNT=8..11 --> number=2,. but number = 3 only when CNT=12, so the "slot" from which number = 3 results is 4x smaller than the other "slots".

JW