With the code I posted in the Example Section (referenced above), the goal was to give the user as much time as possible to do other stuff before needing to update the LCD display, so I went with a 256 prescaler.

Most TMR0 timers are 8 bit, meaning 256 instructions per flag rollover. A 4.000 Mhz crystal gives a 1.000 uS instruction (uS=microSecond). This means the default time for TMRO to rollover is 256 uS.

The prescaler increases the TMR0 rollover Flag time:
Prescale 2 – rollover flag is 2 * 256 = 512 uS
Prescale 8 – rollover flag is 8 * 256 = 2048 uS
Prescale 256 - rollover flag is 256 * 256 = 65536 uS.

At 1.000 uS per instruction, there are 1,000,000 instructions per second. If you do not use a prescaler, then TMRO overflows 1,000,000/256=3906.25 times per second. In code, you just need to keep track of 3906.25 overflows, and 1 second has passed.

If you use a prescaler of 256, then TMR0 overflows 1,000,000/65,636 = 15.235541 times per second.

Because neither of these divisions give integers, some people preload the TMRO to start at a given time rather than 0. You can do this but it is more work - it also takes processor time to load the timer which must be adjusted out in order to maintain high accuracy. See Melanie's code (referenced above) for a perfect example of how to make this approach work.

Since my code allows for colon blink, I tracked 0.5 second time intervals rather than 1.0 second time intervals. Details of the TMRO overflow tracking and math involved are in the code comments at the bottom of the post in the Code Examples Section. The approach I used does not require preloading the timer, but does require keeping track of the residual from the timer overflows (and leads to zero error).

Again, Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA