Is it possible to use a microcontroller to read an input frequency? Please explain how?
Asked
Active
Viewed 8,353 times
0
-
4Can you give us an idea of the range of input frequencies you wish to measure, as well as the voltage levels and waveform? Are we talking a 100Hz 0-5V square wave or a 350Mhz 120mV peak-to-peak signal? They both necessitate very different handling. – drxzcl Apr 19 '11 at 07:20
-
possible duplicate question: http://electronics.stackexchange.com/questions/2811/measuring-0-1mhz-0-25hz-resolution-squarewave-using-an-mcu – vicatcu Apr 19 '11 at 15:49
-
Which micro controller you are using? if PIC then use TMR0 as counter and count the pulses. – MrAlpha_SU Jan 29 '15 at 04:15
-
Welcome to the site. Please realise this is not a free design house, homework-answering service or an on-line technical encyclopedia, copied out to you on demand. People will help you take the next step if your question shows you've done as much as you possibly could on your own - which yours doesn't, I'm afraid. Please edit your question and greatly improve it. Ask a specific question, showing your work and findings so far in considerable detail with any schematic. The better the quality of question, the better the quality of the answers you will attract. Again, a warm welcome to the site. – TonyM May 13 '18 at 20:40
1 Answers
11
You can use a timer capture to detect edges. If the selected edge of the signal occurs the timer value will be latched and the controller will get an interrupt. Read and store the timer value and wait for the next interrupt. Read the new timer value and subtract the previous one. You now have the signal's period. Calculate 1/period to find frequency.
Notes:
- I'm assuming that you have a decent digital signal
- You'll have to take the timer's overflow(s) into account
- Also make sure that the timer is clocked by an appropriate clock

stevenvh
- 145,145
- 21
- 455
- 667
-
I've followed these instructions and it worked well. Thanks. There are some corner cases when duty cycle is 0% or 100% have you tried to figure out how to detect the wave then? – Mohamed Atef Jan 17 '22 at 05:56