Made project with pic18f452 microcontroller. Timer1 module used as a real time clock with 32768kHz crystal and 33pF caps connected to microcontroller's Timer1 oscillator pins. Problem is that clock is not accurate, it makes about 4sec/day delay. Changed crystal, but this didnt helped. Tried to reroute PCB, this also not helped. I suspect maybe my clock routine is wrong? Here it is:
Can clock inaccuracy occur due to permanent writing to TMR1h register? (TMR1L register is never changed.) Any ideas and suggestions?
Rich (BB code):
if(PIR1.TMR1IF==1)
{
TMR1H=252;
if(FourthHertz<3){FourthHertz++; Blinker=1;} //count to four, that is to 1 second and invert variable state for text blinking
else
{
FourthHertz=0; Blinker=0;
if(Seconds<59){Seconds++;}
else
{
Seconds=0;
if(Minutes<59){Minutes++;}
else
{
Minutes=0;
if(Hours<23){Hours++;}
else{Hours=0; if(Day<6){Day++;} else {Day=0;}}
}
}
}
PIR1.TMR1IF=0; //clear timer1 interrupt flag
}
Last edited: