Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Measuring frequency in microcontrollers

Status
Not open for further replies.
I have to measure the frequency of a signal. I want to take the case of generic micro controller not specific. There will generally be a input capture mode which gives me an interrupt every transition from high to low or low to high.My question is I have to count to number of such transitions for 1 second and this gives me the frequency of the signal. Is my understanding correct?
 
You need to be far more specific about your requirements - a LOT depends on what frequencies you want to measure, to what resolution, and how fast.

The 'original' PIC based one (from a VERY old application note) uses a hardware counter to read to more than 50MHz, but for low frequencies measures the pulse width rather than frequency (this gives higher accuracy and faster readings).

There's certainly no requirement to use interrupts, unless you want to.
 
OK thank you very much for the reply. First time I am doing frequency measurement, really I started programming without actually understanding. I think it is little harder than I thought. Any suggestions will help me.
 
It is actually very simple - just need to specify the range of frequencies and choose proper MCU which can handle max. spec. frequency, as Nigel wrote. Then use interrupts to count rising/falling edges.

Or, If absolute precision is not required, you can use freq. divider circuits to measure higher frequencies desired MCU is not able to handle.
 
One method would be with a µp like a Picmicro that has a CCP or capture module, you can specify Low to High or vice versa or a combo of each.
Also if you use a 32khz clock crystal for the T1 timer you have the pulse count (frequency) for every 1sec roll over.
Max.
 
My idea is my bus clock is 40mhz and there is a prescaler to the enhanced capture module. So the maximum frequency I can read is 40mhz. There is also a pulse accumulator module, so I will run a separate 1 sec timer and after the rollover I will count the number of pulses which should directly give me frequency. One thing I did not understand is how to measure frequency from pulse width. Is it possible? And also I did not understand how resolution is involved?
 
One thing I did not understand is how to measure frequency from pulse width. Is it possible? And also I did not understand how resolution is involved?
CCP does just this.... Set up to determine the time between two incoming pulses...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top