Go Down

Topic: Very simple lcd clock to test the internal clock accuracy (no RTC) (Read 1 time) previous topic - next topic

I needed to check the accuracy of the internal clock of Arduino for another project, so I wrote this code. Only Time and LiquidCrystal libraries are included. Not that fancy but the accuracy turned out to be fine. Error<1 min for a day. With addition of a few buttons, you can set the time. Yet I am not sure if powering the board with USB or 9V battery would change the accuracy or not. I would appreciate any comments on that.

Cheers,
Bb


Code: [Select]

#include <Time.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//set the current time here
int s=30;
int h=0;
int m=5;

void setup(){
  lcd.begin (16,2);
  delay(500); 
  lcd.clear();
  lcd.print("Current Time:");
  lcd.setCursor(0,1); 
}

void clc(){
  lcd.clear();
  lcd.home();
  lcd.print("Current Time:");
  lcd.setCursor(0,1);
}

void loop(){
 
  lcd.setCursor(0,1);
  while(millis()%1000 != 0);
  s +=1;
  if(s==60){ s=0; m +=1;}
  if(m==60){ m=0; h +=1;clc();}
  if(h==24){h=1;}
 
  lcd.print(int(h/10));
  lcd.print(h%10);
  lcd.print(":");
  lcd.print(int(m/10));
  lcd.print(m%10);
  lcd.print(":");
  lcd.print(int(s/10));
  lcd.print(s%10);
}


Udo Klein

The clock accuracy is almost completely independent of the power. I have investigated this quite a lot. If you need better accuracy the best way is to use a external time signal like GPS or DCF77 or whatever else is available in your country. If you need an internal clock DS3232 is a superior RTC chip.

You can find my clock investigations here:
http://blog.blinkenlight.net/experiments/measurements/crystal-deviations/
http://blog.blinkenlight.net/experiments/measurements/crystal-deviations-2/
http://blog.blinkenlight.net/2013/01/01/dcf77-project-part-1-get-ready-for-the-real-thing/
Check out my experiments http://blog.blinkenlight.net

sbright33

You can calibrate your internal clock using GPS within minutes of effort.  Once you adjust the frequency in software it is very accurate until you make a significant change in temperature.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Udo Klein

Depending on the crystall cut the impact of temperature may be 2ppm / Fahrenheit or more. A typcial reason for a "significant change" in temperature is switching on or off. With other words: unless you have temperature control GPS calibration will not help to much.
Check out my experiments http://blog.blinkenlight.net

Go Up