Using the polling method the "stability" will be dependent on the duration of the main loop.
Absolute on and off is easy, set or clear the output
if you use a PR value so TMR2IF sets 10 times per period, you can use a counter to decide when to turn the output on/off
Again accuracy will depend on loop duration, but running at 8Mhz will more then likely be plenty fast enough to give you a barely noticable error.
Ok some math and assumptions:
lets assume you have 1000 ASM lines to process for each loop. That would take .5msec.
If you output is 100 Hz, thats 10 msec. So with these numbers, I guess you could be off by 5% on the duty cycle. Hmmm... Not so good. But 1000 lines is HUGE. Also you could check the count in 5 evenly spaced places throughout your main, then the possible error would only be 1%. In case I have stated this wrong, I mean to say 10% duty could be 11%, or 90% could be 91%. So I guess I don't mean duty cycle % error, I really mean the time it takes to get to the next counter check.
Hopefully I have not confused you or anyone else too badly.
If you need utmost accuracy, use interupts![]()
Bookmarks