Using the RTCC on the 16C84

For anyone who is trying to create accurate interrupt times on the pic, you must be aware that when you load the rtcc with a value, the prescaler is cleared to zero. What this means is that when the rtcc reaches 0, and your interrupt service routine starts, the prescaler has continued to accumulate instruction counts. Lets say that it takes a dozen or so counts to finally get around to clearing the interrupt flag, incrementing or decrementing your time counter, and then loading the rtcc with your preload value. The prescaler has been accumulating instruction ticks and will be incrementing the rtcc when it rolls over. However when you preload the rtcc, those ticks get wiped out and reset to zero.

Every interrupt cycle loses time!

The solution is to pick your crystal frequency and your prescaler value such that you never write to the rtcc. It should be allowed to overflow. This way, the prescaler is never cleared to zero and no clock ticks are lost.



Thanks to Jerry Ethridge for this