bsodmike
New Member
Code:
Delay movlw d'39' ; load this to the timer
Loop btfss _intcon,2 ; if tmr0 overflow is not set
goto Loop ; loop, else skip
bcf _intcon,2 ; clear the timer interrupt flag
decfsz w,w ; loop until the wreg is zero
goto Loop ; it isn't zero so loop
return ; zero, so we return
Not sure why this doesn't seem to work. My thinking is as follows:
Clock speed of 4000000Hz/4 = 1000000hz
This 1/4th value is further divided by my pre-scaler of choice /256: 1000000hz/256 = 3906.25hz
3906.25 pulses take 1 second - so to count 10ms delay we need to count when this has tripped over 39 times. To prove this 1/3906.25 = 2.56x10-4 * 39 = 9.98ms.
Right or wrong? Is there anything else needed to get the TMR0 overflow to work?
Thanks,
Mike