cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder CNT reset

Paolo Chiantore
Associate II
Posted on November 08, 2017 at 09:15

On STM32F777 I have configured TIM2 as encoder counter with a period of 8192  (i.e. the CNT will wrap at 8192, see ARR register).

Everything works as expected until I reset the CNT by setting TIM2->CNT=0. In this case the first time CNT doesn't wrap to the expected period value of 8192, it will wrap at (8192 - CNTvalueAtReset): if CNT is 1192 and I reset it, the first time CNT will wrap at 7000 instead than 8192.

After this first time everything works as expected.

Is there some register I can set when resetting the counter to avoid this behaviour? 

#stm32-encoder
1 ACCEPTED SOLUTION

Accepted Solutions
Paolo Chiantore
Associate II
Posted on November 08, 2017 at 10:09

I observe it through a tcp connection.

I just discovered it was my fault: I was resetting CNT in two different places in my code and I completely forgot about one of them!

When resetting it only in one place everything works as expected.

Sorry and thank you for your interest.

View solution in original post

2 REPLIES 2
Posted on November 08, 2017 at 09:31

How do you observe CNT and the wraparound?

JW

Paolo Chiantore
Associate II
Posted on November 08, 2017 at 10:09

I observe it through a tcp connection.

I just discovered it was my fault: I was resetting CNT in two different places in my code and I completely forgot about one of them!

When resetting it only in one place everything works as expected.

Sorry and thank you for your interest.