I'm seeing something unexpected in the running time of a Timer2 based delay loop. With the combined prescale, period, and postscale, should be setting TMR2IF at 500Hz? I expect the polling loop below to fall out after approx 2ms. But it's taking closer to 3.8ms* and I can't think of an explanation.
Part is PIC18F6680, Fosc = 40 MHz.
; THIS DOESN'T WORK... ; Timer2 input = Fosc/4 = 10,000,000 Hz ; divide by 1/16 prescale = 625,000 Hz ; divide by period (156) = ~4006 Hz ; divide by 1/8 postscale = ~500 Hz = approx 2ms! delay2ms: ; set up Timer2 movlw b'01110010' ; 1:8 postscale,timer off,1:16 prescale movwf T2CON clrf TMR2 movlw 156 ; 156 x 8 x 16 cycles = ~1996.8us = approx 2ms movwf PR2 bcf PIR1,TMR2IF bsf T2CON,TMR2ON ; start it! btfss PIR1,TMR2IF ; check for timer overflow bra $-2 return*The running time is measured using Timer0, and I have confidence in the correctness of that timer, having verified expected durations for sanity with simple cycle wasting loops.