itsanjan / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

delayMicroseconds(0) delays far longer than expected. #576

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
----------------------------------------

See - http://arduino.cc/forum/index.php/topic,68383.0.html

Due to predecrement of the param us, the function does not work as expected 
when the param is 0.

snippet of the code:

void delayMicroseconds(unsigned int us)
{
   if (--us == 0)
      return;
...

What is the expected output? What do you see instead?
------------------------------------------------------
Expected an immediate return;
See, long busy wait

Please provide any additional information below.
-------------------------------------------------

Fix proposed - 
http://arduino.cc/forum/index.php/topic,68383.msg504892.html#msg504892

replace
   if (--us == 0)
      return;

with (16 Mhz)
   if (us < 2) 
      return;
   us--;

Fix not tested.

Original issue reported on code.google.com by rob.till...@gmail.com on 5 Aug 2011 at 7:49