cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 timer granularity ?

mehmet.karakaya
Associate III
Posted on May 21, 2014 at 21:28

hello forum ,

I want count the time between the rising and falling edges of a 100 Khz square wave 

with STM32F4 timer 

now as the timer counts with 168 Mhz ,

what can be the minimum count between the two very close measurements ?

is it 1 count or more than 1 count ?

I mean what is the granularity of timer capture function ?

thank you 

#stm32f4-timer
3 REPLIES 3
Posted on May 21, 2014 at 21:37

The counters for a 168 MHz F4 part are 84 MHz for APB1 counters, and 168 MHz for APB2 counters. You can make it more course with a prescaler.

The latching will resolve to a single tick, your issue will be interrupting, and how that saturates the processor.

You can count pulses over a period. You could also use PWM Input mode where the HW captures the measurements, and you get to them when you can. Perhaps you could capture with DMA?
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mehmet.karakaya
Associate III
Posted on May 21, 2014 at 22:19

hello clive , you gave me an idea 

If I have 100 KHz   %50 duty square wave with 168 Mhz counting timer 

I can measure 840 count 

if the frequency drops to 95 Khz I measure 884 count

there is 44 count inbetween

this precision is unsufficient for me

my question

If I take 100 following measurements 

and average to a floating variable 

can I get something like 870,46 ( this is mathematicaly true value ) for example for 96.5 Khz ?

does the ''nature'' help me here to increase the precision ?

this is my best english hope you understand what I mean 

thank you

PS. I dont need interrupt at every mesaurement - I only need the above capture value every milisecond for example

Posted on May 21, 2014 at 23:03

You have a resolution of ~6 ns (168 MHz) or ~12 ns (84 MHz)

You could use a prescaler on the Input Capture, and time over say 8 periods

  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV8;

freq = (168000000 * 😎 / ticks

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..