Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Frequency measurement with microcontroller

Status
Not open for further replies.

ctzof

Full Member level 3
Joined
Mar 1, 2012
Messages
157
Helped
12
Reputation
24
Reaction score
11
Trophy points
1,298
Location
Munich
Activity points
2,516
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.
 

barry

Advanced Member level 5
Joined
Mar 31, 2005
Messages
4,906
Helped
1,072
Reputation
2,154
Reaction score
1,062
Trophy points
1,393
Location
California, USA
Activity points
26,810
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:

ctzof

Full Member level 3
Joined
Mar 1, 2012
Messages
157
Helped
12
Reputation
24
Reaction score
11
Trophy points
1,298
Location
Munich
Activity points
2,516
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.
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,382
Helped
279
Reputation
558
Reaction score
268
Trophy points
1,363
Location
France 01800
Activity points
9,670
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.
 

ctzof

Full Member level 3
Joined
Mar 1, 2012
Messages
157
Helped
12
Reputation
24
Reaction score
11
Trophy points
1,298
Location
Munich
Activity points
2,516
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.
 

barry

Advanced Member level 5
Joined
Mar 31, 2005
Messages
4,906
Helped
1,072
Reputation
2,154
Reaction score
1,062
Trophy points
1,393
Location
California, USA
Activity points
26,810
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".
 

SunnySkyguy

Advanced Member level 5
Joined
Sep 26, 2007
Messages
6,743
Helped
1,675
Reputation
3,348
Reaction score
1,643
Trophy points
1,413
Location
Richmond Hill, ON, Canada
Activity points
50,727
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?
 

ctzof

Full Member level 3
Joined
Mar 1, 2012
Messages
157
Helped
12
Reputation
24
Reaction score
11
Trophy points
1,298
Location
Munich
Activity points
2,516
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top