Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Frequency measurement using PIC microcontroller

Status
Not open for further replies.
Hi,
Can anybody suggest me how to measure frequency of sine wave of 50Hz,with 0.1 precision.
Hi siddarth.ghaste
Although my knowledge in digital is very small . but i know how to do it . you'll have two ways for going through .
1- using an FVC integrated circuit and then measuring the out put voltage of the FVC by ADC of your PIC . ( i.e : FVC is an IC which will deliver different voltages instead of different frequencies . )( frequency to voltage converter ) and it is easily available till several GHZ !!!
But as you mentioned your frequency is low and it is about 50HZ .
2-So you need to use a comparator ( which i think PIC has one of them internally ) to convert your sine wave into square wave . and then using two kind of timers of your PIC . first one will prepare you a 1 sec ( it will count as a triangle ) and then another one will count while you have the input and then compare number of triangles and then showing it on LCD or &segment .
But about it's programming i'm sorry because i don't know about programming ! but i'm sure the way is like what i've told .
Best Wishes
Goldsmith
 
To measure any frequency
(1) you need a reference clock that is more accurate. You only need 0.2% or 2000 ppm accuracy, so that should be easy to find. Even a watch is 50~100ppm.
(2) you need a counter over some measurement interval. If you have a fast accurate counter, a few cycles will do. If you don't then you can increase the measurement interval and average.


You can use a watch xtal, GPS 1ppm and 10MHz or any reference.

There are dozens of variations of measuring frequency, using a sample and hold with a zero crossing trigger to sample an external 50Hz sawtooth and hold. The output will be a sawtooth with the difference frequency. The slope will change if the error is + or -.

Easiest way is buy an inexpensive counter.

or make one **broken link removed**

Another way is get a free piano or guitar tuner and use the audio port on a PC or mobile device with an app to measure the frequency. good enough for 3 or 4 digits of accuracy.
 
Last edited:

Hi

first, you should convert sine wave to a square wave with a simple OPAMP such as LM324 (has 4 OPAMP). Then you can count square wave using counter module in PIC micro-controllers.

good luck

HR Karami
 

Hi siddarth.ghaste
Although my knowledge in digital is very small . but i know how to do it . you'll have two ways for going through .
1- using an FVC integrated circuit and then measuring the out put voltage of the FVC by ADC of your PIC . ( i.e : FVC is an IC which will deliver different voltages instead of different frequencies . )( frequency to voltage converter ) and it is easily available till several GHZ !!!
But as you mentioned your frequency is low and it is about 50HZ .
2-So you need to use a comparator ( which i think PIC has one of them internally ) to convert your sine wave into square wave . and then using two kind of timers of your PIC . first one will prepare you a 1 sec ( it will count as a triangle ) and then another one will count while you have the input and then compare number of triangles and then showing it on LCD or &segment .
But about it's programming i'm sorry because i don't know about programming ! but i'm sure the way is like what i've told .
Best Wishes
Goldsmith

I am converting F to V using LM2917N. But the problem is suppose I turn my circuit for first time, it shows 1.920V. But when I turn after some hours voltage increases to 2.990.I am using 10 bit ADC, so step size 4mv.I am unable to identify the problem.PLEASE HELP
 
there are many sources of error which you have neglected to report on.

+\- ? Accuracy of ;

source 50Hz =
F to V converter
V reference drift?
V reference Noise? ( which can cause missing levels)
temperature change?
Supply change?
ADC accuracy=? > resolution

You must confirm each to find your problem.
 

I am converting F to V using LM2917N. But the problem is suppose I turn my circuit for first time, it shows 1.920V. But when I turn after some hours voltage increases to 2.990.I am using 10 bit ADC, so step size 4mv.I am unable to identify the problem.PLEASE HELP
Hi siddarth.ghaste
As SunnySkyguy mentioned above it can be because of several parameters that you need to mention them . and also it can be because of bounce of the key too . can you tell us about these parameters please ?
Best Wishes
Goldsmith
 

This is quite easy to do using a mid-level PIC. I have used a PIC16F877A to measure frequencies from 5 Hz to 20 kHz, with a precision of 0.01Hz.

Reference: Peatmans book on PIC microcontrollers.
a) Use CCP1 and Timer 1 module to capture the input signal.
b) Use CCP2 to count the number of Timer overflows.
c) Use Timer 0 to set a flag F after an (approximately) 1s interval.

The ISR for CCP2 would increment a count of overflows. The ISR for CCP1 would add the Timer 1 count to an accumulator as well as count the complete periods. Upon seeing the flag F it would store (a) the number of complete periods (b) the number of overflows (from CCP2 ISR) (c) the accumulator. It would set another flag. The mainline code would test this flag (in a CS) and calculate the frequency based on this data.

Note that Timer 0 ISR does not have to be high priority. It is used to simply wait for about 1 sec. so as to enable enough counts.

Thus the frequency is measured over an (approx) 1 s. period. If the PIC is running at full throttle (20 Mhz) then you would have approx. 5e6 counts, needing 24 or 32 bit arithmetic, and providing more than enough precision.

Hope this helps.

vkj.
 

Find 2 consecutive peak of sine wave.

Sample the signal using ADC module in PIC.

Decide no of samples per second.

With the no. of sample and duration (I mean samples taken at particular interval) you can find the time period of the wave.

1/ time period will give you the frequency.

By adjusting the sampling rate, you will get 0.1 precision.
 

Original question was how to measure 50Hz with 0.1 Hz accuracy

All you need is a count of 500 pulses +/-1 so you can either;

a) count 50Hz pulses derived from AC using resistor divider to scale down voltage for 10 seconds where 10 seconds is accurate within 0.2% or
b) count between zero crossing in one 20ms cycle at least 500x the frequency of 50Hz or 25,000 KHz

Averaging b) will reduce variation and improve resolution by square root of N samples so 100 samples reduces jitter by 10x thus giving resolution of 1 cycle in 50,000 but if signal has random noise gives deviation of 1 cycle in 5,000.

Overall accuracy is always limited by your frequency reference. If you have uC with a 32kHz Tuning Fork, MEMs or "crystal" or say a 10MHz crystal these are usually rated in parts per million (PPM) The cost of these resonators is cheap now with 1ppm TCXO's worth $5 and 50ppm Xtals worth 10 to 50 cents. Your Requirement of 1 part in 500 = 2000 PPM should only cost 1 penny ( ha. ha., if you extrapolate the inverse cost vs accuracy.)
 

Hello friend,

Am facing the problem stacked in frequency measurement.

i need to find the frequency of mains transformer that is 50hz. I know there is is an IC LM331 which can be used to convert frequency to voltage, Problem is it is impossible to connect mains AC direct to an IC. So in between i need to measure frequency which i can give an input to the IC.

So, please suggest me i need to build an hardware to measure MAINS frequency 50HZ and frquecy to voltage converter.

Prompt answer will be appreciated.

Thanks

- - - Updated - - -

I am converting F to V using LM2917N. PLEASE HELP

Dear Friend,

How did you give frequency input to the IC LM2917. Is there any circuit to measure frequecny for MAINS 230 v 50hz.
i need to find the frequency of mains transformer that is 50hz. I know there is is an IC LM331 which can be used to convert frequency to voltage, Problem is it is impossible to connect mains AC direct to an IC. So in between i need to measure frequency which i can give an input to the IC.

So, please suggest me i need to build an hardware to measure MAINS frequency 50HZ and frquecy to voltage converter.

Prompt answer will be appreciated.

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top