diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-11-22 23:33:59 -0500 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-11-22 23:33:59 -0500 |
commit | eb9c51d43c451b3e48725d04af519d8a6c36107b (patch) | |
tree | c3b55b5688d873b452b648e6a2cab9d17099e0ec /cores/arduino | |
parent | 6ac63fbadfd25eea9c1b4aa375c238df92ee23cb (diff) |
pulseIn() now times out while measuring the pulse, not just while waiting for it to start.
Diffstat (limited to 'cores/arduino')
-rwxr-xr-x | cores/arduino/wiring_pulse.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/cores/arduino/wiring_pulse.c b/cores/arduino/wiring_pulse.c index 8f232f1..0d96886 100755 --- a/cores/arduino/wiring_pulse.c +++ b/cores/arduino/wiring_pulse.c @@ -55,12 +55,15 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) return 0; // wait for the pulse to stop - while ((*portInputRegister(port) & bit) == stateMask) + while ((*portInputRegister(port) & bit) == stateMask) { + if (numloops++ == maxloops) + return 0; width++; + } // convert the reading to microseconds. The loop has been determined - // to be 10 clock cycles long and have about 16 clocks between the edge + // to be 20 clock cycles long and have about 16 clocks between the edge // and the start of the loop. There will be some error introduced by // the interrupt handlers. - return clockCyclesToMicroseconds(width * 10 + 16); + return clockCyclesToMicroseconds(width * 21 + 16); } |