circuit_projects

Circuit Projects

Electrical/Electronics Blogger

Circuit's Projects :

Return to Projects

Frequency Counter by PIC16F628

Project Summary

In this project we are building a basic and low cost frequency counter circuit . It can measure from 16Hz to 100Hz signals with a maximum amplitude of 15V. The sensitivity is high, the resolution is 0.01Hz. The input signal can be a sine, a square or a triangle waveform.

Project Description

The counter can be used in many applications. For instance, to observe an oscillator’s accuracy, to measure the mains frequency or to find out the rpm of a motor that is connected to an encoder.

The PCB file is provided in pdf format. You can apply it to the board by using the ironing method.

The components are listed below.

1 x PIC16F628 – 04/P Microcontroller
4 x Common Cathode 7 Segment Display
1 × 4N25 General Purpose Phototransistor Optocoupler
5 x BC547 NPN Transistor
1 × 7805 Voltage Regulator
7 × 330 Ohm 1/4 W Resistor
7 × 1K 1/4 W Resistor
1 × 470 Ohm 1/4 W Resistor
1 × 10K 1/4 Resistor
1 × 4.7K 1/4 W Resistor
1 × 1N4148 Diode
2 × 220nF Polyester Capacitor
2 × 22pF Ceramic Capacitor
2 × 100uF 16V Electrolytic Capacitor
1 × 4Mhz Crystal Oscillator

Figure:1

Figure 1 

The CCP (Capture/Compare/PWM) module of the PIC microcontroller counts the input signal. Only the capture function is used. To learn more about the CCP module of the PIC please visit http://www.microchip.com.

The displays are 14.2 mm common cathode seven segment LEDs with red light.

Figure:2

Figure 2 

Before measuring the frequency of the input signal, the signal must be converted to the square waveform. So an optical isolator circuitry with 4N25 optocoupler is used for this purpose. So the input signal is safely isolated from the microcontroller circuit and converted to square wave. The signal amplitude must not exceed 15V. If this happens, 1k resistor may burn. If you want to measure the mains frequency, you should use a 220V/9V transformer first.

The supply voltage should be between 8-12V. Since the circuit may be defected, you should be careful about the polarity while connecting the supply.

The counter circuit schematic is given in the project file. There are 4 displays that are driven by the multiplexing method. To make the measurement, the RB3 pin is connected to the output of the optic isolator. The second display’s 5 numbered pin is connected to the supply via 1K resistor so the dot after the second display brights. This connection isn’t shown in the schematic.

Figure:3

Figure 3 

The C code that is writen with Hi-tech PIC C compiler is available in the downloadable project file. The hex code is also included.

We used extra two sockets. One (18 pin, 2 way) is for the PIC16F628 microcontroller, and the other one is (40 pin, 2 way) for the seven segment displays.

Y.Erol

Project Files

File NameFile Size
Frequency-Counter.rar281.41 KB
Tags: frequency, counter

Comments on this Project:

By bigmac -2Score: 

5 years ago:  thanks for this cool project...

By Christophe 0Score: 

5 years ago:  Is it possible to adapt the code so this circuit could measure
frequency starting from 1 Hz till 100 Hz instead of starting from 16 Hz till 100 Hz ???

By LSoft 0Score: 

5 years ago:  Dear Mr. Erol!
Thanks to your project I was able to make my own freq. counter.
Thanks a lot! Although there were some errors in your C source code ;)

By Teska 0Score: 

5 years ago:  Hello Mr. Erol ,
I have built your circuit and it seems to work , only
the c segment from the 7 segment display get not driven by
the microproccesor. Probably a software bug like Lsoft stated.
Do you have allready an updated and corrected C source and/or Hex file for this circuit ??? It's a pitty that we can not contact other members else i would e-mail to Lsoft as he stated that he found the bugs allready ??

By Teska 0Score: 

5 years ago:  Accidently pin 8 of my microprocessor was bowed to the inside unerneath the IC-socket. Problem is solved. Everything seems to work correctly with the original source-cose. I used the Hex file altough.
Kind regards

By Ronald Fens 0Score: 

