Skip to content

Commit

Permalink
Waiting for pulse to start (rising or falling edge) to start timing.
Browse files Browse the repository at this point in the history
  • Loading branch information
damellis committed Nov 8, 2008
1 parent 542a64f commit e79b319
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hardware/cores/arduino/wiring_pulse.c
Expand Up @@ -44,6 +44,11 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
unsigned long numloops = 0;
unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;

// wait for any previous pulse to end
while ((*portInputRegister(port) & bit) == stateMask)
if (numloops++ == maxloops)
return 0;

// wait for the pulse to start
while ((*portInputRegister(port) & bit) != stateMask)
if (numloops++ == maxloops)
Expand Down

0 comments on commit e79b319

Please sign in to comment.