2022-01-21 04:30 AM
Hello everyone,
I'm using 4 timers of a stm32 nucleo board to count the increments in encoder mode. 2 timers are 16 bit and 2 others are 32 bit.
The increments can be between -1,000,000,000 and +1,000,000,000.
With 32 bit timers, there is no problem because they can be -2147483648 to +2147483647.
But 16-bit timers can be -32768 to +32767 so several times an overflow occurs.
It is impossible to find where the overflows occur to simply add each time -32768 or +32767 and solve the problem. So I need to somehow convert the 16-bit timer to 32 bit.
is it possible? Do you have any idea?
Thank you so much for your help.
2022-01-21 04:48 AM
In software, sample the encoder timer's value regularly - more often than half of period at maximum input frequency - and calculate the number of overflows from that.
There's no bulletproof way to do it in hardware.
You may want to consider using a cheap small STM32 as a slave to add more 32-bit timers.
JW
2022-01-21 07:44 AM
Dear @Nmo.1 ,
I think this AN2592 "Achieving 32-bit timer resolution with software expansion for STM32Cube and Standard Peripheral Library" can help you.
SofLit