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.

How to measure the frequency of the sine wave using micro?

Status
Not open for further replies.

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,689
Frequency measurement

Hi

Does anyone know how to measure the frequency of the sine wave by using a microcontroller?

Bascially the sine wave are sampled at few hundred via ADC channel from my microcontroller. I have no idea how to calculate the frequency.

Help from you would be greatly appreicated

Maverick Max
 

Re: Frequency measurement

Unless you are measuring *very* low frequencies, or have a *very* fast MCU, using the ADC for frequency measurements is probably not the best way to do it.

There are two basic ways an MCU is generally used to measure frequency. First though, all you need to give the MCU is a common point on the wave. You can do this with a comparator assuming you have attenuated or amplified the signal as necessary. Does your MCU have a comparator built in? Or, you can detect the rising edge of the signal with an interrupt pin.

Then, either:

1. For low frequencies, start a counter at the first rising edge. Stop the counter at the next rising edge. The frequency is 1/time. For greater accuracy, you could count more edges before checking the time, for instance count ten.

Or:

2. For higher frequencies, the rising edge increments the counter, and you time for a set amount with another counter/timer. Say, count for 0.1 seconds, then the frequency is 10*counts.

Search the web - there are a *lot* of examples of this type of thing.

I designed one using a CPLD as the counting part, to get more speed and accuracy. Principle was exactly the same but it did both (1) and (2) together and timed the duty cycle. It worked on the breadboard. Never got around to actually finishing it though.

If you *must* use the ADC, then you just look for the zero-crossing point and use that to count from instead of the interrupt above.

FoxyRick.
 

Re: Frequency measurement

Sine Wave-->Zero detector(hard limiter)-->Square Wave


The square wave generate the estimulus to the uC interruption, then use Timer to count time, between two consecutive positive slope transitions.

I have to confess that, i try by this way in work, and i have problems.
I don't know to say if there is some Timer operation that involves directly an event that force the timer to count (without interrupt routine intervention).
 

Frequency measurement

in fact a second paper in topic below covers accurate measurment based on sampled signal .
But note that frequency you measure must be unique one in signal you sample, to use such method (otherwise result will be erroneous):




You can look to first papepr as well but i guess it is more complicated than second .
 

Re: Frequency measurement

To measure the frequence of a sine wave, convert to square and then use the CAPTURE mode of the CCP to measure the time between two zero crossing.

1/T will give you the frequency.

Cheers

Ravi
 

Re: Frequency measurement

Hi
First,you convert the sine wave to square wave by Smith circuit
You used counter(1 or 0) to count the pulses during a time
I have completed measure frequency of square wave,if u need,please mail to me:lthanhtuan1984@yahoo.com
Regard
 

Re: Frequency measurement

Hi

Do the following

1. Use a zero voltage Switch.
2. Make a time base for 1 Sec.
3. Pass zvs through 1 sec timebase.

Thx+
 

Re: Frequency measurement

There uC based 1MHz frequency counter in July/August 2005 issue of elektor magazine. It's based on zero crossing detection. The code for the avr uC is downloadable from elektor's website. It might give you some clues. :wink:
 

Re: Frequency measurement

Just use a frequency to voltage converter chip and measure the analog voltage by the micro adc. This method will not use any additional resources of the micro. Alternatively if you have lots of spare memory in the micro, use interuppts and timer.
 

Re: Frequency measurement

Zeppelin said:
There uC based 1MHz frequency counter in July/August 2005 issue of elektor magazine. It's based on zero crossing detection. The code for the avr uC is downloadable from elektor's website. It might give you some clues. :wink:
Can you upload the copy of this article?
Thanks
 


Re: Frequency measurement

pop48m said:
Zeppelin said:
There uC based 1MHz frequency counter in July/August 2005 issue of elektor magazine. It's based on zero crossing detection. The code for the avr uC is downloadable from elektor's website. It might give you some clues. :wink:
Can you upload the copy of this article?
Thanks

The site doesn't like upload of copyrighted material, but I'll try to find a link for the article.
 

Re: Frequency measurement

I have posted a link to this issue of elektor here
 
Last edited by a moderator:

Re: Frequency measurement

Zeppelin said:
I have posted a link to this issue of elektor here

Your link was removed. Please send me the paper on email address given in personal message.

Thanks, Pop
 
Last edited by a moderator:

Re: Frequency measurement

First scale down ur signal if it is more then 5v and then feed it to an op-amp based schmitt trigger to convert it into square wave. After this feed this to the CCP input of PIC 16f877.
 

Frequency measurement

Hi...

How can we make a circuit for this if sine wave is varying? (eg: sine wave is 20V@1kHz ~ 5mV@200Hz)

Please help me for this.............

Thank
 

Re: Frequency measurement

Hi,
Like yousafzai suggested, using an op amp circuit will increase the level of your small signals (e.g. 5mv) but will rail for larger signals (e.g. 20V). Depending on your power supply, you can get a clean square wave output if you included the schmitt trigger. I thought about suggesting a zener clipper circuit to bring down the higher level signals but some of the better op amp choices will accept higher voltage inputs without problems. Hope this helps and good luck!
SD
 

Frequency measurement

Hi I think a peak detection rotine canbe done after every sample and could be counted, a timer interrupt after every second could be used to transfer counter value to frequency register and clear it ..
 

Re: Frequency measurement

use a schmitt-trigger 40106 is good
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top