Searching \ for '[PIC]: 18Fxx20 Context saving during interrupts' 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/microchip/ints.htm?key=interrupt
Search entire site for: '18Fxx20 Context saving during interrupts'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 18Fxx20 Context saving during interrupts'
2003\02\11@071133 by Graham North

flavicon
face
Hi everyone,

I am converting some 17C756A code to run on a 18F6620 but I'm a little
confused by the context saving during interrupts. In the data book it says:

During an interrupt, the return PC value is saved on the
stack. Additionally, the WREG, STATUS and BSR registers
are saved on the fast return stack. If a fast return
from interrupt is not used (See Section 4.3), the user
may need to save the WREG, STATUS and BSR registers
in software. Depending on the user s application,
other registers may also need to be saved. Example 6-1
saves and restores the WREG, STATUS and BSR registers
during an Interrupt Service Routine.

Is it a good idea to use the fast register stack? Or should I just do it the
old fashioned way?

Thanks

Graham North

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@074709 by Kari Lehikko

flavicon
face
> Is it a good idea to use the fast register stack? Or should I just do it the
> old fashioned way?

I'd say use the automatic stack. It saves you a lot of trouble.

- K

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@081447 by Scott Dattalo

face
flavicon
face
On Tue, 11 Feb 2003, Graham North wrote:

> Hi everyone,
>
> I am converting some 17C756A code to run on a 18F6620 but I'm a little
> confused by the context saving during interrupts. In the data book it says:
>
> During an interrupt, the return PC value is saved on the
> stack. Additionally, the WREG, STATUS and BSR registers
> are saved on the fast return stack. If a fast return
> from interrupt is not used (See Section 4.3), the user
> may need to save the WREG, STATUS and BSR registers
> in software. Depending on the user s application,
> other registers may also need to be saved. Example 6-1
> saves and restores the WREG, STATUS and BSR registers
> during an Interrupt Service Routine.
>
> Is it a good idea to use the fast register stack? Or should I just do it the
> old fashioned way?


Use the Fast Register Stack.

Keep in mind that this stack is only 1-level deep though. This is mainly a
concern if you're using interrupt priorities. Earlier versions of the
18cxxx silicon had a bug with interrupt priorities. So I made it a habit
not to use the priorities at all. Since there are only two priority
levels, it's not extremely useful.

I structure my interrupt routines like so:

       ORG     8


check_TMR0_interrupt:

       BTFSC   INTCON,T0IF             ;If the roll over flag is not set
        BTFSS  INTCON,T0IE             ;or the interrupt is not enabled
         BRA   check_Peripherals       ; Then check the next interrupt

   ;; TMR0 has rolled over. Clear the pending interrupt and perform
   ;; whatever action is necessary for your application:

       BCF     INTCON,T0IF,0           ; Clear the pending interrupt

check_Peripherals
       BTFSS   INTCON,PEIE             ;If peripheral interrupts aren't
        RETFIE 1                       ;enabled then exit.

check_USART_TX_interrupt:
       BTFSC   PIR1,TXIF
        BTFSS  PIE1,TXIE
         BRA   check_USART_RX_interrupt

   ;;  tx stuff

check_USART_RX_interrupt:


       BTFSC   PIR1,RCIF
        BTFSS  PIE1,RCIE
         BRA   check_next_peripheral

   ;;  rx stuff

check_next_peripheral:
   ;; ....

        RETFIE 1                       ;Leave interrupt routine


Scott

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@084230 by Olin Lathrop

face picon face
> I am converting some 17C756A code to run on a 18F6620 but I'm a little
> confused by the context saving during interrupts. In the data book it
says:
>
> During an interrupt, the return PC value is saved on the
> stack. Additionally, the WREG, STATUS and BSR registers
> are saved on the fast return stack. If a fast return
> from interrupt is not used (See Section 4.3), the user
> may need to save the WREG, STATUS and BSR registers
> in software. Depending on the user s application,
> other registers may also need to be saved. Example 6-1
> saves and restores the WREG, STATUS and BSR registers
> during an Interrupt Service Routine.
>
> Is it a good idea to use the fast register stack? Or should I just do it
the
> old fashioned way?

