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:
Based upon the parts on hand I decided to work with the first link listed above.
- You will need a library located here: http://interface.khm.de/wp-content/uploads/2009/01/FreqCounter1.zip and get that copied into your library folder.
- Next you will need build a simple amplifier to increase the power level of the signal that you are planning to measure. I built built something like: http://interface.khm.de/wp-content/uploads/2009/01/preamp.gif but I tweaked it to use a PN2222 because it was what I had on-hand.
- The theory is the signal comes into the amp and then is sent to PIN 5 on the Arduino Uno board.
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.
- 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
73 de NG0R