Pages: [1]   Go Down
Author Topic: Digital input frecuency??  (Read 1427 times)
0 Members and 1 Guest are viewing this topic.
Lanus
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Shannon Member
****
Karma: 215
Posts: 12463
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Lanus
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Take a look at the pulseIn() function also, may do what you need already.
YEEEEAHHHH, Thank's CrossRoads   smiley
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So combine it with other stuff, maybe like this:
Code:
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;
}
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: