Hi Ben,
To over come the Timer Re-load problem. You can ADD the TMR1Reload value to the current TMR1 count, instead of just loading the value and losing the time it took to get there.
This way the frequency will stay the same. Only the rising and falling edges will vary depending on how long it takes to service the interrupt.
The best way to ADD the value in is with a little ASM because it's easier to figure out how long it will take.
Code:
ASM
RST?RP ; Set to BANK0
BCF T1CON,TMR1ON ; Turn off timer
MOVF _TMR1Reload ,W ; 1
ADDWF TMR1L,F ; 1 ; reload timer with correct value
BTFSC STATUS,C ; 1/2
INCF TMR1H,F ; 1
MOVF _TMR1Reload+1,W ; 1
ADDWF TMR1H,F ; 1
BSF T1CON,TMR1ON ; 1 ; Turn TIMER1 back on
ENDASM
This way, you know for sure that it takes 7 cycles to reload the timer. Just add 7 to the TMR1Reload that you already have.
Code:
TMR1Reload = 0 - TMR1Reload + 7
You'll also need to place TMR1Reload in BANK0
Code:
TimerReload VAR WORD BANK0 'Reload value for TMR1
HTH,
Darrel
Bookmarks