5 years ago:  Hallo,

I try to download the PCB but the rarfile does not exist.
Please help

Ronald Fens

By salger 2Score: 

5 years ago:  hello sir
i want a frequency meter counts from 1 to 99 hz (two digits) withaout a pic but with simpls ic . its pssible !

By Steffi 0Score: 

5 years ago:  Hello, I was very interested in the C-Code. The zip folder does not have it though. Where on the webpage can I find it?

By Jun 0Score: 

5 years ago:  Hi, this project seems pretty cool but download link is not working. I also tried searching in your schematic archive but not available in there. Can please send me a download link by e-mail if you are unable to provide it here?

This is exactly what I am looking for, so please provide me the schematic diagram.

Thanks....

By Max 0Score: 

5 years ago:  Hi please try downloadin it again. Thanks

By Jun 0Score: 

5 years ago:  Thanks for your prompt action. Note to everybody who experienced difficulty downloading the schematic, the link is now working... salute!

By jun 0Score: 

5 years ago:  Can you please provide the 7 Segment Display part number? It think I have purchased the wrong one.

Thanks...

By J.E.Boerma 0Score: 

4 years ago:  will this chip work with 4mHz

By ato agustin 0Score: 

4 years ago:  thanks for the link sir...more power!

By Bdhong 0Score: 

4 years ago:  Trim's
Mudah-mudahhan oke

By khimzkie 0Score: 

4 years ago:  pano ba ito aaply?..

By VU3NOV, India 0Score: 

4 years ago:  Can you provide me the required code to count the RPM of motor (The existing encoder on my motor gives 1 pulse / Rev)

Thanks....

By ranidel de ocampo 0Score: 

4 years ago:  this looks fun to build. I will try this one :)

By Banthom 0Score: 

4 years ago:  Thanks>>>

By vi 0Score: 

4 years ago:  hi, where is the delay.c ?
can you upload?
thanks

By emmanuel okoli 0Score: 

4 years ago:  please how can i order for the component and pcb

By john 0Score: 

4 years ago:  I don't understand c yet would I be able to find an asm listing for mplab. this is very interesting thanks

By X2 0Score: 

3 years ago:  Hi,

Im interested in using the value of the frequency as a number. That is 50.01 or 51 or 49 and I want to use this number as an input in another PIC to compare it with a fixed value say 50. Is it possible to obtain from your circuit such an output? My knowledge in electronics is limited.

Thanks

By Gurdev 0Score: 

3 years ago:  Erol - hi - I've just started playing around with PIC's and just finished building your circuit - thanks for sharing - it works!! - must be getting better with my soldering iron!!
I would like to learn about coding PICS - eg I would like the display to show RPM (60 * FREQ) but don't know how to change the code.
Can you give me some idea where I should look to be able to learn & do this with my finished circuit board project??
Thank You

Gurdev

By dani 0Score: 

3 years ago:  can I using 16F628A instead of 16F628-04/P, or I should change the code?

By dani 0Score: 

3 years ago:  i cannot program the pic, i have try to program both 16F628A or 16F628-04/P, I'm using RCD and JDM programmer without success, error when verify, the programmer said config word not mach. any clue?
thanks,

By joanne 0Score: 

3 years ago:  i have made this freq.counter but i dont know how to test the frequency do i need a signal generator to create oscillation? beacuse when i turn it on it reads zero and when i connect it to a AM/FM receiver it display numerical value in the 7segment but turn to zero qucikly.. please help im just new in electronics tnks....

By Ajit 0Score: 

3 years ago:  Thanks for the project.
Please Mr. Y Erol provide the correct source c code as the posted c code is incomplete & full of errors.

aman Fatima
By aman Fatima (0) 0Score: 

11 months ago:  can u also tell me the code of this project..??

jose Mendoza
By jose Mendoza (0) 0Score: 

10 months ago:  Hola usuarios hice el proyecto con el pic 16f628a y prende los display pero se quedan en cero y hay veces cambia de numero o lo hago con el pic k dice 16f628 04
nose verdad ayudenme

Login or Register to post comments.
Click Here