Sub micro timing

Status
Not open for further replies.

janbor

Active member
Hello. I need a timing that is more accurate than micros(). That is; I need to wait for a duration of 0 to 1 full second doing nothing, and then at a given time call a function. I know beforehand for how long I must wait, but I need the timing to be more accurate than 1 microsecond. I suspect this is possible as the IntervalTimer can do interrupts every 1 microsecond quite accurately, but how do I do it?

Sincerely, Jan
 
Maybe IntervalTimer can help. The input parameter is a floating point number, so it automatically accept any fraction of a microsecond and converts to the correct number of clock cycles.

However, if you try to interrupt too rapidly, you'll burn up all the CPU time simply getting in and out of your ISR function.

To achieve good timing, you'll also need to increase the priority of your interrupt above all others. For extreme precision, you'll also need to avoid flash memory. Details here:

https://forum.pjrc.com/threads/27690-IntervalTimer-is-not-precise?p=64142&viewfull=1#post64142
 
Do you mean something like this:

IntervalTimer timer.
double waittime = 0.98765432; // seconds with 10 ns resolution

setup() {
timer.priority(0);
}

FASTRUN void callBack() {
function();
timer.end();
}

main() {
..
do whatever...
..
timer.begin( callBack,1.0e6 * waittime );
delay(1e3 * waittime);
}
 
Status
Not open for further replies.
Back
Top