i'm using PIC18F452 for a project and had written codes in C with CCS
the calculation i've done for my timer0 interrupt is as follows,
11059200/4=2764800;
2764800/256(8-bit TMR0 register)=10800
10800/16(pre-scaler)=675
therefore, i need to count up to 675, a good round figure for one sec timing
every 1 sec bit generated is accumulated in the main program
my system will generate an output every 24 hours, but i find that this system actually triggers an output about 5-6 seconds earlier every single day. For example, a counter increments from 1 to 86400 (total seconds in a single day) beginning from actual time of 12.00.00 am, and when the total of 86400 overflows, i'm getting an output at 11.59.55 p.m rather than the intended 12.00.00 am
and this is my code for high priority interrupt. there is no other part whereby the interrupt is disabled.
#INT_TIMER0 FAST //Change to fast context saving
void ISR_TMR0 (void) //High priority
{ //triggers every 1.48ms
if (++cnt_sec_timeup == 675) //Execute process list
{
bit_timeout_1s = 1; //set 1s task
cnt_sec_timeup = 0;
}
bit_timeout_1ms = 1;
if (++cnt_1ms == 7) //triggers every 10.3ms
{
bit_timeout_10ms = 1; //set 10ms task
cnt_1ms = 0;
}
}
with crystal 11.0592MHz, i'm able to generate an exact 1second timing theoretically but the as i've found out it actually doesn't so i've put up my enquiry at CCS forum and the boys had come to conclusion that this error is due to the incorrect loading capacitors used. well, i've used a pair of 15pF earlier and i have finally reduced the error to as little as +1 sec difference in two days with a pair of 27pF caps.
i've done some research over the internet regarding loading capacitors, and an article from Microchip is very helpful
the formula they've used to calculate the estimate values to use is as folllows
Cloading = ((C1*C2)/(C1+C2)) + Cstray
what i want know is how do we measure Cstray on the PCB? information has it estimated as 5 to 15pf