AnsweredAssumed Answered

STM32F405 32-bit timer in encoder mode

Question asked by kubushyn.sergey on Mar 9, 2015
Latest reply on Mar 10, 2015 by kubushyn.sergey
I'm using STM32F405 TIM5 in encoder mode. As it is 32-bit timer I want to have the CNT register to hold actual position so I wouldn't need software assistance once it is setup, just read the counter.

However it looks like I can NOT initialize the counter to what I want.

When I'm writing e.g. 0x7ff to the CNT register it works. I can read 0x7ff back after writing, counter counts from that value when encoder moves.

The problem starts when I'm trying to initialize the counter with bigger value, more that 16 bits. When I'm writing e.g. 0x7fffffff into it (with 32-bit str instruction in assembly so that is not a C quirk) CNT reads back as 0 and encoder counts from zero. It looks like writing anything bigger than 0xffff (i.e. more than 16 bits) just resets the counter to zero.

Am I missing something? Are there some magic hoops I have to jump to initialize it to the value I need (bigger than 16 bit) or it is a Silicon Bug and I should kiss it goodbye?

Documentation is misleading -- ALL timer registers are shown as 16-bit but that nice picture with memory locations shows it as 32-bit. There is absolutely no mention of something special about initializing that timer CNT register. No mention of 16-bit only, no counter reset, nothing.

Can somebody shed a light on what's going on and how to work around it?