Go Down

Topic: Arduino Due micros() resolution (Read 1 time) previous topic - next topic


My apologies for being redundant.  I was unable to find the answer with my searches.

Thanks to all who replied.


May 16, 2013, 11:12 pm Last Edit: May 16, 2013, 11:22 pm by Rebellos Reason: 1
There is SoC specific code in Arduino libs, all I used was git clone the repo and "git grep micros":

If you want to have more preciesely timing, you can better use:
Code: [Select]


It's equal to 1/84000000 seconds.

Err... assuming that NOP instruction in program takes exactly 1 tick of core is really brave, and surely OPcodes shouldn't be used for timing purposes without calibrating it to some timer. NOP might even get optimised out during runtime by the core caching mechanism, or it can take few cpu cycles to fetch and "execute" it.
So yeah - been there, done that, so you don't have to. :P

//edit, as a sidenote:
While micros does loop checking system clock tick counter, there's also Sleep function for longer delays (1ms resolution), using Wait For Interrupt - https://github.com/arduino/Arduino/blob/1.5.2/hardware/arduino/sam/system/libsam/source/timetick.c
In embedded machines using the second one is better practice (whenever you don't need better resolution than 1ms) as WFI does put ARM core into sleep, decreasing the power consumption as core is being awaken every 1ms and then being put back to sleep until required delay passes.

Go Up