Go Down

Topic: DUE Scheduler DelayMicros() (Read 1 time) previous topic - next topic


I cant get the the scheduler.h library to work with delayMicros(), it only seems to work with delay() -milliseconds.

Is there some way to fix this? I need to parallel process both live analog inputs and heavy processing at the same time.
Using delay() and yield() worked like a charm until i realized that I need a delay of exactly 1/2 millisecond.



After some searching, I found the delay() function in ..\hardware\arduino\avr\cores\arduino\wiring.c
There can see that it simply uses the yield() function on increments of microseconds.

Below is my version which preforms delayMicros() that is Scheduler.h library compliant.

void delayMicros_Sch(unsigned long us)
   unsigned long start = (unsigned long)micros();
   while (true) {
      if ((unsigned long)micros() - start >= us)

You may want to have it increment/decrement on multiples of microseconds since the function micros() is has an inaccuracy of several microseconds. Also, it may avoid wasted CPU cycles on this task.

Go Up