| ??? 10/12/03 20:25 Read: times |
#56565 - RE: help me with timer on 89c2051 Responding to: ???'s previous message |
"If you look at the timer interrupt service routine code for a typical ISR you will see that there are a small number of machine cycles of instructions that happen to vector to the ISR and then process the initial part before the timer gets reloaded. This short period will actually cause the timer interrupt to run a bit slower than the 100 Hz rate you are shooting for. This can be compensated for by lowering the above suggested 9246 number."
This is just a sidebar note for systems where there can be a dynamic amount of Timer ISR latency (due to other ISRs, brief periods with interrupts disabled, etc.). I find it useful to let the timer itself assist in "calculating" the latency to avoid time drift. Something like: ;** The reload definition factors in how long the timer is stopped to perform
;* the dynamic reload operation.
;**
RELOAD EQU -(9216-7) ; -((11059200/12/100)-7) = 10ms
Timer0_ISR:
PUSH ACC
PUSH PSW
CLR EA
CLR TR0 ; 1
MOV A,TL0 ; 1
ADD A,#LOW RELOAD ; 1
MOV TL0,A ; 1
MOV A,TH0 ; 1
ADDC A,#HIGH RELOAD ; 1
MOV TH0,A ; 1
SETB TR0 ; 1 = 7~ timer reload compensation.
SETB EA ; 1+1 = 9~ latency added to high
; priority interrupts.
POP PSW
POP ACC
RETI
|



