Digital input frecuency??

Hi, my name is Nahuel and I want to make a proyect. I have digital pulses of 50microsec of duration that came from a detector. It's not regular pulses, the only thing that I know is that the signal will be in high for 50micosec but could be 100 pulses in 1s or 3 pulses in 1s. I wan't to make a counter that say's the number of pulses in one second. I don't know how fast is the digital read, how many samples it takes?

Thanks and sorry for my English

About 4 to 5 us per call to digitalRead I think. If you need faster then direct port manipulation is available...

Take a look at the pulseIn() function also, may do what you need already.

CrossRoads:
Take a look at the pulseIn() function also, may do what you need already.

YEEEEAHHHH, Thank's CrossRoads :slight_smile:

CrossRoads:
Take a look at the pulseIn() function also, may do what you need already.

Not sure that will work. He already knows the width (50usec) of the pulses, he wants to know how many pulses occur in a fixed timed sampling period.

Lefty

So combine it with other stuff, maybe like this:

void loop()
{
if ( digitalRead (startPin) == 0 ){
startTime = micros();
timeRunning = 1;
}
if (timeRunning == 1 & (micros() < (startTime + duration) ){
if ( pulseIn(pin, HIGH)){
pulsecount = pulsecount +1;
}
if (timeRunning == 1 & (micros() > (startTime + duration) ){
timeRunning = 0;
serial.print ("number of pulses ");
serial.print ln (pulsecount);
serial.print ("frequency = ");
float frequency = duration/pulsecount;
serial.println (frequency);
pulsecount = 0;
}
}

It is assumed that the time measured is small enough that the capacitance, COFFSET, provides a
valid voltage to the A/D Converter.