Arduino is Slow

Hi,

my Arduino is very slow. I lose about 20 sec every hours. Why?

void loop() { if(t_start==0) { t_start=millis(); ///first loop - chrono start }

t_now=millis()-t_start;

c=(t_now/10)%100 //cent s=(t_now/1000)%60; //sec m=(t_now/60000)%60; //min h= t_now/3600000;

Serial.print(h); Serial.print(":"); Serial.print(m); Serial.print(":"); Serial.print(s); Serial.print("."); Serial.println(c); }

t_start and t_now are unsigned long.

first of all,

c=(t_now/10)%100;  //cent

Second of all, 12 seconds on 3600 is about 0.33(1/3)% failure, seems right by me. The millis() and micros() functions have a pretty good accuracy, but not 100%. In your function, it has an accuracy of 99.67% which is pretty much what you can get from an arduino without external RTC or web-based time.

Thanks!

stefranz: my Arduino is very slow.

It is not slow. It is just not running at exactly 16 MHz and over a long period of time the error becomes noticeable compared to the greater accuracy of a clock.

...R

The Uno Rev 3 has a resonator (for its clock) part number CSTCE16M0V53-R0. That has an advertised accuracy of +/- 0.5%.

So, say 1% error (+0.5 or -0.5%).

With 86400 seconds in a day, 1% of that would be 864 seconds. So worst case, you might be out by +/- 432 seconds a day.

You say you are about by 20 second every “hours” (do you mean “hour”?) which sounds about right. Working as expected.

Arduino Uno rev 3 boards have pads for a quartz crystal and caps if you are able to do some surface mount solder reworking you can fix this.

For reasons I don't understand they downgraded from quartz to a resonable in the Uno making it hopeless for timekeeping.

MarkT:
For reasons I don’t understand they downgraded from quartz to a resonable in the Uno
making it hopeless for timekeeping.

Money perhaps? I can understand they used somewhat cheaper components that have a bigger tolerance to keep the costs down (For us, the end users…)

What's your Serial speed, I bet it slows you down.

YemSalat: What's your Serial speed, I bet it slows you down.

Has no effect on millis(), only how often the sketch prints the time.

Stefranz, you could tune those dividers you use to reflect the true speed of your CPU. I think you would have to calculate hours and true remainder to get minutes then seconds, but you can be within millis per day as long as the board temperature is stable. Hey with the on-chip thermometer you might even be able to get around warming/cooling changing the resonator.

If you make your own breadboard duino you can use a crystal, have a clock and keep your dev board too. http://www.gammon.com.au/breadboard

But before we go on and on on how to fix the timing, i'd like to ask @Stefranz if it is necessary? Was the OP's question a problem or just something he/she liked to know?

  1. Sorry for my english! I’m back at work today.

  2. c=(t_now/10); :frowning:

  3. I try to do a stopwatch lap timer and my first question is do a good chronomether. 12 sec every 3600 => about 0,2 sec every min, is too big!!!

I I thought that quartz was much more accurate!

RTC module is more accurate, or is better read the time from the string of gps module?

The uno doesn't have a quartz crystal.

It has a resonator, which is only accurate to +/-0.5%. A crystal would be more accurate.

A cheap real time clock module is as good as an electronic watch as long as it has power. They cost a few $ if that on eBay. Try search on rtc arduino

OK! Thank you all. I'll try with RTC module!