I'm pretty sure Microchip has an app note on this very thing. I can't remember if the old 16F54 has a TMR0.IF (which would make it easy)
Use something modern if you can like a 16F627 or 16F88
I may be wrong, but it strikes me that your loop is very likely to be in the wrong place when that timer hits zero, and will miss it completely fairly often.
I may be wrong, but it strikes me that your loop is very likely to be in the wrong place when that timer hits zero, and will miss it completely fairly often.
You only need to write code to catch it "near" zero. It won't be absolutely accurate, but better than totally missing the end sometimes/often. But the loop still has to be tiny and fast or else you just make your problem worse.
You only need to write code to catch it "near" zero. It won't be absolutely accurate, but better than totally missing the end sometimes/often. But the loop still has to be tiny and fast or else you just make your problem worse.
Hi kchriste my process routine is very small.It takes below 20uS time.
But every TMR0 overflows this process routine cylcles may vary like 17uS,19uS etcc...but maximum it takes 20uS time.[/quote]
In this case you should be fine. With your prescaler setting of 128 the TMR0 register will contain a value of '0' for a full 128 cycles (128 usecs). That's more than enough time to sample it at a value of '0' and perform your Process. You just need to make sure you don't process that '0' value multiple times (grin)...