I want to build a digital clock without other components or third party modules like RTC or something else. Thank you and I appreciate your tips.
Are you building a clock. Accuracy is relative.
laubiacastle:
I want to build a digital clock without other components or third party modules like RTC or something else.
If you have WiFi near, then build it with some ESP8266 module/board.
ESP-12 (module) or WeMos D1 mini (complete board with ESP-12).
Can pull time of the internet (NTP) every hour or so, like your PC/laptop, and is crystal controlled for stable time in between.
Leo..
How often do you want to correct the time because it’s wrong?
Once a day?
Once a week?
Once a month?
Once a year?
As wolframore said, it’s all about accuracy. A typical crystal controlled AVR should be good for about +/-0.005% accuracy. That’s about two minutes a month. But, common AVR based Arduinos don’t have crystals, they have ceramic resonators, no where as good as a crystal for stability.
laubiacastle:
I want to build a digital clock without other components or third party modules like RTC or something else. Thank you and I appreciate your tips.
Strange question really.
An ATMega328P and crystal wont do much 'without other components' you will need to add;
Power supply
Connectors
Capacitors
Wire
Display of some sort
Resistors probably etc.
An RTC is the obvious component to use for a digital clock so what is youir specific reason for building one without ?
Is this a real project or an academic exersize ?
You could replace the Arduino's resonator or existing crystal with an accurate crystal, but it will be expensive and still subject to drift with temperature change.
Much easier, cheaper and more accurate to use a DS3231 module.
I can understand why you don’t want to use a $2.50 RTC, ‘NOT!’
Is there a professor telling you to do this so she/he can watch people sweat?
larryd:
I can understand why you don’t want to use a $2.50 RTC, ‘NOT!’Is there a professor telling you to do this so she/he can watch people sweat?
LOL. Not really. The thing is that I am learning and I thought to solve the accuracy with just a big crystal like 18.432MHz but I'm wrong. And of course my project concist in a circuit with capacitors, buttons, voltage regulators, etc.
Try this simple count up clock, see if it has the accuracy you need.
unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedTime;
// Initial time to start, adjust as needed.
byte hundredths;
byte tenths;
byte oldTenths;
byte secondsOnes = 0;
byte oldSecondsOnes;
byte secondsTens = 0;
byte minutesOnes = 2;
byte minutesTens = 3;
byte hoursOnes = 4;
byte hoursTens = 0;
void setup() {
Serial.begin(115200); // make serial monitor match
Serial.println ("Setup Done");
}
void loop() {
currentMicros = micros();
// how long's it been?
elapsedTime = currentMicros - previousMicros;
if ( elapsedTime >= 10000UL) { // 0.01 second passed? Update the timers
previousMicros = previousMicros + 10000UL;
hundredths = hundredths + 1; // increment
if (hundredths >= 10) {
hundredths = 0; // else rollover and increment next digit
tenths = tenths + 1;
if (tenths >= 10) {
tenths = 0;
secondsOnes = secondsOnes + 1;
if (secondsOnes >= 10) {
secondsOnes = 0;
secondsTens = secondsTens + 1;
if (secondsTens >= 6) {
secondsTens = 0;
minutesOnes = minutesOnes + 1;
if (minutesOnes >= 10) {
minutesOnes = 0;
minutesTens = minutesTens + 1;
if (minutesTens >= 6 ) {
minutesTens = 0;
hoursOnes = hoursOnes + 1;
if ((hoursTens == 2) && (hoursOnes == 4)) {
hoursOnes = 0;
hoursTens = 0;
}// hours total rollover check
if (hoursOnes >= 10) {
hoursOnes = 0;
hoursTens = hoursTens + 1;
} // hoursOnes rollover check
} // minutesTens rollover check
} // minutesOnes rollover check
} // secondsTens rollover check
} // secondsOnes rollover check
} // tenths rollover check
} // hundredths rollover check
}// hundredths passing check
if (oldTenths != tenths) { // show the elapsed time
oldTenths = tenths;
Serial.print(hoursTens);
Serial.print(hoursOnes);
Serial.print(":");
Serial.print(minutesTens);
Serial.print(minutesOnes);
Serial.print(":");
Serial.print(secondsTens);
Serial.print(secondsOnes);
Serial.print(".");
Serial.println (tenths);
} // end one second check
} // end loop
[/code[
jremington:
You could replace the Arduino's resonator or existing crystal with an accurate crystal, but it will be expensive and still subject to drift with temperature change.Much easier, cheaper and more accurate to use a DS3231 module.
A few pence for 10ppm SMT crystals these days...
Perhaps he means "expensive" in terms of damaging boards.
larryd:
I can understand why you don’t want to use a $2.50 RTC, ‘NOT!’Is there a professor telling you to do this so she/he can watch people sweat?
I cannot understand why you want to use a $2.50 RTC so badly. If a crystal is used as the main clock the precision should be the same as "normal" RTC. The code to use a RTC is not so much shorter (or faster) than counting time in SW - and Arduino already have the millis function. If precision is the only requirement saving cost (money, HW complexity) of a RTC is well justified.
DS3231 would give better precision - but we don't know OP's target so we may only guess if it is needed.