Pages: [1]   Go Down
Author Topic: Arduino Due micros() resolution  (Read 937 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8443
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

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

Offline Offline
Newbie
*
Karma: 1
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

The Netherlands
Offline Offline
Full Member
***
Karma: 1
Posts: 123
MKDS hacker and Programmer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to have more preciesely timing, you can better use:
Code:
asm("nop");
It's equal to 1/84000000 seconds.
Logged

Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

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

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

Thanks to all who replied.
Logged

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

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:
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. smiley-razz

//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.
« Last Edit: May 16, 2013, 04:22:48 pm by Rebellos » Logged

Pages: [1]   Go Up
Jump to: