In the same way as the LCD project this frequency counter circuit uses TMR1 in 16 bit counter mode to count the input signal edges. Counter overflows are accumulated to give the total count in multiples of 65536. Adding the current value of the counter at the end gives the total count.
Specification of the frequency counter circuit
|Max frequency||~50MHz (limited by input pin characteristics).|
|Input signal level||TTL|
The major difference in this project is that the display must be continuously refreshed so that your eye is fooled into thinking that display as is not flickering (persistence of vision).
For this frequency counter circuit project the display is refreshed every millisecond which is excessive – but does work. This refresh rate was chosen due to the timing period of the gate loop (999us) and allows easier constant time operation. Your eye only needs a refresh rate of about 50Hz or 20ms.
Pushing the refresh rate higher also shows you how to split the processing of a machine code algorithm, in the C environment, into several pieces so that the display can be refreshed at an approximate 1ms rate.
Just as in the LCD project the measurement time is 1 second the final count is actually the frequency of the input signal and again using the 1 second measurement time gives a frequency resolution of 1 Hz.
Note: The exact maximum operating frequency is determined by the PIC input pin characteristic.
Frequency counter circuit Test routines
Once constructed you can test the wiring out using the following two files e.g. if the 1st download file does not appear to work:
These tests will also test out a system using individual 7 segment displays.
|Frequency counter circuit:Test wiring 1||Download here.|
|Frequency counter circuit:Test wiring 2||Download here.|
Test wiring 1 : Outputs constant digits to the display and reads “12345678” from left to right. You can use this test to see if PORTD and each transistor driver is connected correctly.
Test wiring 2 : Outputs a shifted digit set from 1-8 to test PORTD connections to each 7 segment. Just observe each digit and make sure it goes through each number 1 to 8.
For a tutorial on compiling these files click here.
You can recompile the frequency counter circuit files if you want examine code operation (using the built in simulator) or change the source code. Note the hex file is contained in the download.
For the general theory of operation of this circuit and notes on frequency counting for this frequency counter circuit click here.
PIC frequency counter circuit Hardware
The main circuit blocks of the frequency counter circuit are shown in the diagram below.
The 8 seven segment displays are multiplexed using a Johnson counter (4017) that activates a single output after each clock pulse. Port A drives the reset line and clock signal to the 4017 and transistors at the outputs of the 4017 are connected to the common cathode of each seven segment display. This lets the micro turn on each display sequentially. Port D drives the segment enable lines to control the character displayed.
The crystal oscillator is simply a crystal and two capacitors connected to the PIC oscillator port at OSC1 and OSC2. The capacitors can both be fixed unless you want to tune it using a frequency reference. If you don’t have an accurate reference then use fixed capacitors.
For more detail: 50MHz 7 segment frequency counter using PIC16F877A