Time drift issues

7 views
Skip to first unread message

Rhythmtech

unread,
Mar 8, 2010, 4:52:53 PM3/8/10
to RuggedCircuits
I am timing power on / power off cycles of a motor using an analog
input and a current transducer. Currently I am testing my setup using
a pot to simulate the voltage from the transducer. I use the millis()
function to mark when the power cycles on then subtract the difference
when power goes off. To check the timer I have been using a stopwatch
and am coming up with some discrepancies in the timing. I understand
that there can be some error incurred by human input, but I am seeing
2 seconds of error at 5 min, which is far more than human input error
generally is.

Stop Watch Gator using millis()

10:00.96 9:58.557
5:25.00 5:23.746
3:00.72 3:00.025
1:16.15 1:15.823

Any ideas on how to improve this or another method might be helpful. I
need to be accurate to a tenth of a second.

Rhythmtech

unread,
Mar 8, 2010, 5:28:28 PM3/8/10
to RuggedCircuits
1.25 seconds of error at 5 min...

Rugged Circuits

unread,
Mar 8, 2010, 5:59:52 PM3/8/10
to RuggedCircuits
The millis() function is intended for "loose" timings and I wouldn't
trust it for the kind of precision you're looking for. The way it's
implemented is also not friendly to core frequencies above 16 MHz (the
Gator runs at 20 MHz).

Specifically, on the Gator the millis() function runs too slowly by a
factor of 255/256. Any result from millis() therefore should be scaled
by 256/255 for better accuracy.

Rhythmtech

unread,
Mar 9, 2010, 11:24:29 AM3/9/10
to RuggedCircuits
The scaling appears to be working, I'll take some data to see if it is
a consistent fix. Can you recommend another approach to get better
accuracy? Thanks

Rugged Circuits

unread,
Mar 9, 2010, 8:35:36 PM3/9/10
to RuggedCircuits
On Mar 9, 11:24 am, Rhythmtech <jared.c.cor...@gmail.com> wrote:
> The scaling appears to be working, I'll take some data to see if it is
> a consistent fix. Can you recommend another approach to get better
> accuracy?  Thanks

Please see the 'wiring.c' file uploaded to the Files section of this
group. It hasn't been thoroughly tested but it should fix the problem
with millis() by using a more accurate scheme.

Make a backup of the 'wiring.c' file in your current Arduino directory
(should be in hardware/cores/arduino/wiring.c) and replace it with the
file described above. Then recompile your code.

Rhythmtech

unread,
Mar 10, 2010, 9:14:00 AM3/10/10
to RuggedCircuits
Sounds good, thanks
Reply all
Reply to author
Forward
0 new messages