Go Down

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

yelsewno

I haven't been able to find a definitive answer to this question.  If the prescaler is 64 in the stock Arduino code, thereby making the micros() resolution on 16Mhz boards 4uS, would that make the 84Mhz Due micros() resolution about 0.762uS or 1uS?

Graynomad

One can only assume that the guys writing the code got it right and a function called micros() actually has a resolution of 1uS. If that was not the case I'm sure we would have heard about it by now.

Quote
if the prescaler is 64 in the stock Arduino code,

I'm not familiar with the code but the hardware is totally different, any prescaler referred to in AVR code will have no bearing on ARM code. On an ARM I would think they are reading the systick counter directly.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

yelsewno


any prescaler referred to in AVR code will have no bearing on ARM code


I hadn't even considered that, very good point!

Anybody out there with a Due that can verify micros() returning values other than multiples of 4?

schwingkopf

same question was already answered in this forum a couple of month ago... http://forum.arduino.cc/index.php?topic=147505.msg1108517#msg1108517

micros() returns values that are multiples of 1us

Gericom

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

asm("nop");

It's equal to 1/84000000 seconds.
Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

yelsewno

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

Thanks to all who replied.

Rebellos

#6
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":
https://github.com/arduino/Arduino/blob/1.5.2/hardware/arduino/sam/cores/arduino/wiring.c#L31


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

asm("nop");

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.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489e/Cjafcggi.html
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