I have been using PIC BASIC Pro for a long time, however all my applications have been very basic, a range of inputs and range of corresponding outputs,
and a small amount actual processing.

The timings are simply based on a short pause at the start of the main loop with lots of variables incrementing on each loop. The inputs and counter variables are checked during each loop and outputs set when required. So no other pauses required, although various command like serial and A/D are used.

However, when the amount of time counters or the amount of input / outputs start to grow and the lenght of time counting requirements increased (perhaps into days), the accurancy is a problem. Until now i have just measured the error over a couple of hours, then made an adjustment to the loop pause.

But anything that is added into the loop at a later stage or things like serial outputs makes everything go astray, this does not seem like the right method.

I have started to use TMR0 interupts / prescaler, so no pauses in the main loop, just variables incrementing on each interupt.

The next issue was that if i now want to use sleep to save power i am stuck, i believe that TMR0 shares the prescaler with the watchdog, used for sleep, so i would have to use another timer.

Getting to the point, what is the best way to handle all these timings, and if sleep is required, how can this be used when no current pauses are used?

I also understand that sleep (or nap) is not accurate, so if i just used this instead of the interupt method, my problems may be even worse.

I have assumed that the device would go to sleep, wake up via the interupt (which would be accurate), then increment all the counters & check the conditions and set outputs etc. all from inside the interupt rountine.??

Any comments or clarification would be appreciated.

Gordon