frequency meter

hi

i want to have frequency meter in my project like this :

Htime=pulseIn(8,HIGH); //read high time
Ltime=pulseIn(8,LOW); //read low time

but i have question :
what will happen if pulse get high and do not be low for long time ?

i want to measure 50khz to 200khz ! and this part shouldnt take time more than 5ms !

sorry i am noob

thank you for your help
best regards

payam2000:
i want to measure 50khz to 200khz !

What accuracy do you require?

The code in this bears a remarkable similarity to the snippet in the OP: Arduino Frequency Counter Tutorial with Circuit Diagrams & Code

It makes this quite remarkable claim also:

This Frequency Meter can measure frequencies up to 1 MHz.

Edit:

PulseIn() has this performance from here :

The timing of this function has been determined empirically and will probably show errors in longer pulses. Works on pulses from 10 microseconds to 3 minutes in length.

aarg:
What accuracy do you require?

i dont need high accuracy ! i will map it 0 to 100 !
just measuring frequency souldnt take more than 5ms

can i use this :
http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-frequency-counter-library/

and set gatetime to 5ms ?

what will happen if pulse get high and do not be low for long time ?

[u]pulseIn()[/u] says you can go up to 3 minutes, or you can set a timeout. (But, you'll need a type long to hold more than 65,535 microseconds. :wink: ).

i want to measure 50khz to 200khz ! and this part shouldnt take time more than 5ms !

If my math is correct, the period of a 50kHz square wave is 0.02mS so that's the longest it can take to "measure" (excluding any processing/calculating or I/O, etc.). In any case, it will NEVER be 5ms if the minimum frequency is 50kHz.

Yes. Use one of the libraries like the one you found or : GitHub - PaulStoffregen/FreqCount: Measures the frequency of a signal by counting the number of pulses during a fixed time. and look at the examples.

The pulseIn() based frequency counters will not work above about 50kHz.

Are you sampling the result every 5mS ?

6v6gt:
Are you sampling the result every 5mS ?

i will sampling result every 100ms but the time it take to measure frequency shouldnt be more than 5 ms !( some times frequency is much lower than 50khz ! i dont need them !

if for example frequency = 10hz it at least take 100ms to measure !! but it shouldnt take that much time !
(i do not need to measure frequency lower than 50khz !

thank you for your help . best regards