seilda TPMCNTLsta ticks+3lda TPMCNTHsta ticks+2lda TPM_overflow+1sta ticks+1lda TPM_overflowsta tickscli
The problem is between the 'sei' and the 'lda TPMCNTL'. It's conceivable that TPMCNT could overflow between those two instructions. TPM_overflow will then need to be incremented, but it won't because of the 'sei', making the lower 16 bits incoherent with the upper 16 bits. Swapping the instructions doesn't fix it; it just changes the "polarity" of the vulnerability.
Anyone know how to do long timers reliably?
Schwab
Message Edited by rocco on 2007-02-0102:28 PM
sei lda TPMCNTL sta ticks+3 lda TPMCNTH brclr TPMSC_TOF, TPMSC, normal ; Overflow; resample. cli ; Allow interrupt to fire, increment TPM_overflow. sei lda TPMCNTL ; Resample the timer sta ticks+3 lda TPMCNTHnormal: sta ticks+2 lda TPM_overflow+1 sta ticks+1 lda TPM_overflow sta ticks cli rts
In other words, we solve the problem by ignoring it . This approach probably consumes no more time than fancy comparisons against $0000 and/or $FFFF, and probably less. For extra speed, we could increment TPM_overflow and clear TOF inline, rather than letting the ISR actually execute.
Unless anyone sees anything obviously and horribly wrong with this, this is the approach I plan to take.
Schwab