PIC Frequency Counter
by Harry Lythall - SM0VPO

I must begin by stating that this project is not all my own work. The project is based on a PIC frequency counter by Wolfgang Buescher, DL4YHF. It is with his kind permission that I have modified his work.


This project is a 5-digit basic frequency counter, based on the cheap PIC16F628A microprocessor chip. It has a range from well under 100Hz to about 60MHz, and has a 5-digit, auto-ranging display. Sensitivity falls with frequency, but a simple 2-turn loop on the input is more than sufficient to count my GDO-2 project from 100kHz to well over 35MHz. This counter is very basic in that it simply displays frequency, with no frequency offsets, memories, or any other bells and whistles. Wolfgang's original project does include frequency offsets, so the project could be used as the counter in a communications receiver. But for workbench use I needed a simple, basic counter and thought that any offset could lead to mistakes and possible confusion.

I will supply my modified counter software (.ASM = 88,477 bytes, .HEX = 3,947 bytes); a modification of DL4YHF's work, but if you want all the full options of the original project then you can download the original files from Wolfgang "Wolf" Büscher, DL4YHF's homepage. My PCB is fully compatible with Wolfgang's software, but the "Pg" input on my PCB has no function for my modified version of the counter.

If I wanted to be really clever I could have re-organised the pins a bit and re-used the "Pg" pin saving as a 5th digit driver. This would have taken a lot of time, saved one transistor and four diodes, and made my board incompatible with Wolfgangs work :-(


The project uses two Printed Circuit Boards, one for the main processor, and one for the five 7-segment LED displays. Two display versions are given, one for normal, and one for large size displays.

Complete circuit diagram.

I chose to use the SC39-11EWA (link to datasheet), 10mm high, High Efficiency, GaAs, Common-Cathode LEDs. I have included the PCB for the ELS-511IDR (link to datasheet), which is a 14mm high, High Efficiency 7-segment LED, suitable for viewing up to 7 metres. I drove both devices with about 4mA per segment, which gives a good bright display IF YOU USE A RED FILTER.

Main processor PCB pattern.

7-segment displays have the segments identified with the letter A, B, C, D, E, F, G and Dp. Segment A is the top-most segment, and they are mumbered sequentially A - F in the clockwise direction. Segment G is the centre segment, and Dp is the decimal point. All A-segments from all five displays are connected together in parallel. The common-cathode terminal of one display is grounded to cause one segment to display a digit. This is under software control. Only one digit is ever illuminated at any instant in time, and if you physically shake the display you will see a pattern due to this effect (called multiplexing).

Display board for ELS-511IDR displays.

The above PCB is for the ELS-511IDR (14mm) displays. These are good used for demonstrations, where the figures can be viewed from about 7 metres. The training courses are also one reason I had to remove the options from the software, or the trainees would push every button and change every parameter possible: nothing worse that starting a demonstration and finding that the instrument(s) all have to be reprogrammed!! When correctly printed the text will be the correct way around when viewing the copper side of the board. The terminals marked 1, 2, 3, 4 and 5 are the common-cathodes of each display (D1, D2, D3, D4 and D5). Note that there are four wire links and these are all fitted to tracks connected between the display common-cathodes, and D2, D3 D4 and D5 (the four lower-most tracks on the PCB).

The PCB below is for the SC39-11SRWA (10mm) displays. These are better suited for laboratory use and will allow a smaller case to be used. When correctly printed the text will be the correct way around when viewing the copper side of the board. This particular display board was first used for a simple DDS signal generator, so the common-cathode displays are a little differently marked:

The segment numbering on this board is still A - G, but in lower-case (a - g). The decimal point (Dp) is simply labelled "p". Note that D1 - D5 (CC0 to CC4) each have a wire link from the pad to the common cathode terminals of the displays.

Display board for SC39-11SRWA displays.

The processor I chose was the PIC16F628A, clocked at 20MHz to get the best performance. If you want to use the 4MHz option that Wolfgang used then you will either have to use his original software, or make changes to the .ASM file. I have included a single transistor pre-amplifier, which boosted sensitivity tremendously. You may want to use the BF199, but in tests I found that the BC547 worked just as well. The upper frequency limit is restricted by the processor performance and not the input pre-amplifier.

You will notice that there are a couple of 100Ω resistors sprinkled around the board. I put one in series with the "Pg" input pin to the processor. To me it feels wrong to connect a micro-processor pin to an external switch (I was brought up on the 4004, 8080, 6502 and Z80 chips). The 100Ω gives the chip's internal protection diodes a fighting chance in the event of static.

I also added a 78L05, 5V regulator. I felt it would be a good idea to give a constant performance for the complete life of the battery. I also included a 100Ω in series with the regulator. This is a little kindness to the regulator chip, and also to lower the maximum current the chip can deliver. Maybe they do not improve anything, but they make me feel better :-)

