Pages: [1]   Go Down
Author Topic: Function Micros and precision  (Read 727 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

I read on arduino.cc/en/reference/micros that I can know the number of microseconds since the Arduino  began running the program.
On my 16 MHz Arduino Uno board, the function has a resolution of four microseconds and less with a 8 MHz board. I found the arduino Due (arduino.cc/en/Main/ArduinoBoardDue)  and it has a 84 MHz clock speed.

Could I have a better resolution than 4 µs ? I would like to have a precision with nanos seconds.

Logged

0
Offline Offline
Shannon Member
****
Karma: 214
Posts: 12406
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code for micros() is quite complex on the Due, I suspect it won't give much better
accuracy.  However the underlying tick count is available fast, its just the accounting
for its overflow that is tricky.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Jr. Member
**
Karma: 2
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

I read on arduino.cc/en/reference/micros that I can know the number of microseconds since the Arduino  began running the program.
On my 16 MHz Arduino Uno board, the function has a resolution of four microseconds and less with a 8 MHz board. I found the arduino Due (arduino.cc/en/Main/ArduinoBoardDue)  and it has a 84 MHz clock speed.

Could I have a better resolution than 4 µs ? I would like to have a precision with nanos seconds.



I have written a code to get resolution on a standard Arduino board (Uno, Nano, Ethernet, etc) down to 0.5us.  It is super easy to implement.  The code and an example can be found here: http://electricrcaircraftguy.blogspot.com/2014/02/Timer2Counter-more-precise-Arduino-micros-function.html

I chose to use the Atmega328 Timer2 (note: it has 3 timers) in order to preserve the functionality of the Servos library, which uses Timer1.  However, if you follow my example of what I am doing to Timer2, and apply it to Timer1, you can get a good timer with resolution down to 62.5 nanoseconds.  As a matter of fact, Timer2 can also have this resolution, but the counter will quickly overflow since it is only 8-bit.  In either case, check out what I've done, and see what you think.

PS. Here is my description of my code:

"I wrote a "libary" to get 0.5us precision on a "micros()" replacement function, so that I can get repeatable results reading a PWM or PPM signal, to within 1us.  I searched all around the internet and could not find something comparable (or that was easy to use, and maintained the Arduino's ability to write PWM signals via the Servo Libary), so I think this is my first real contribution to the world of Arduino and Radio Control." 
http://electricrcaircraftguy.blogspot.com/2014/02/Timer2Counter-more-precise-Arduino-micros-function.html
« Last Edit: February 26, 2014, 12:29:45 am by panther3001 » Logged

Visit my RC aircraft blog at http://electricrcaircraftguy.blogspot.com/

Offline Offline
Jr. Member
**
Karma: 2
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code for micros() is quite complex on the Due, I suspect it won't give much better
accuracy.  However the underlying tick count is available fast, its just the accounting
for its overflow that is tricky.

I am also wondering what the precision is of the micros() function when used on the Due.....
Logged

Visit my RC aircraft blog at http://electricrcaircraftguy.blogspot.com/

Pages: [1]   Go Up
Jump to: