timer0 faster than expected
Hello everyone, I am a but confused with what i'm seeing on my oscilloscope when running my simple timer program I have done. I have attached the code but as a quick summary:
clock - internal clock set at 1Mhz from the configuration bits option list.
timer0 clock source - Fosc/4 (250Khz) (This is correct as I have checked by enabling the clock output pin and measuring on my scope)
8 bit mode
I have written the code to turn on a digital output then start the timer and wait for the interrupt flag to set on overflow before turning off the digital output and resetting the timer. At the moment it is triggered by a pushbutton input.
I would have expected that when using 250KHz clock (Fosc/4), and 4:1 prescaler and the timer incrementing every instruction cycle (the datasheet says that timer0 acts as timer only when using internal clock source and timer mode increments every instruction cycle) that the count rate should be 64uS and the counter will fill up after 256 counts which is 16.38ms.
250,000Hz/4 = 62,500Hz (after prescaler); 62500Hz/4 = 15625Hz (per instruction cycle);
1/15625Hz = 0.000064seconds (64us)
8 bit counter gives 256 increments = 64us * 256 = 0.01638s (16.38ms)
therefore I would expect my digital ouput to be on for approximately the same length of time however on my scope it is only on for 40us. Nothing I do on paper with my calculations makes this number make sense so I must be doing something every obvious wrong. Can someone tell me what is going on?