7 years, 9 months ago.

Measure high Frequency using Timer2

Hello All,

I am using Nucleo F446ZE and trying to measure the Frequency on a PA1 Pin which is connected to a wafer form generator .

I am using TIM2 with external clock setting. So I see the counter value changes as per input from waveform generator (just checking counter value in main loop).

How do I get the TIM2 counter data out to measure the input frequency?

Thanks, Invn

1 Answer

7 years, 9 months ago.

Wait x time in your main loop (or use a Ticker interrupt). Check the count before you started waiting, check it afterwards, The difference between those two is the number of periods. Frequency is the number of periods divided by the time you waited.

my sys clock is at 180Mhz so I belive main loop frequency should be 180Mhz .

To check count value i will have to use hal_getCounter function (HAl based) so it may take several clock cycle , not sure how to check the time x for hal_getCounter . if I add delay on top .. might loose few more clock cycles and wont be accurate enough. Is there any other way I can get this counter data out like using DMA or ISR that barely adds additional overheads

posted by Test Test 07 Mar 2017

Sure there are ways with DMA and other timers. But if you simply measure long enough, the overhead per cycle is very small. If you have a high frequency, it is better to not measure the time between two occurances, or just measure for example 1ms long how counts happen. If you measure 1ms, and your overhead if 500ns, then you have a 0.05% error.

posted by Erik - 07 Mar 2017