I'm also assuming that I will need to reload the TMR1H/L register as I exit the interrupt service routine. Correct?
I'm also assuming that I will need to reload the TMR1H/L register as I exit the interrupt service routine. Correct?
Generally no. If you are interrupt driven, and you need an interrupt every 'x' seconds then your ISR would reload the registers with the appropriate values as soon as possible (to insure correct timing). There is no need to reload them upon exit.
In PBP, I normally run in "pseudo-interrupt" mode. I sit in a tight loop polling PIR1.0 until it goes true, clear that bit, reload TMR1H and TMR1L then enter my main routine. After the routine, I go back to the polling mode.
I put all my high-priority items (such as checking the serial port interrupt bit) in the tight loop, and all the normal stuff in the main program. I avoid pauses whenever possible and instead rely on the timer to provide timing information.
Charles Linquist
>Generally no. If you are interrupt driven, and you need an interrupt every 'x' >seconds then your ISR would reload the registers with the appropriate >values as soon as possible (to insure correct timing). There is no need to >reload them upon exit.
That's what I meant...thank you
>In PBP, I normally run in "pseudo-interrupt" mode. I sit in a tight loop >polling PIR1.0 until it goes true, clear that bit, reload TMR1H and TMR1L >then enter my main routine. After the routine, I go back to the polling >mode.
I already have a tight loop polling my serial port looking for a charaacter. Are you saying I can use the timer without having it generate an interrupt?
Hadn't thought about that....That could be quite easy to implement in my code.
Thanks .... chris
Yes, here is a quick code example:
FastLoop:
IF PIR1.0 = 1 THEN
PIR1.0 = 0
TMR1H = TimerPreloadValue.Highbyte
TMR1L = TimerPreloadValue.Lowbyte
GOSUB MainProgram
ENDIF
IF PIR1.5 = 1 THEN
Gosub KeyboardInputRoutine ' HSERIN clears PIR1.5
ENDIF
GOTO FastLoop
MainProgram:
'Do something here every time the timer rolls over
RETURN
' This works perfectly as long as your 'Main Program' never takes as long as the timer period. The code sits in the FastLoop waiting for either a keyboard input or a timer timeout. When the timer timeout occurs, then the MainProgram is executed. If you output data in your MainProgram, that data will be output at a regular interval regarless of the length of your program.
Just remember - stay away from PAUSEs in your main program whenever possible!
Charles Linquist
Bookmarks