Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system
Summary
Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons this needed to be reduced by a factor of 10 to about 25us. It is possible to achieve quite accurate timing on your embedded software system using a PIC, however it can take a bit of work to tune things. This it makes it difficult to know what values to put into the registers to get an accurate overflow period – you end up trying to account for the interrupt latency and counting assembly instructions in the interrupt handler to estimate times etc. Have a look here if you need help in figuring how to setup Timer2 for your desired timing parameters – it’s very handy! Once Timer2 is initialised in this manner, it will cycle automatically without the need to reload any values yielding a stable (and hopefully more accurate) time period.