Wednesday, August 5, 2015

100MHz frequency counter

Couple of weeks ago I purchased from eBay one of these amazingly cheap an useful modules with MAX7219 LED driver and 8 digit LED display. It is ideal for frequency counter project. The problem was the absence of library for PIC microcontrolers. Luckily, I found a great library for Arduino and I reworked it to be compatible with PIC. The schematic of the frequency counter is actually almost the same as the previous . It uses PIC16F628A microcontroller with external 32.768kHz watch crystal attached to Timer1 to generate 1 second time base. Measured signal is fed to pin3 (RA4) which is counted by Timer0.

The program make short (0.125s) test of the input signal to determine the prescaler value. Next is the actual counting with the proper prescaler value and then the result is send to the display.

This is fast breadboard proof-of-concept project, and I don't intend to make a finished product, for now at least. Of course there must be some sort of preamplifier/protection in front of the frequency counter in order to be usable.

In the pictures below is shown the breadboard and five different quartz crystals generating different frequencies. The differences between the value on the display and the value on the oscilloscope are negligible. I tested the schematic also with frequencies above 90 MHz and even above 100Mhz and the results was accurate, but of course most significant digit was lost in case of 100+ MHz.

Link for downloading the code and .hex files: LINK


  1. Very interesting project. Unfortunately, problem with hex. by a file - a processor after programming stops to be identified. Does the respected author can to help? 73! Vitaly

  2. I used the program PICkit 2 v2.61 and "native" device. After failure, I have tried to use homemade JDM with program "PonyProg2000", factory "Triton". The Process occurs so: comptroller successfully "is flooded", afterwards, in an effort consider appears the message "device is not identified or faulty". I used undoubtedly worker 628 3 items - result same. Dear Hristo, but what program and device use you?.Thank you. Respectfully yours, Vitaliy

    1. I use the same program and my programmer is DIY clone of PICkit2. You can try this:
      First, in the program set "VDD PICkit2" to 5V.
      Second, in "Tools" check the option use "VPP First Program Entry".
      These steps should help the program to recognize the chip.

  3. Hristo, thank you for consultation. I shall without fall try your advice, but first want to try the processor from the other parties - beside me doubts about marking product from chinese "friends". I have done quite a few designs, but such - first once. Respectfully yours, Vitaliy

  4. Христо, большое спасибо за помощь. Действительно,с включением "VPP First Program Entry" все "зашилось" нормально. Хочу добавить входной формирователь на полевых транзисторах. У меня уже собран ГСС на AD9850, с индикацией на модуле MAX7219. Частотомер на том же модуле, как мне кажется, хорошо будет смотреться на передней панели универсального прибора. Еще раз спасибо за программу и помощь. С уважением, Виталий.