Hi guys, I built a simple clock using a mega8 and a character display. However, I have noticed that it is always off. I am using the internal clock and noticed that at the 300s mark (5 min) i am a little over 2 second ahead of my stopwatch.
Is it possible to get a stable clock source on a AVR using the internal clock ?
I am currently running the most basic version of the program as follows:
include#include #include #include #include "lcd.h" #include uint8_t TimeZuluHr = 0; uint8_t TimeZuluMin =0; uint32_t TimeZuluSec = 0; uint8_t TimeZuluDay = 0; ISR(TIMER1_COMPA_vect) { TimeZuluSec++; } int main(void) { // Settings up da 1 sec timer TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode OCR1A = 15625; // Set CTC compare value to 1Hz at 1MHz AVR clock, with a prescaler of 64 TCCR1B |= ((1 << CS10) | (1 << CS11)); // Start timer at Fcpu/64 TIMSK |= (1 << OCIE1A); // Enable CTC interrupt sei (); // Enable global interrupts // initialize display, cursor off lcd_init(LCD_DISP_ON); char buffer[6]; for (;;) { // loop forever lcd_gotoxy(0,0); itoa(TimeZuluSec, buffer, 10); lcd_puts(buffer); } // end main loop }