Understanding micros() in DASH


#1

In Arduino website, micros():

Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds.

Question 1:
If I ran DASH at 120MHz, would I get a 1:1 microsecond resolution?
Or in other words, if micros() returns 3, then that will be
• 4 microsecond in Due/Nano?
• 8 microsecond in LilyPad?
• 3 microsecond in Dash?

Question 2:
• Can DASH sense a pulse at nanoseconds? If yes, what’s the resolution?


#2

The Dash derives micros() from the SysTick peripheral. SysTick is configured to pulse every 1ms, and that supplies the millis() value. The SysTick counts the system clock pulses, which is 8 1/3 ns per tick at 120MHz. So every 120,000 ticks the Systick fires and increments millis(). The micros() takes the current count of the SysTick register to get the fractional millis part.

To get sub-microsecond resolution on a pulse input, you would need to write your own driver for the FlexTimer hardware module and set it in dual capture mode. The counter register is only 16 bits I believe, so there is a trade-off between length of pulse and resolution. You have to set the prescalar such that the counter doesn’t overflow, but that may not give you the resolution you need. Chapter 38 of the processor reference manual describes the many features of the FlexTimer module. Check out this application note also, with 3.8 and 3.9 being applicable to your situation. Also note though that other features of the Dash, such as analogWrite, use the FlexTimer module and modifying a channel register could break PWM output.


#3

@Erik Thanks.

If I’m following your thought process correctly:
120,000 ticks = 1 millisecond
120 ticks = 1 microsecond ?
Thus we can say that micros() in Dashboard has a resolution of 1:1?

For the nanos, the red-flags you raised is enough for a no-go, and I think I can’t get a 1:1 resolution.