Pages: [1]   Go Down
Author Topic: DUE Scheduler DelayMicros()  (Read 505 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Question:
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.

Thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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) {
      yield();
      if ((unsigned long)micros() - start >= us)
                      break;
      }
}


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.
Logged

Pages: [1]   Go Up
Jump to: