Searching \ for 'Inttrupt routine & another inttrupt?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=inttrupt+routine
Search entire site for: 'Inttrupt routine & another inttrupt?'.

Truncated match.
PICList Thread
'Inttrupt routine & another inttrupt?'
1998\10\21@114548 by Radboud Verberne

flavicon
face
Hi,

Just a question: What happens if your program is doing the inttrupt service
routine and another Intflag getting set? Is the inttrupt directly detected
by the PIC after the retfie instuction?

Greetz,
       Radboud Verberne.
ICQ     : 918640 (I Seek You)
HAM  : PE1RUH

S-Mail: Eerste Vijverstraat 6
       5258 HR Berlicum, The Netherlands
Phone : +31-73-503-4733

1998\10\21@122259 by Harold Hallikainen

picon face
On Wed, 21 Oct 1998 17:34:22 +0200 Radboud Verberne <spam_OUTr.verberneTakeThisOuTspamhsbos.nl>
writes:
>Just a question: What happens if your program is doing the inttrupt
>service routine and another Intflag getting set? Is the inttrupt
directly
>detected by the PIC after the retfie instuction?

       Yes... unless your "main ISR" has not yet dealt with that
interrupt.  My typical interrupt handler has a bunch of btfsz
instructions polling the appropriate interrupt flag bits followed by
calls of the handler for that device.  The end of the routine has the
ertfie.
       You COULD enable interrupts in the ISR and allow interrupts to
interrupt interrupts, but the limited stack depth in the PIC is sure to
cause problems.  There are also reentrancy problems in the ISR code.
       I'm sure that my code often gets an interrupt set after the ISR
has already polled that device, causing an immediate interrupt after the
retfie.  This could be avoided by having the ISR loop 'til none of the
interrupt flags are set, possibly speeding interrupt response time since
you'd only have to save and restore context once.  I haven't had to
resort to this (yet), though.


Harold


Harold Hallikainen
.....haroldKILLspamspam@spam@hallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm


___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
or call Juno at (800) 654-JUNO [654-5866]

1998\10\21@135657 by John Payson

flavicon
face
part 0 3085 bytes
I've done this on some occasions; the PIC's interrupt hardware is
extremely simple, so there's no complex "faking" as can sometimes
be needed on, e.g., an 8x51.

Basically you need to consider that nesting ISR's means two things:

(1) The stack depth of the nesting ISR is in addition to that of the
   current ISR.

(2) Anything the nesting ISR does to registers may bash the underlying
   ISR; either the nesting ISR has to avoid any instructions that may
   affect flags or W, or else you need seperate file registers to
   save W and F for the two interrupts.

Generally, then, the only time that it makes sense to have ISR's nest
is if there's a very simple routine that is allowed to execute during
a longer and more complicated one.  For example, suppose you have a
routine which you would like to execute precisely once every 5000
clock cycles, and which may take over 1000 cycles to execute.  Since
the RTCC's prescalar won't allow timing durations of that sort, and
since writing to the RTCC clears the prescalar (BOO HISS!) the only
option is to use a 1:1 prescalar and deal with the interrupt every
256 cycles (once every 20 interrupts we perform the "real" ISR and
jog the RTCC a bit).

ISR:
               decfsz  Counter,f
                retfie
               bsf             GIE
               movwf           SaveW
               swapf           STATUS,F
               movwf           SaveStat
               movlw           123             ; Jog count by 120; add 3 to dea
l
                                               ; with PIC's synchronizing delay
s
               addwf           RTCC,f
               movlw           20
               addwf           Counter,f
               ... real meat of ISR goes here
               swapf           SaveW,f
               swapf           SaveStat,w
               movwf           STATUS
               swapf           SaveW,w
               retfie

Note that interrupts may be safely nested at any point after the
third instruction; unless twenty interrupts occur before the main
ISR is done the nested interrupts won't disrupt anything.

By the way, when doing nested interrupt stuff like this, it's often
useful to use INCFSZ/DECFSZ in situations where the skip-on-zero is
not needed (provided it won't cause trouble), since unlike INCF/DECF,
they don't set flags.  Also, using BSF and BCF instructions on the
RTCC may be somewhat handy.  For example, if it's desired to have the
ISR execute every 135 cycles this may be accomplished by

               bsf             RTCC,7 ; Skips ahead 128 counts, but drops 3
               decfsz  RTCC,f ; Drops back a count, plus 3 more

While not nearly as clear as:
               movlw           259-135
               addwf           RTCC,f

the approach with "bsf" and "decfsz" has the decided advantage that
it does not affect any flags or W.

In short, nesting ISR's is fine provided that the nested ISR's tread
very lightly.  It takes a bit of getting used to, but allows for some
useful techniques.

1998\10\22@023248 by Dr. Imre Bartfai

flavicon
face
Hi,

Yeah. That's why one can enter into an endless loop when forgetting to
reset the appropriate IF.

Imre


On Wed, 21 Oct 1998, Radboud Verberne wrote:

{Quote hidden}

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...