Warning: This site is under construction, most links will be broken.

Electronics -> 60MHz 8-digit frequency counter

Last modified on Thu, 19th Nov 2009 at 22:20 UTC by zipplet

Recently I needed a high precision frequency counter to tune oscillators for my Megadrive PAL 60 composite modification. I checked my usual suppliers, balked at the high prices and ran off to ebay. There are some good offerings, but the cheap ones have to be imported from China and may be of dubious quality. I also wanted something I could run from my 12V portable battery pack if necessary for portability. Besides, I don't need a crystal oven stabilised counter just yet (although it would be nice!).

I decided to try to make a frequency counter using a PIC microcontroller. I figured if I used a reasonably good crystal and calibrated it that I would get fairly good accuracy. My first port of call was google to see if anyone else had a project like this. I found a few examples and decided to build this 4-5 digit counter onto a breadboard to play around with it - I didn't want to waste time designing/building one if a PIC simply couldn't do it well enough.

I was impressed and as I wanted one in a hurry but needed more precision I set about altering the design of DL4YHF's counter to allow 8 digits. I found some bugs in the firmware that I hacked around and the result is fairly good. However I will be writing my own firmware from scratch because I have ideas to increase the precision further (read down for more information). I also added a negative value indicator, zero indicator and preamp selector switch. I removed the auto-range display function so the measurement is always shown in Hz with all digits. The gate time has been fixed at 1 second to improve precision.

bbcode image
The finished product

Officially the PIC RA4/T0CKI pin cannot count faster than 50MHz (with prescaler) but it has been confirmed up to 60MHz reliably by multiple people so I labelled mine up to 60MHz.

Parts list


Coming soon.

Schematic diagram


Coming soon.

Calibrating the oscillator


My unit is clocked with a 20MHz +/-20ppm crystal. I fitted a tunable capacitor to allow me to alter the frequency slightly to make the unit as accurate as possible. To calibrate the unit, I measured several oscillators and then adjusted the counter accordingly. I have confidence in the calibration but it will not be as good as calibrating it against a very precise frequency source.

Accuracy and precision


The counter should be as accurate as the tuned crystal oscillator inside it. There is a bug in DL4YHF's firmware that causes the counter to lose exactly 16Hz for every 65536 counts. I could not find the root cause of the bug so I corrected for it. I believe it may have something to do with the watchdog timer and prescaler. This will be corrected in my rewritten firmware.

Precision is dependent on the prescaler. The timer register cannot increment more quickly than the CPU oscillator divided by 4 (in theory 5MHz with a 20MHz crystal but >4MHz is reported to be troublesome). Additionally, if the timer overflows too quickly the firmware will lose counts so the speed needs to be kept sane.

Precision is as follows:

The precision can be improved by using tricks to figure out the remainder in the prescaler at the end of the timing loop, to give resolution down to an amazing 1Hz at 60MHz! Very very good for such a cheap device.

I also plan to show digits after the decimal point for low frequencies.

More pictures


bbcode image
Back of the unit, from left to right: Program button, probe port, preamp selector switch, power switch, power port.

bbcode image
Bottom of unit with warning label.

bbcode image
Detachable counter probes - simple unshielded test probes (I will build some nicer ones later). Terminated with 2 mini grippers, very useful for connecting to small pins.

bbcode image
Unit powered up without a probe, showing a zero count. An ungrounded floating probe (or disconnected probe) may cause the unit to pick up stray mains hum, showing a count of 50 on the display because it is very sensitive (high impedance) with the preamp turned off. I switched off my flourescent lamp, which allowed the counter to settle at 0.

bbcode image
Calibrated* unit measuring a 4MHz 5V oscillator module. The value shown is close to exact - the oscillator being measured is not exactly 4MHz.
See above for information about the calibration, which is not perfect

bbcode image
Calibrated unit measuring a 25MHz 3.3V oscillator module.