1
\$\begingroup\$

This question is mainly a query for an advice.

I am trying to implement a frequency meter on STM32F4. Up to this point I have a working ADC converter with DMA and a timer which checks for the current voltage value and catches a zero crossing (with margin) and counts the counter.

Now, what is the best way hot to determine the actual frequency? In sense of - shall I rely on timer clk speed or should I use RTC?

Or is there a better way how to determine the frequency?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

I would use a zero-crossing detector circuit (google - tons of them, very easy) and then (depending on the frequency you're trying to measure) either use an input-capture timer/counter to automate the counting, simply reading & resetting the count at given measurement intervals (much lower CPU load), or use the input pulses to gate a fast counter (to count a LOW frequency) and calculate the inverse (for low frequencies it's easier to measure the time taken per pulse rather than pulses accumulated per time period).

Either should leave your CPU with very little hard work to do.

\$\endgroup\$
1
\$\begingroup\$

In order to measure a frequency, you normally use a much higher or much lower and well known frequency.

If you want to measure a frequency (much) lower than your system oscillator, you could do the following: Execute an interrupt on a rising or falling edge of your signal and use it to start the counter. On the next interrupt you read the value of the timer.

The other way round: On each rising edge of your (now much faster) signal increment your counter. After some time (~100 -> ~10000 signal cycles) a timer reads and resets the counter.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ An approach that gives the best of both worlds is to have an input both increment a counter and latch the value of a high-speed free-running counter; periodically take a snapshot of both the former counter and the latter latch. This could allow fast display updates and good accuracy with signals over a wide frequency range. A 60.001Hz signal might sometimes be reported as five pulses in 83,333us, sometimes as five pulses in 83,334us, sometimes as six in 100,000us, and sometimes as six in 99,999us, but all scenarios it could be could be displayed as 60.001Hz (precise to five sig figs). \$\endgroup\$
    – supercat
    Commented Mar 19, 2013 at 18:15
  • \$\begingroup\$ Hmm, interesting Idea. Thanks for that input. I will try this the next occasion. \$\endgroup\$
    – Botnic
    Commented Mar 19, 2013 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.