AnsweredAssumed Answered

32-bit Timer out of two 16-bit

Question asked by obid.matic on Jul 22, 2015
Latest reply on Jul 23, 2015 by Uwe Bonnes
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.