FreqPeriod Library

Hi,

I've been using the FreqPeriod library, found here: http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/

Overall, it's wonderful, but every once in a while I get an erroneous measurement, off by several hundred Hz.

I'm using Timer2 to run interrupts at around 22kHz, so I'm wondering if that might be impacting the accuracy. I'm not smart enough to know for sure. Has anyone used this lib and dealt with similar issues?

Thanks,

  • Greg

To rephrase the question, is there a better solution to generate a frequency from an input pulse?

You first have to define what a "frequency" is to you.
This very fine library uses a hardware feature (available in most microcontrollers) called "compare and capture".

It does very precisely determine the time between two rising edges of a signal.

When you encounter deviations here, it is most likely (but not necessarily) your signal, or an intermediate glitch.

When you want to read something like a "frequency" it is best to use an moving average, even better with a suppression of run-away values.

Well, I'm sure it's not my input signal, so what kinds of intermediate glitches might be occurring?

I've been thinking about the moving-average idea, will probably try that out.

Tried with a moving average, still getting large jumps in period duration.

We might learn something if you had a statistic from your "fixed" signal:

  • What values occur?
  • How often?

Og course these measurement must be done without averaging...

Here's a sample list of period measurements:

Check out that 89122.00 right in the middle. That's the kind of thing causing problems.

23608.00
23522.00
23553.00
23513.00
23543.00
23583.00
23485.00
23645.00
23628.00
23592.00
89122.00
23449.00
23579.00
23584.00
23615.00
23582.00
23477.00
23576.00
23524.00
23531.00
23561.00
23541.00
23552.00
23546.00
23586.00
23517.00
23565.00
23484.00
23599.00
23562.00
23549.00
23580.00
23570.00
23559.00
23586.00
23560.00
23587.00
23540.00
23508.00
23554.00
23572.00
23538.00
23602.00
23592.00
23554.00
23617.00
23575.00
23577.00
23527.00
23618.00
23540.00
23589.00
23548.00
23558.00
23527.00
23491.00
23603.00
23501.00
23642.00
23559.00
23643.00
23584.00
23457.00
23599.00
23583.00
23565.00
23560.00
23487.00
23585.00
23528.00
23576.00
23572.00
23580.00
23596.00
23542.00
23615.00
23494.00