cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert 16-bit Timer to 32-bit?

Nmo.1
Associate III

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.

2 REPLIES 2

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

SofLit
ST Employee

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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.