Home | Contact | Projects | Post Mortem | Publications | Pictures | Private | Blog


Reciprocal Frequency Meter


Software:V1.2
git:n/a yet
Board:Circuit
License:GPL V2
Discussion:On mikrocontroller.net (German)

There are a few frequency meter implementations available for Atmel's microcontroller series, but I haven't come across a reasonable reciprocal frequency counter implementation, let alone one without extra hardware. Thus I created one running on an ATtiny2313, ATmega8 and up, or ATmega48 and up with a usable frequency range of 0Hz..10MHz (when running at 20MHz), sub-Hz resolution, and 2.5ppm relative accuracy or better.

The operating principle of a reciprocal frequency meter like this is as follows: The software counts the number of system clocks and falling edges of the input signal for the sampling period. It makes sure that counting is started at a falling edge, and stopped after the sampling period at a falling edge as well. Due to this the sampling period may be extended for low frequency signals.

After counting has stopped, two numbers are available: n_CLK (number of system clocks of frequency f_CPU) and n_EVT (number of input events). The frequency results then as
   f = n_EVT * f_CPU / n_CLK
In order to get sub-Hz resolution, this has to be calculated in fixpoint arithmetics. This easily exceeds the range of 32bit arithmetics, thus 64 bit arithmetics are required, which need special handling to fit into the tiny flash of the ATtinys.

Calculating the accuracy of the implementation is tricky, see the accompanying README for it.