Use it.  That's what it's there for.  It makes getting into and out of an
interrupt faster.

However, note that W, STATUS, and BSR are written to the fast register
stack automatically on every interrupt.  Therefore you can't use it for
low priority interrupts if high priority interrupts are also enabled, and
you can't use it in the rest of the system when any interrupts are
enabled.

The bottom line is use the fast register stack to save/restore W, STATUS,
and BSR for single priority or high priority interrupts, but not low
priority interrupts or anywhere else in the system.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@120527 by Graham North

flavicon
face
Thanks for the replies, but are these the only registers that need saving
during an interupt? Is it not a good idea to save the STATUS register?

Have I been saving to many registers all along?

Thanks

Graham

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@122215 by michael brown

picon face
On Tuesday 11 February 2003 11:03 am, you wrote:
> Thanks for the replies, but are these the only registers that need
> saving during an interupt? Is it not a good idea to save the STATUS
> register?

I recommend that you continue to save (and restore) the STATUS register, unless you like your code to behave as though it came from Redmond.   ;-)

> Have I been saving to many registers all along?

No, probably not.

michael brown

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@122417 by Scott Dattalo

face
flavicon
face
On Tue, 11 Feb 2003, Graham North wrote:

> Thanks for the replies, but are these the only registers that need saving
> during an interupt? Is it not a good idea to save the STATUS register?
>
> Have I been saving to many registers all along?

Since Olin is probably at lunch, I'll answer for him:

  Read the Data Sheet!

:)

After you've scanned through the whole data sheet, go back and read
carefully the section on interrupts. It clearly states what is saved
during the interrupt (and yes, the status register is saved). Also, look
at the CALL instruction and the RETURN/RETFIE. After that, read about the
DAW instruction and join in on the BCD thread :).

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@122620 by

flavicon
face
But STATUS *is* part of the "Fast Register Stack".
Or did I miss something ?

Jan-Erik Söderholm.

Graham North wrote :
>Thanks for the replies, but are these the only registers that need saving
>during an interupt? Is it not a good idea to save the STATUS register?
>
>Have I been saving to many registers all along?

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@131313 by Olin Lathrop

face picon face
> But STATUS *is* part of the "Fast Register Stack".

Yes.

> Or did I miss something ?

Apparently not.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@131322 by Olin Lathrop

face picon face
> Thanks for the replies, but are these the only registers that need
saving
> during an interupt?

That depends on what "these" refers to.

> Is it not a good idea to save the STATUS register?

Yes.

> Have I been saving to many registers all along?

Um, that would depend on what registers you have been saving all along.
It's hard to imagine how you expected people to answer this question
intelligently.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\11@135924 by michael brown

picon face
On Tuesday 11 February 2003 11:21 am, you wrote:
> On Tuesday 11 February 2003 11:03 am, you wrote:
> > Thanks for the replies, but are these the only registers that need
> > saving during an interupt? Is it not a good idea to save the STATUS
> > register?
>
> I recommend that you continue to save (and restore) the STATUS
> register, unless you like your code to behave as though it came from
> Redmond. ;-)
>
> > Have I been saving to many registers all along?
>
> No, probably not.


Oops, I retract what I said, the STATUS *is* saved automatically, so outside of the cases that Olin already clearly outlined, you shouldn't need to save it.  That'll teach me to speak before reading.  ;-)  Sorry.

michael  <:-)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\12@052842 by Graham North

flavicon
face
Sorry guys, wrist slapped. This cold must be bluring my vision :-)

