The toggle does effectively halve the frequency but neither time or the timer stops during the actual time it takes for the instructions to execute.
Clearing the interrupt flag takes instruction(s), toggle the output takes multiple instructions, reloading the timer takes instruction(s). Each instruction takes time. By the time you're actually presetting the timer to 128 it's already continued counting and you're "pulling it back" ever so slightly every time, so the frequency drops. No secrets, nothing special, just the way it works. Think about it.
Here are two different versions you can try to see which one is the most accurate for your needs, then you can always tweak the value.
Code:
mainloop:
if INTCON.2=1 THEN
TMR0 = 128 'yes work
INTCON.2=0
toggle portb.2
endif
goto mainloop
Code:
mainloop:
if INTCON.2=1 THEN
TMR0 = TMR0 + 128 'yes work
INTCON.2=0
toggle portb.2
endif
goto mainloop
/Henrik.
Bookmarks