Page 1 of 1

Alternative frequency counter

Posted: Sun Feb 03, 2013 5:26 pm
by Jan Lichtenbelt
On an other place, there is given an very accurate frequency counter
http://www.matrixmultimedia.com/mmforum ... 49&t=10974
This is based on counting the input pulses for a special period (100µsec, 1 msec, up to 10 sec) by means of the Timer1 input of pin T1CKI.

An other possibility is to count a timer for one period of the input oscillating signal. I used the same Timer1, but instead of T1CKI input, now the Fosc internal clock. This is the same method as the auto baud rate detecting works, with the difference that the clock here is 64 times faster.

The Times1 counts up to 2 bytes. At overflow a second 2 bytes counter will be increased with 1 Together the result is an Ulong counter ( up to 2^32). With an oscillator of 19 600 800 Hz, up 218 seconds can be measured.

Please find a Flowcode program and the macro, which will gives the number of counts in [1/Fosc] units, with Fosc in [Hz].

I expected a high accuracy. But..... I found 19647121 counts for a 1 second oscillator signal, which is an error of -0.07%. At a baud rate of 38400 (or oscillator of 19 200 Hz) an error of 0.7% is found. At 100 kHz 189 counts were measured which is an error of -4%.

This error at higher frequencies is not clear for me. Who knows a solution?

With kind regards

Jan Lichtenbelt