Frequency counter with PIC16F628A


xristost blogged about the frequency counter module he made:

First of all I wanted a PIC microcontroller to do the whole job without any additional ICs. Also I wanted to use the the familiar 16F628A, but because one of the portA pins (RA5) can be used only as input I was short of outputs to do the job. Driving 6 digit 7-segment multiplexed display requires 7 + 6 = 13 outputs. The 16F628A has 16 IO pins, two of which are used for the crystal oscillator, one is for the signal input and other one can be used only for input, that leaves us with only 12 useful IO pins. The solution was to drive one of the common cathodes with a transistor, which opens when all other digits are switched off.

Join the Conversation


  1. Proper 6 digits of precision would need an OCXO etc. 6 digits is rarely useful in hobby work. Given crystal precision and temp stability, a 4 digit LED module and a floating decimal point for kHz units would fit the PIC part nicely. Ewww, he uses tantalums…

    1. I just wonder why he went all that trouble with the transistor and what not instead of using a different PIC. There are plenty of PICs around $2 that could do the job.

      I don’t agree that 6 digit resolution is not useful – if he is doing anything with HAM radio, there at 20MHz 6 digits gives you resolution of 100s of Hz. There are communication modes that actually require that sort of frequency stability (or better!) and seeing whether your signal drifts in frequency is important. What is rarely needed is absolute accuracy, though. With usual 10ppm crystal he could achieve 200Hz stability.

      1. There are a lot of books stuck in the PIC16F877A and early PIC18 period and maybe either he is either using old stock or he doesn’t know about the new stuff. For example I still have 4 PIC16F84A that I can’t figure what to use for myself.

        Actually I’ve never seen any ham radio blog postings here on DP. No obvious category tag either. So I do think folks around here would rarely need 6 d-p, especially for an audio-to-ultrasonic range thingy.

      1. Important to be Green for products to avoid getting used by Greenpeace as an example to others, heh heh. I avoid them in my hobby stuff as a matter of principle.
        Take for instance SSDs. Initially, when they started the write-cache-to-flash on power outage trend, you can see some manufacturers using banks of tantalums. Oh, bad idea, Greenpeace will get you for that. So that quickly changed to banks of MLCCs. Now that the analog IC people have made some nice supercap controllers, I’m seeing boards using supercaps now. Problem solved.
        Many articles talk about tantalum in consumer products, but fact is, tantalum caps in mass market consumer products have become a really rare thing.

  2. Another way to save PINs would be to use one common cathode and one common anode LED modules. This way you can drive 6 digits w/ 3 pins in a sort of charlieplexing setup.
    Better yet use 4 digit modules and enable the decimal to give some range display w/ higher resolution.
    8 segments + 4 digits (actually 8 via charlieplexing) = 12 IO pins.

  3. What’s so heretical about adding a 3 to 8 decoder? One chip, and there’s more resolution than you can shake a stick at.
    6-digit displays are great for HEX dumps too: 4 digit address, 2 digit value. 8-digit displays are better when you have 16-bit wide memory.

    1. Project author wanted a single chip solution; fair enough, so we were offering opinions based on that constraint. He can probably fit a 74HC(T)164 in the back, or if he raised the display by 1 turned pin socket height, he can even put a DIP part right under the display. Better than that bunch of diodes, I think.
      I tried hex dumps for tracing some USB code once; even on a 16×2 HD44780 it wasn’t ideal. 16×8 chars on a handphone LCD screen was much better.

Leave a comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.