The data book says to use the 'FAST RETURN' instruction to return from an
interrupt to restore the registers saved on the fast register stack. We have
always been told to use the 'RETFIE' instruction to return from interrupts,
which according to the data sheet will restore the registers W, STATUS and
BSR from their corresponding shadow registers (WS, STSTUSS and BSRS), and
more importantly re-enable interrupts. Are these shadow registers the same
as the Fast Register Stack? The 'RETFIE' instruction on the 17C756A only
restored the PC.

The 'FAST RETURN' instruction isn't mentioned in the instruction set in the
data book, I presume the instruction is 'RETURN FAST'. FAST is equated to 1
in the .inc file, and therefore the description of the 'RETURN FAST'
instruction says the registers W, STATUS and BSR are restorde by the value
in their corresponding shadow registers (WS, STSTUSS and BSRS), BUT
interupts are NOT re-enabled (which does make sense).

If you've made it so far then thanks, my question is what instruction should
I use to return from interrupts? It would seem to me that 'RETFIE' is the
most efficient, but the data book says to use the Fast Register Stack the
'RETURN FAST' instruction should be used! Is the data book wrong? Or just
missleading? I have been trying to find some sample code for the 18F6620 to
see how it is done in that, but have not found any.

Sorry I didn't give much information in my last question, hope this one is
better.

Thanks

Graham

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\12@060239 by Kari Lehikko

flavicon
face
> The 'FAST RETURN' instruction isn't mentioned in the instruction set in the
> data book, I presume the instruction is 'RETURN FAST'. FAST is equated to 1

fast return is retfie 1

Look at the instruction set under "retfie"

- K

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\12@063134 by Lyle Hazelwood

flavicon
face
> If you've made it so far then thanks, my question is what instruction
should
> I use to return from interrupts? It would seem to me that 'RETFIE' is the
> most efficient, but the data book says to use the Fast Register Stack the
> 'RETURN FAST' instruction should be used! Is the data book wrong? Or just
> missleading? I have been trying to find some sample code for the 18F6620
to
> see how it is done in that, but have not found any.

On the 18F458, I use "RETFIE FAST" to return from interrupts with register
restore.
Perhaps it's the same for the 18FXX20?

Good Luck,
Lyle

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\12@082111 by Olin Lathrop

face picon face
> The data book says to use the 'FAST RETURN' instruction to return from
an
> interrupt to restore the registers saved on the fast register stack. We
have
> always been told to use the 'RETFIE' instruction to return from
interrupts,
> which according to the data sheet will restore the registers W, STATUS
and
> BSR from their corresponding shadow registers (WS, STSTUSS and BSRS),
and
> more importantly re-enable interrupts. Are these shadow registers the
same
> as the Fast Register Stack? The 'RETFIE' instruction on the 17C756A only
> restored the PC.
>
> The 'FAST RETURN' instruction isn't mentioned in the instruction set in
the
> data book, I presume the instruction is 'RETURN FAST'. FAST is equated
to 1
> in the .inc file, and therefore the description of the 'RETURN FAST'
> instruction says the registers W, STATUS and BSR are restorde by the
value
> in their corresponding shadow registers (WS, STSTUSS and BSRS), BUT
> interupts are NOT re-enabled (which does make sense).

Note that the RETFIE instruction also has a FAST option.  This is how you
return from an interrupt and restore W, STATUS, and BSR from the fast
register stack.  Use the RETFIE without the FAST option to return without
restoring these registers.  The normal return has a fast option so that
the fast register stack can be used when interrupts are not used.  It is
intended to work with the CALL instruction, which also has a FAST option.

However, note that the fast register stack is written to on every
interrupt, regardless of whether you intend to restore the register from
there on return or not.  This means you can only use the fast register
stack for interrupts whenever interrupts are active, and also means you
can only use it for high prioirty interrupts if multiple interrupt
priorities are enabled.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\12@085849 by Graham North

flavicon
face
Thanks everyone, I understand now.

Now I've just got to work out what all those config bits mean!

Graham

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

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