Arduino Frequency Counter



I have wanted to mess around with building a frequency counter with a PIC or Arduino. So tonight I wondered if I could pull something together in an hour or two.

Using my good friend "Google" I found some examples:
http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1231326297
http://www.swharden.com/blog/2011-03-14-frequency-counter-finished/

Based upon the parts on hand I decided to work with the first link listed above.


I grab the sample code from the website and dropped that into a new sketch. I think that magic is in library behind the code shown above. I have not spent much time digging through the library yet given that I am running out of time tonight.

That is showing 3.40774MHz or 3,407,740KHz

I used a small hand held signal generator (so I could test this at my desktop vs. at my workbench) and sure enough the Frequency Counter is outputting the raw unformatted value on the screen that largely matches what the signal generator says.

The range seems to run to about 8Mhz which is likely the 50%  value of the Arduino Uno clock speed of 16Mhz. I will need to investigate this a bit to see what I can do without going to a prescaler chip.

So end-to-end it took about 2 hours to get this working and much of that was figuring out where the library source was located on the Internet. The parts were simple, 100nF cap, 470k & 1k resistor, and PN2222 NPN transistor.

Next steps:
  • Dig through the library to understand how the sine wave is being counted and the gate timing
  • Understand how far I can scale this without using a divider or prescaler
  • Add a prescaler
It would be interesting to get this to cover 1MHz to 60MHz and format the data for an LCD so that it could be a standalone project.

73 de NG0R