Hi,
I have extrange results from pulseIn.
What I have is an IR receiver, from an old home DVD player. I have programmed arduino with interrupt attatch to pin 2 ( where IR data pin is ) and it's OK.
Problem is when I try going through pulseIn.
This is the so simple code:
int irPin = 2; // IR data
volatile unsigned long data;
void setup() {
pinMode( irPin, INPUT );
Serial.begin( 38400 );
Serial.println( "PulseIn testing" );
}
void loop() {
unsigned long current;
while ( pulseIn( irPin, LOW ) == 0 )
{}
Serial.println( "Reading for 30 millis" );
current = millis();
while ( millis() - current < 30 )
{
data = pulseIn( irPin, LOW );
Serial.println( data, DEC );
}
}
As you can see, I wait for a LOW pulse to come and then read durations with pulseIn during 30 milliseconds.
Here is serial log:
Reading for 30 millis
85437501
85375001
85375001
87875001
Reading for 30 millis
164750001
164812501
85812501
0
Question is ... How is possible durations are 85 or 164 MIllions ????? I think pulseIn returns Microseconds ( 1 seconds == 1 Million microseconds ) so it is not possible to have so big numbers in just 30 milliseconds ...
May be I'm wrong about pulseIn return value ??
May be pulseIn returns something smaller than microseconds ?
Should I divide returned value depending on some arduino parameter ?
May I use pulseIn on any arduino PIN ?
I will thank some light on this.