i have written this test program to become more familiar with the timer0 module. The only problem is that according to my calulations from the calculator that was posted on this thread the timer should throw and interrupt every 1 ms and then every 1000 roll overs it should increment the seconds variable +1 so my counter counts in seconds. with the code below this should keep the led on for 5 seconds. but im only getting the led to stay on for 320ms. Why is the timing so far off from what i calculated?


'Definitions'
DEFINE OSC 3
DEFINE ADC_BITS 10 ' set number of bits in result
DEFINE ADC_CLOCK 3 ' set clock source
DEFINE ADC_SAMPLEUS 50 ' set sampling time for microseconds
'Definitions'

'Register Initializations'
ADCON0 = %10001011 ' set as right justified and turn on AD
ANSEL = %01001100 ' A to D on AN2 and AN3
CMCON = %00000111 ' set all pins to digital
TRISIO = %00011111 ' define Inputs and Outputs
GPIO = %00000000 ' set all pin states to off
WPU = %00000000 ' shut off weak pull ups
OPTION_REG = %01010001 ' set the tmr 0 to prescale of 1:4 for 1ms roll over
INTCON = %10100000 ' ENABLE THE TMR0 INTERRUPTS
'Register Initializations'


'Variables'
LED VAR GPIO.5
i var word
ROLLCOUNT VAR WORD
ROLLOVER_COUNTER VAR WORD
SECONDS VAR WORD
'Variables'

ON INTERRUPT GOTO ROLL_OVER
INITIALIZE:
for i = 0 to 50
pause 10
next i

LED = 1
ROLLOVER_COUNTER = 0
SECONDS = 0

MAIN:
IF SECONDS = 5 THEN LED_OFF

GOTO MAIN

LED_OFF:
LED = 0
ROLLOVER_COUNTER = 0
SECONDS = 0
GOTO INITIALIZE

DISABLE
ROLL_OVER:
ROLLOVER_COUNTER = ROLLOVER_COUNTER + 1 ' INCREMENT ROLL COUNT 1 EVERY 1 ms
IF ROLLOVER_COUNTER >= 1000 THEN 'created to count seconds instead of ms
SECONDS = SECONDS + 1
ROLLOVER_COUNTER = 0
ENDIF
INTCON.2 = 1
RESUME
ENABLE