The counter hardware is otherwise super-simple. The counter is auto-ranging, and the decimal-point flashes to indicate kHz or steady (not flashing) to indicate MHz.

7-Segment Display Interpretation
Range Display Gate Time Decimal Point
0 to 9.999 kHzx.xxxx1 secondflashing (= "kHz")
10 to 99.99 kHzxx.xxxx1/2 secondflashing
100 to 999.9 kHzxxx.xx1/4 secondflashing
1 to 9.999 MHzx.xxxx1/4 secondsteady (= "MHz")
10 to 50.00 MHzxx.xxx1/4 secondsteady


Select and print my PCB(s) on OHP film, using a Laser printer. Do NOT "resize" the patterns in any drawing program or you will loose resolution. Select "printer resolution" if you are using GIMP, PSP or Phtoshop. If you have none of these then you can import the pictures into MS-WORD and drag the corners so that scale bar prints exactly 1" or 25mm.

Scale bar = 1" (25mm) between centres.

Note that the text on the ink/toner side of the paper must be backwards. If you iron the toner onto the copper-clad board, or use photo-etch then the text will become the correct way round. All PCB holes are drilled with 0.8mm to 1.0mm holes. Fit the components as shown in the component overlay drawing. I used jumper wires between the processor and display boards, but I had originally though of using a ribbon cable. Do not solder the PIC processor to the PCB. Use a DIL socket.

Mainboard Component Overlay (Component side - X-Ray view of copper).

The PIC pin with a square pad is pin-1. Note that there is one wire link, between the 10nf and the In pin. If you use an axial capacitor for the input then you can eliminate this link, and wire the BC547 Base to the In pin with the longer capacitor. I didn't have a suitable component but the boards accepts both alternatives.

When the boards have been assembled WITHOUT THE PIC PROCESSOR, connect a 9v battery and check the current drawn is no more than a few mA. If all is well, then disconnect the battery, plug in the processor and re-connect tha battery. You should be greeted to all segments on all five displays lit for 0.5 seconds. After that, four blank displays and one displaying "0". Momentarily connect a 10pf to 100pf capacitor between one of the 20MHz crystal pins and the counter input. You should see a display of "20.000" if all is well.


As stated above, you can download the software of the original project from Frequency counter with a PIC and minimum hardware, by Wolfgang "Wolf" Büscher, DL4YHF. Select the version for Common Cathode LEDs.

If you are using MP-Labs software then my modified pic_counter_no-pgm5.asm source file is here. If you want to load my pic_counter_no-pgm5.hex file into your processor then click here. Just right-click and select "save as", then choose a file location on your computer.

Working Project

This particular version was NOT fitted into a case since I use it for demonstrations in my courses (up to 60 people). Signal generators and other instruments today are big, almost identical boxes, with a large LCD display and many "sort of pushy-things" (knobs, buttons and switches). I prefer to use a GDO and leave the counter open so students can see what is inside the instruments. Students get to see the innards and understand without me having to add yet another "teaching point".

Assembled boards displaying 30.814MHz from my GDO #1.

One of my course demos is to measure the length of a piece of wire, or a drum of coaxial cable (CNT240). I use the Grid Dip Oscillator to find resonance of an unknown (8-metre) length of wire or an unknown drum (49 metres) of coaxial cable (with inner-outer shorted at both ends). The GDO displays resonance, the counter displays the resonant frequency, and the length of the wire or cable can be calculated to within a few centimetres. I fitted a temporary loop of wire to the input of the counter and it seems to have become a permanent fixture. Here you can see the oscillator is tuned to 30.814MHz. You can also see the wire links for the common-cathode connections, and the orientation of the 7-segment displays on the display board.

Now you should have enough information, drawings and the software required to build my version of the frequency counter. Because the main board and display board are seperate, you can fit the completed frequency counter into a very small box. You can make a counter with a very large display, and if you use Wolfgang's original software then this board will support the programming mode.

Well I hope that you have learned something useful with this information. If you have any questions or comments then please use my forum to pose them. I often get overloaded with e-mail. Return to the INDEX page for the link to the forum.

Very best regards from Harry - SM0VPO

Return to INDEX page