cancel
Showing results for 
Search instead for 
Did you mean: 

32-bit Timer out of two 16-bit

matic
Associate III
Posted on July 22, 2015 at 23:24

Hi. I have another question... 🙂

I use STM32F103c8 MCU and it has only 16-bit timers. I need a 32-bit timer with high resolution (72 MHz). I made it with connecting two 16-bit timers (one as master, second as slave). Master is counting with 72 MHz, while slave increments on a master's overflow. Both of them are in (IC) Input Capture mode. I latch their CNT registers with a pulse on one GPIO pin, which is connected on both IC channels. Than I read both CCR registers and make a 32-bit value. That works perfectly, if I reduce master's frequency a lot (with prescaler). But with full speed, some strange things occasionally happen around master's overflow... 

If I latch them when master is just above the overflow (few counts over 0), slave still don't update his value by 1 (its value is still old - for 1 smaller than it should be). Thus, when I combine both values, I get for about 2^16 smaller value than I should.

Now I solve this problem by software. When I need a value, I make two consecutive readings. If the second one is just for a little bit larger than the first one, then I'm sure that the second reading is true. It works...

But, I would like to ask, if anyone had the same experience when combining two 16-bit timers into 32-bit? Am I doing something wrong here?

Thank you in advance.

#timer #stm32f103
4 REPLIES 4
raptorhal2
Lead
Posted on July 23, 2015 at 16:31

Since two capture register reads are required, there is a finite time in between when a master overflow can occur. The workaround is probably the answer.

Cheers, Hal

Posted on July 23, 2015 at 19:09

16-bit timers, and poor clocking strategies have long frustrated me in the STM32 designs.

Do you have a compelling reason to be using an STM32F1 part over one of the newer versions of the part? One that has 32-bit timers, although on the slower APB1 bus.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on July 23, 2015 at 20:03

Because it is cheaper than newer MCUs and it has smaller footprint. These are the main reasons.

Uwe Bonnes
Principal II
Posted on July 23, 2015 at 23:34

Even some STM32F0 parts have one 32-bit timer.