The micros() documentation notes that the return value will always be a multiple of 4.
Is there any way to get a higher resolution microsecond click, preferably down to the 1 microsecond level?
Dropping down to the AVR level is acceptable.
|
|
Yes, depending your Arduino's basic clock rate. For example here are the counter-timer input frequencies and periods after pre-scaling, for an ATMega2560's counter-timer 2, and a basic clock rate of 16MHz:
The resulting interrupt rate would be: 16MHz / (prescaler * (255 - TCNT2)) You could get the timer to run at the full 16MHz (62.5nSec) though that's way faster than you need; 2MHz with an initial count of (255-2) would give you 1MHz interrupt rate. Divide that by 2 in your ISR:
The data sheet for your MCU is the basic resource; this article will give you (and gave me!) a good head-start. |
|||
|
|
|
If dropping down to AVR Level is acceptable (as you mentioned in your question), you can set up a timer and even get the ticks of the AVR's clock. You need to refer to your AVR's datasheet because it differs within the different ATMegas and ATTinys. But the procedure is always the same. What you need to do is:
That way can get the exact ticks from the timer register, however you need to count the overflows manually. This is as precise as possible by technology. Here is some example code for the outdated AT90S2313, but it gives you good hints what to do basically:
|
|||||||||
|