Go Down

Topic: Accuracy of Arduino delay() command (Read 5 times) previous topic - next topic

Fudge

Hello all. Not sure if this is in the correct place, sorry if it's not...

I have been searching for a few hours on this, but cannot seem to find a reasonable answer to this.

Basically, I am doing a assignment and am using short(ish) pulses, from 1ms to 100ms. I have two questions:


  • Is there any way to get shorter pulses, such as 0.5 or even 0.2ms pulses?

and
  • how accurate is the pulse command?



The first one is not crucial, I can live with 1ms pulses.

However, as this is a formal lab report, I need to state my error margins. To what extent is the delay command accurate? I would imagine something like 0.01ms, however I really have no clue on what it might be.

Any help would be greatly appreciated.

Thanks in advance,
Fudge.

Coding Badly

Quote
Is there any way to get shorter pulses, such as 0.5 or even 0.2ms pulses?


delayMicroseconds

Quote
how accurate is the pulse command?


Which "pulse commnad"?  pulseIn?

Fudge

Oops... my bad. Proofreading failure.

By pulse command, I meant delay. Basically, my code turns on, delays for however many milliseconds, then turns off. How accurate is the delay command?

robtillaart


for shorter pulses you may need to use direct port manipulation as digitalWrite itself takes some time too. Or use digitalWriteFast (google for it on the forum) which does just that but works only for fixed pins.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Coding Badly

Quote
How accurate is the delay command?


For long time spans, it is very accurate.  For short time spans, not so much.  Given your concern for accuracy, you should be using delayMicroseconds and, as @robtillaart mentioned, direct port manipulation.

Go Up