---------- > From: John Payson > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: TMR0 interrupt (PIC16c84 and PWM) > Date: Monday, 19 May 1997 09:58 > > > Just for a start, DON'T re-enable GIE inside the ISR. The RETFIE > > instruction does this automagically, and, if you have had an int whilst > > processing the isr, you'll blow your stack really quickly this way. This > > is the sort of thing a simulator will probably never find, BTW, as its very > > time-sensitive. > > As a slight clarification, never enable GIE within an ISR unless you are > absolutely sure you know what you're doing *AND* you have counted up the > stack overhead. I have on a couple of programs used a short ISR which ran, > essentially, this: > > [ save W and PSW ] > [ do a little bit of work] > [ restore W and PSW ] > decfsz counter,f > retfie > bsf gie > [ save W and PSW to another pair of locations] > [ set up counter again] > [ do 'a lot' more work (more than a timer-ticks' worth ] > [ restore PSW and W] > retfie > > My smaller interrupt routine does not make any sub-calls. My larger one > does make one level of calls, but they are "guarded" with disable-timer > interrupt and enable-timer interrupt instructions. > > For applications where an ISR has to do periodic "thinks" but mostly just > keeps a counter or two, I think this approach is an excellent one. Has > anyone else used it? That's an interesting exception to the rule. Must make a note of it. Almost reminds me of Windows background processing MikeS