delayMicroseconds broken?

Status
Not open for further replies.
Writing a simple pin state toggle loop with delayMicroseconds() and then observing the pin state with an oscilloscope would have given you the answer: It is not broken and it never has been.

External third party stuff is not forcibly reliable...

There might be cases where these delay() and delayMicroseconds() functions which exist mainly to make the Teensy processors Arduino-compatible, might not be precise. But that is not Teensy specific since on every processor, everything about timing depends on the CPU load, interrupt priorities and other stuff running in the background. So, it's up to you as a software developer to make sure that either your code will not affect these delay functions or, better, to not to use these when timing is critical. In these cases, using integrated MCU hardware like the PDB, PITs, or FTMs to get an independent timing control, are the more professional solution.

I for myself decided long time ago to make use of these Arduino functions as few as possible. Very often, there are more efficient solutions if you develop for one specific MCU, using its reference manual and using its specific hardware and registers, instead of using functions which are written to give a maximum of compatibility with a bunch of different platforms.

In the code example which you linked in your post, the delayMicroseconds() is used to slowly ramp up the DAC output level in order to prevent a "plop" before the audio generation starts. At this point, where just the DAC has been initialized but no heavy background activity is started, there is really no reason why it should be broken.
 
Last edited:
What could the author be referring to?

Maybe try asking the author, by posting this question as a comment on the hackaday.io site?

And yes, delayMicroseconds() does indeed work. It uses the same busy loop approach as Arduino's function, with all the same limitations, for best compatibility with the many Arduino programs and libraries using it.
 
It uses the same busy loop approach as Arduino's function, with all the same limitations, for best compatibility with the many Arduino programs and libraries using it.
Thanks for the explanation!

Also thanks to @Theremingenieur for the suggestions! I am now considering alternative solutions.
 
Status
Not open for further replies.
Back
Top