Go Down

### Topic: Digital input frecuency?? (Read 2231 times)previous topic - next topic

#### nahuelv

##### Feb 10, 2012, 08:45 pm
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

#### MarkT

#1
##### Feb 10, 2012, 09:23 pm
About 4 to 5 us per call to digitalRead I think.  If you need faster then direct port manipulation is available...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#2
##### Feb 10, 2012, 10:35 pm
Take a look at the pulseIn() function also, may do what you need already.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### nahuelv

#3
##### Feb 11, 2012, 12:39 am

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

#### retrolefty

#4
##### Feb 11, 2012, 12:46 am

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

#5
##### Feb 11, 2012, 01:03 am
So combine it with other stuff, maybe like this:
Code: [Select]
`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;}}`
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### ribbery45

#6
##### Aug 27, 2012, 10:09 am
It is assumed that the time measured is small enough that the capacitance, COFFSET, provides a
valid voltage to the A/D Converter.

Go Up

Please enter a valid email to subscribe