Continue to Site

# Frequency measurement with microcontroller

Status
Not open for further replies.

#### ctzof

##### Full Member level 3
Hello,

I am working on a new project and I am planning to use a microcontroller. The initial goal is to count incoming frequency of a sine wave by pulses. So I use a timer and I count in 1 ms how many times the sine wave is high and for that I determinate the frequency. In the initial desgin I used an FPGA to implement the timer-counter. Now I want to make the implementation in a microcontroller without any other external chip. The incoming frequency is up to 85 Mhz. The microcontroller should work in automotive grade -40-125°c. I was thinking of using ecap function from ti in picollo microcontrollers for example. But I would like to have more suggestions.

I'm not really familiar with these devices, but from what I read briefly, you've got some limitations. Assuming you use the divide function of the ecap module (divide the incoming signal by 62), you're going to have limited resolution. If the processor runs at 120MHz, and your input frequency is 85MHz, the best you can get is 120/(85/62)=85 samples/cycle. Or, said another way, worse than 1% error. If this is good enough, then you're all set.

Another way to measure frequency is to use the incoming signal to increment a counter. Enable the counter for a fixed amount of time, and let it accumulate lots of input pulses. Then divide the counter value by the enable time to get your frequency. For example, enable the counter for 100milliseconds. If you read out a value of 1,000,000, your input frequency is 10MHz. (1e6/0.1). This method will give you pretty accurate results.

Last edited:

I'm not really familiar with these devices, but from what I read briefly, you've got some limitations. Assuming you use the divide function of the ecap module (divide the incoming signal by 62), you're going to have limited resolution. If the processor runs at 120MHz, and your input frequency is 85MHz, the best you can get is 120/(85/62)=85 samples/cycle. Or, said another way, worse than 1% error. If this is good enough, then you're all set.

Another way to measure frequency is to use the incoming signal to increment a counter. Enable the counter for a fixed amount of time, and let it accumulate lots of input pulses. Then divide the counter value by the enable time to get your frequency. For example, enable the counter for 100milliseconds. If you read out a value of 1,000,000, your input frequency is 10MHz. (1e6/0.1). This method will give you pretty accurate results.

Thanks for the answer. I use exactly the second approach now with the FPGA. I want to switch to a microcontroller. The thing is I dont know if the counter-timer inside the microcontroller can catch a sine wave or pulses with 85 Mhz frequency. Do you have any suggestions? The microcontroller as I wrote has to work in automotive grade -40-125°C.

hello,

on most MCU PIC familly, max freq input is less than 30MHZ
for timer used as counter..
so for higher frequency ,you must use special divider like
MB506 ( divide by 256 up to 1GHz !)
or other high speed logic divider.
and also a large band width amplifier + trigger stage,
if your signal is not ttl level compliant with the MCU input.

hello,

on most MCU PIC familly, max freq input is less than 30MHZ
for timer used as counter..
so for higher frequency ,you must use special divider like
MB506 ( divide by 256 up to 1GHz !)
or other high speed logic divider.
and also a large band width amplifier + trigger stage,
if your signal is not ttl level compliant with the MCU input.

The thing is that I don't want to use any other external ic to perform that. For example I can still use the FPGA with an ip processor to perform the task. I was wondering if there is any availiable microcontroller or SOC with integrated microcontroller and high frequency counter.

The thing is I dont know if the counter-timer inside the microcontroller can catch a sine wave or pulses with 85 Mhz frequency. Do you have any suggestions?

My suggestion would be to read the data sheet and determine if, in fact, the counter-timer CAN work at 85MHz. If it can't then you need some different hardware. Your problem is like saying "I had a Ferrari that could go 300 km/h, but I now have a tractor and I want IT to go 300 km/h".

An 85 MHz counter in a uC is a rather tall expensive order when a prescaler and 4040 binary counter is so cheap.

Have you figured out the accuracy required for your XO or TCXO yet?

So far there is no alternative. I think I can work with a TI Piccolo from what I read from the datasheet there is a 32bit-timer that is running free and its value can be stored each time we have a rising or falling edge of a signal. I can save two times one for the first rising and one for the second rising and use them to calculate the frequency of the signal. There is no need to divide the signal as long we have a system clock that is running at least with the frequency of the signal or more but there is also the option to use a prescaler and work with lower frequency system clock.

Status
Not open for further replies.