Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Interrupt routine

Interrupt routine

2006-01-02 by Moataz Hussein

I am working on a test project on AVR 1200, I have a question regarding the external interrupt. I understand that after the interrupt occurs the interrupt handling routine is called, after it is finished the program goes back to where it has stopped.
I have a question:
Is it possible and how to; After the interrupt handling routine is completed. Can the program starts from the begining not where it stopped when the interrupt routine was called.
Thank for help.
Moataz

Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

Re: [AVR-Chat] Interrupt routine

2006-01-02 by James Washer

when you say "start from the beginning", are you saying you want a FULL RESET?

If so, you'd need to build and trigger an external reset hardware, or enable the watchdog timer and then just spin until a watchdog reset occurs.

 - jim

On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
Moataz Hussein <husseinmoataz@yahoo.com> wrote:
Show quoted textHide quoted text
> I am working on a test project on AVR 1200, I have a question regarding the external interrupt. I understand that after the interrupt occurs the interrupt handling routine is called, after it is finished the program goes back to where it has stopped.
>    
>   I have a question:
>    
>   Is it possible and how to; After the interrupt handling routine is completed. Can the program starts from the begining not where it stopped when the interrupt routine was called.
>    
>   Thank for help.
>    
>   Moataz
> 
> 		
> ---------------------------------
> Yahoo! Photos
>  Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

Re: Re: [AVR-Chat] Interrupt routine

2006-01-02 by Don AE5K

James Washer wrote:
> when you say "start from the beginning", are you saying you want a FULL RESET?
> 
> If so, you'd need to build and trigger an external reset hardware, or enable the watchdog timer and then just spin until a watchdog reset occurs.
> 
>  - jim
> 
> On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
> Moataz Hussein <husseinmoataz@yahoo.com> wrote:
> 
> 
>>I am working on a test project on AVR 1200, I have a question regarding the external interrupt. I understand that after the interrupt occurs the interrupt handling routine is called, after it is finished the program goes back to where it has stopped.
>>   
>>  I have a question:
>>   
>>  Is it possible and how to; After the interrupt handling routine is completed. Can the program starts from the begining not where it stopped when the interrupt routine was called.
>>   
>>  Thank for help.
>>   

All you need to do is to jump to the beginning of your program at the
end of the interrupt service routine instead of using the usual RETI
(return from interrupt) instruction.  Of course, this depends on how you
initialize things too -- if you start out your program from reset and do
not assume anything is initialized and do the full initialization of
everything, then you should be OK.   Just beware of the state of the
interrupt enable.  All this is predicated on using assembly language and
not C.

Don

-- 
Confidence is the feeling you have before you really understand the problem.

Re: Re: [AVR-Chat] Interrupt routine

2006-01-02 by Dennis

He may not be talking about the beginning of the entire program but, say, 
the beginning of an infinite loop that was broken by the interrupt and then 
returning to the beginning of that loop.
Dennis
----- Original Message ----- 
Show quoted textHide quoted text
From: "Don AE5K" <don@ae5k.us>
To: <AVR-Chat@yahoogroups.com>
Sent: Monday, January 02, 2006 12:01 PM
Subject: Re: Re: [AVR-Chat] Interrupt routine


> James Washer wrote:
>> when you say "start from the beginning", are you saying you want a FULL 
>> RESET?
>>
>> If so, you'd need to build and trigger an external reset hardware, or 
>> enable the watchdog timer and then just spin until a watchdog reset 
>> occurs.
>>
>>  - jim
>>
>> On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
>> Moataz Hussein <husseinmoataz@yahoo.com> wrote:
>>
>>
>>>I am working on a test project on AVR 1200, I have a question regarding 
>>>the external interrupt. I understand that after the interrupt occurs the 
>>>interrupt handling routine is called, after it is finished the program 
>>>goes back to where it has stopped.
>>>
>>>  I have a question:
>>>
>>>  Is it possible and how to; After the interrupt handling routine is 
>>> completed. Can the program starts from the begining not where it stopped 
>>> when the interrupt routine was called.
>>>
>>>  Thank for help.
>>>
>
> All you need to do is to jump to the beginning of your program at the
> end of the interrupt service routine instead of using the usual RETI
> (return from interrupt) instruction.  Of course, this depends on how you
> initialize things too -- if you start out your program from reset and do
> not assume anything is initialized and do the full initialization of
> everything, then you should be OK.   Just beware of the state of the
> interrupt enable.  All this is predicated on using assembly language and
> not C.
>
> Don
>
> -- 
> Confidence is the feeling you have before you really understand the 
> problem.
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

RE: Re: [AVR-Chat] Interrupt routine

2006-01-02 by stevech

Customarily, the interrupt handler sets a bit and exits, then the
interrupted program inspects the bit and if set, takes action.
Show quoted textHide quoted text
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of Dennis
Sent: Monday, January 02, 2006 10:26 AM
To: AVR-Chat@yahoogroups.com
Subject: Re: Re: [AVR-Chat] Interrupt routine

He may not be talking about the beginning of the entire program but, say, 
the beginning of an infinite loop that was broken by the interrupt and then 
returning to the beginning of that loop.
Dennis
----- Original Message ----- 
From: "Don AE5K" <don@ae5k.us>
To: <AVR-Chat@yahoogroups.com>
Sent: Monday, January 02, 2006 12:01 PM
Subject: Re: Re: [AVR-Chat] Interrupt routine


> James Washer wrote:
>> when you say "start from the beginning", are you saying you want a FULL 
>> RESET?
>>
>> If so, you'd need to build and trigger an external reset hardware, or 
>> enable the watchdog timer and then just spin until a watchdog reset 
>> occurs.
>>
>>  - jim
>>
>> On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
>> Moataz Hussein <husseinmoataz@yahoo.com> wrote:
>>
>>
>>>I am working on a test project on AVR 1200, I have a question regarding 
>>>the external interrupt. I understand that after the interrupt occurs the 
>>>interrupt handling routine is called, after it is finished the program 
>>>goes back to where it has stopped.
>>>
>>>  I have a question:
>>>
>>>  Is it possible and how to; After the interrupt handling routine is 
>>> completed. Can the program starts from the begining not where it stopped

>>> when the interrupt routine was called.
>>>
>>>  Thank for help.
>>>
>
> All you need to do is to jump to the beginning of your program at the
> end of the interrupt service routine instead of using the usual RETI
> (return from interrupt) instruction.  Of course, this depends on how you
> initialize things too -- if you start out your program from reset and do
> not assume anything is initialized and do the full initialization of
> everything, then you should be OK.   Just beware of the state of the
> interrupt enable.  All this is predicated on using assembly language and
> not C.
>
> Don
>
> -- 
> Confidence is the feeling you have before you really understand the 
> problem.
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
> 



 
Yahoo! Groups Links

Re: Re: [AVR-Chat] Interrupt routine

2006-01-02 by Moataz Hussein

Thanks all for your advice, I was meaning start of program i.e. full reset.
In a book I have it is mentioned
"When an interrupt occurs the value of the program counter is stored in the stack so that the program returns to where it was when the handling interrupt is over."
So is it correct that going to the start (rjmp start) at the end of the interrupt routine instead of the RETI instruction will not help?
Moataz
Show quoted textHide quoted text
James Washer wrote:
> when you say "start from the beginning", are you saying you want a FULL RESET?
>
> If so, you'd need to build and trigger an external reset hardware, or enable the watchdog timer and then just spin until a watchdog reset occurs.
>
> - jim
>
> On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
> Moataz Hussein wrote:
>
>
>>I am working on a test project on AVR 1200, I have a question regarding the external interrupt. I understand that after the interrupt occurs the interrupt handling routine is called, after it is finished the program goes back to where it has stopped.
>>
>> I have a question:
>>
>> Is it possible and how to; After the interrupt handling routine is completed. Can the program starts from the begining not where it stopped when the interrupt routine was called.
>>
>> Thank for help.
>>

All you need to do is to jump to the beginning of your program at the
end of the interrupt service routine instead of using the usual RETI
(return from interrupt) instruction. Of course, this depends on how you
initialize things too -- if you start out your program from reset and do
not assume anything is initialized and do the full initialization of
everything, then you should be OK. Just beware of the state of the
interrupt enable. All this is predicated on using assembly language and
not C.

Don

--
Confidence is the feeling you have before you really understand the problem.


Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

Re: [AVR-Chat] Interrupt routine

2006-01-02 by Micah Stevens

No because you're not resetting the memory contents. Your instructions will 
start over, but you'll have non-initialized ram, which may affect program 
flow. 

-Micah 
Show quoted textHide quoted text
On Monday 02 January 2006 1:02 pm, Moataz Hussein wrote:
>   Thanks all for your advice, I was meaning start of program i.e. full
> reset.
>
>   In a book I have it is mentioned
>   "When an interrupt occurs the value of the program counter is stored in
> the stack so that the program returns to where it was when the handling
> interrupt is over."
>
>   So is it correct that going to the start (rjmp start) at the end of the
> interrupt routine instead of the RETI instruction will not help?
>
>   Moataz
>
>   James Washer wrote:
> > when you say "start from the beginning", are you saying you want a FULL
> > RESET?
> >
> > If so, you'd need to build and trigger an external reset hardware, or
> > enable the watchdog timer and then just spin until a watchdog reset
> > occurs.
> >
> >  - jim
> >
> > On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
> >
> > Moataz Hussein <husseinmoataz@yahoo.com> wrote:
> >>I am working on a test project on AVR 1200, I have a question regarding
> >> the external interrupt. I understand that after the interrupt occurs the
> >> interrupt handling routine is called, after it is finished the program
> >> goes back to where it has stopped.
> >>
> >>  I have a question:
> >>
> >>  Is it possible and how to; After the interrupt handling routine is
> >> completed. Can the program starts from the begining not where it stopped
> >> when the interrupt routine was called.
> >>
> >>  Thank for help.
>
> All you need to do is to jump to the beginning of your program at the
> end of the interrupt service routine instead of using the usual RETI
> (return from interrupt) instruction.  Of course, this depends on how you
> initialize things too -- if you start out your program from reset and do
> not assume anything is initialized and do the full initialization of
> everything, then you should be OK.   Just beware of the state of the
> interrupt enable.  All this is predicated on using assembly language and
> not C.
>
> Don

Re: Re: Re: [AVR-Chat] Interrupt routine

2006-01-02 by Don AE5K

Moataz Hussein wrote:
>  
>  
> Thanks all for your advice, I was meaning start of program i.e. full reset.
>  
> In a book I have it is mentioned
> "When an interrupt occurs the value of the program counter is stored in
> the stack so that the program returns to where it was when the handling
> interrupt is over."
>  
> So is it correct that going to the start (rjmp start) at the end of the
> interrupt routine instead of the RETI instruction will not help?
>  
> Moataz
> 
>

Moataz,

I believe that is what I said (below).  Since you are no doubt
initializing the stack pointer as one of the first tasks when you start
your program, resetting it again by going to the start of your program
will take care of the return value that was on it (essentially
discarding it).  Also, since you won't be using the RETI instruction,
interrupts will be inhibited until you allow them again in your further
code.

There's nothing really magic about interrupts ... they are quite similar
to subroutines in most ways, and the RETI is same as a return from
subroutine except it takes care of the interrupt flag.  What you are
seeking is considered a non-standard return (just one of the tricks that
we sometimes play and need to document thoroughly in your source code).

Don
Show quoted textHide quoted text
> 
>     All you need to do is to jump to the beginning of your program at the
>     end of the interrupt service routine instead of using the usual RETI
>     (return from interrupt) instruction.  Of course, this depends on how you
>     initialize things too -- if you start out your program from reset and do
>     not assume anything is initialized and do the full initialization of
>     everything, then you should be OK.   Just beware of the state of the
>     interrupt enable.  All this is predicated on using assembly language and
>     not C.
> 
>     Don

Re: Re: [AVR-Chat] Interrupt routine

2006-01-02 by Zack Widup

Your initialization of the chip should include resetting the stack 
pointer.  So if at the end of your interrupt routine you go to the very 
start of the program instead of using "retfie", you're starting completeny 
new and it shouldn't matter.

Zack
Show quoted textHide quoted text
On Mon, 2 Jan 2006, Moataz Hussein wrote:

>  
>    
>   Thanks all for your advice, I was meaning start of program i.e. full reset.
>    
>   In a book I have it is mentioned
>   "When an interrupt occurs the value of the program counter is stored in the stack so that the program returns to where it was when the handling interrupt is over."
>    
>   So is it correct that going to the start (rjmp start) at the end of the interrupt routine instead of the RETI instruction will not help?
>    
>   Moataz

RE: Re: [AVR-Chat] Interrupt routine

2006-01-02 by Larry Barello

IIR the original post mentioned the AT901200 which does not have a normal
stack.  A hard reset would be the only way to "reset" it.


-----------
Larry Barello
www.barello.net


| -----Original Message-----
| From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
| Of Zack Widup
| Sent: Monday, January 02, 2006 3:36 PM
| To: AVR-Chat@yahoogroups.com
| Subject: Re: Re: [AVR-Chat] Interrupt routine
| 
| 
| Your initialization of the chip should include resetting the stack
| pointer.  So if at the end of your interrupt routine you go to the very
| start of the program instead of using "retfie", you're starting completeny
| new and it shouldn't matter.
| 
| Zack
| 
| On Mon, 2 Jan 2006, Moataz Hussein wrote:
| 
| >
| >
| >   Thanks all for your advice, I was meaning start of program i.e. full
| reset.
| >
| >   In a book I have it is mentioned
| >   "When an interrupt occurs the value of the program counter is stored
| in the stack so that the program returns to where it was when the handling
| interrupt is over."
| >
| >   So is it correct that going to the start (rjmp start) at the end of
| the interrupt routine instead of the RETI instruction will not help?
| >
| >   Moataz
| 
| 
| 
| 
| Yahoo! Groups Links
| 
| 
| 
| 
|

Re: [AVR-Chat] Interrupt routine

2006-01-02 by Micah Stevens

Now that I think of it, you'd run through variable initialization as well 
right after that, so the memory locations should be reset to their initial 
values needed. At least, that's what I do in ASM. I would assume a C compiler 
would do the same thing, but I've never paid attention. 

-Micah 
Show quoted textHide quoted text
On Monday 02 January 2006 3:36 pm, Zack Widup wrote:
>  Your initialization of the chip should include resetting the stack
>  pointer.  So if at the end of your interrupt routine you go to the very
>  start of the program instead of using "retfie", you're starting completeny
>  new and it shouldn't matter.
>
>  Zack
>
>  On Mon, 2 Jan 2006, Moataz Hussein wrote:
>  > 
>  >   
>  >   Thanks all for your advice, I was meaning start of program i.e. full
>  > reset. 
>  >   In a book I have it is mentioned
>  >   "When an interrupt occurs the value of the program counter is stored
>  > in the stack so that the program returns to where it was when the
>  > handling interrupt is over." 
>  >   So is it correct that going to the start (rjmp start) at the end of
>  > the interrupt routine instead of the RETI instruction will not help? 
>  >   Moataz
>
> SPONSORED LINKS
> Atmel avr   Microcontrollers   Intel microprocessors
>   Pic microcontrollers
>
>
> YAHOO! GROUPS LINKS
>
>
>  Visit your group "AVR-Chat" on the web.
>  
>  To unsubscribe from this group, send an email to:
>  AVR-Chat-unsubscribe@yahoogroups.com
>  
>  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

Re: [AVR-Chat] Interrupt routine

2006-01-03 by dlc

The ONLY way to return to where the interrupt occurred is to use a RETI 
instruction.

DLC

Moataz Hussein wrote:
>  
>  
> Thanks all for your advice, I was meaning start of program i.e. full reset.
>  
> In a book I have it is mentioned
> "When an interrupt occurs the value of the program counter is stored in 
> the stack so that the program returns to where it was when the handling 
> interrupt is over."
>  
> So is it correct that going to the start (rjmp start) at the end of the 
> interrupt routine instead of the RETI instruction will not help?
>  
> Moataz
> 
>     James Washer wrote:
>      > when you say "start from the beginning", are you saying you want
>     a FULL RESET?
>      >
>      > If so, you'd need to build and trigger an external reset
>     hardware, or enable the watchdog timer and then just spin until a
>     watchdog reset occurs.
>      >
>      >  - jim
>     & gt;
>      > On Mon, 2 Jan 2006 04:19:44 -0800 (PST)
>      > Moataz Hussein <husseinmoataz@yahoo.com> wrote:
>      >
>      >
>      >>I am working on a test project on AVR 1200, I have a question
>     regarding the external interrupt. I understand that after the
>     interrupt occurs the interrupt handling routine is called, after it
>     is finished the program goes back to where it has stopped.
>      >>  
>      >>  I have a question:
>      >>  
>      >>  Is it possible and how to; After the interrupt handling routine
>     is completed. Can the program starts from the begining not where it
>     stopped when the interrupt routine was called.
>      >>  
>      >>  Thank for help.
>      >>  
> 
>     All you need to do is to jump to the beginning of your program at the
>     end of the interrupt service routine instead of using the usual RETI
>     (return from interrupt) instruction.  Of course, this depends on how you
>     initialize things too -- if you start out your program from reset and do
>     not assume anything is initialized and do the full initialization of
>     everything, then you should be OK.   Just beware of the state of the
>     interrupt enable.  All this is predicated on using assembly language and
>     not C.
> 
>     Don
> 
>     -- 
>     Confidence is the feeling you have before you really understand the
>     problem.
> 
> 
> ------------------------------------------------------------------------
> Yahoo! Photos
> Ring in the New Year with Photo Calendars 
> <http://us.rd.yahoo.com/mail_us/taglines/photos/*http://pg.photos.yahoo.com/ph//page?.file=calendar_splash.html&.dir=>. 
> Add photos, events, holidays, whatever.
> 
> SPONSORED LINKS
> Atmel avr 
> <http://groups.yahoo.com/gads?t=ms&k=Atmel+avr&w1=Atmel+avr&w2=Microcontrollers&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=90&.sig=a_VWnyFlgM4nNSKwYg7V3Q> 
> 	Microcontrollers 
> <http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1=Atmel+avr&w2=Microcontrollers&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=90&.sig=b26gH7zUN4MtXbR94lbbng> 
> 	Intel microprocessors 
> <http://groups.yahoo.com/gads?t=ms&k=Intel+microprocessors&w1=Atmel+avr&w2=Microcontrollers&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=90&.sig=lPUnRqJx7nqw1wyiyGpciw> 
> 
> Pic microcontrollers 
> <http://groups.yahoo.com/gads?t=ms&k=Pic+microcontrollers&w1=Atmel+avr&w2=Microcontrollers&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=90&.sig=FQZsK0YJzN30czaApcXA-A> 
> 
> 
> 
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
> 
>     *  Visit your group "AVR-Chat
>       <http://groups.yahoo.com/group/AVR-Chat>" on the web.
>        
>     *  To unsubscribe from this group, send an email to:
>        AVR-Chat-unsubscribe@yahoogroups.com
>       <mailto:AVR-Chat-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>        
>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
> 
> 
> ------------------------------------------------------------------------
> 

-- 
-------------------------------------------------
Dennis Clark          TTT Enterprises
www.techtoystoday.com
-------------------------------------------------

RE: [AVR-Chat] Interrupt routine

2006-01-03 by stevech

A software-initiated full reset of the AVRs is often done by forcing a
watchdog timer timout.
Show quoted textHide quoted text
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of Micah Stevens
Sent: Monday, January 02, 2006 3:42 PM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] Interrupt routine

Now that I think of it, you'd run through variable initialization as well 
right after that, so the memory locations should be reset to their initial 
values needed. At least, that's what I do in ASM. I would assume a C
compiler 
would do the same thing, but I've never paid attention. 

-Micah 

On Monday 02 January 2006 3:36 pm, Zack Widup wrote:
>  Your initialization of the chip should include resetting the stack
>  pointer.  So if at the end of your interrupt routine you go to the very
>  start of the program instead of using "retfie", you're starting
completeny
>  new and it shouldn't matter.
>
>  Zack
>
>  On Mon, 2 Jan 2006, Moataz Hussein wrote:
>  > 
>  >   
>  >   Thanks all for your advice, I was meaning start of program i.e. full
>  > reset. 
>  >   In a book I have it is mentioned
>  >   "When an interrupt occurs the value of the program counter is stored
>  > in the stack so that the program returns to where it was when the
>  > handling interrupt is over." 
>  >   So is it correct that going to the start (rjmp start) at the end of
>  > the interrupt routine instead of the RETI instruction will not help? 
>  >   Moataz
>
> SPONSORED LINKS
> Atmel avr   Microcontrollers   Intel microprocessors
>   Pic microcontrollers
>
>
> YAHOO! GROUPS LINKS
>
>
>  Visit your group "AVR-Chat" on the web.
>  
>  To unsubscribe from this group, send an email to:
>  AVR-Chat-unsubscribe@yahoogroups.com
>  
>  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.




 
Yahoo! Groups Links

Re: [AVR-Chat] Interrupt routine

2006-01-03 by Micah Stevens

Good idea.. 
Show quoted textHide quoted text
On Monday 02 January 2006 8:19 pm, stevech wrote:
>  A software-initiated full reset of the AVRs is often done by forcing a
>  watchdog timer timout.
>
>  -----Original Message-----
>  From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
>  Of Micah Stevens
>  Sent: Monday, January 02, 2006 3:42 PM
>  To: AVR-Chat@yahoogroups.com
>  Subject: Re: [AVR-Chat] Interrupt routine
>
>  Now that I think of it, you'd run through variable initialization as well
>  right after that, so the memory locations should be reset to their initial
>  values needed. At least, that's what I do in ASM. I would assume a C
>  compiler
>  would do the same thing, but I've never paid attention.
>
>  -Micah
>
>  On Monday 02 January 2006 3:36 pm, Zack Widup wrote:
>  >  Your initialization of the chip should include resetting the stack
>  >  pointer.  So if at the end of your interrupt routine you go to the very
>  >  start of the program instead of using "retfie", you're starting
>
>  completeny
>
>  >  new and it shouldn't matter.
>  >
>  >  Zack
>  >
>  >  On Mon, 2 Jan 2006, Moataz Hussein wrote:
>  >  > 
>  >  >   
>  >  >   Thanks all for your advice, I was meaning start of program i.e.
>  > full > reset.
>  >  >   In a book I have it is mentioned
>  >  >   "When an interrupt occurs the value of the program counter is
>  > stored > in the stack so that the program returns to where it was when
>  > the > handling interrupt is over."
>  >  >   So is it correct that going to the start (rjmp start) at the end of
>  >  > the interrupt routine instead of the RETI instruction will not help?
>  >  >   Moataz
>  >
>  > SPONSORED LINKS
>  > Atmel avr   Microcontrollers   Intel microprocessors
>  >   Pic microcontrollers
>  >
>  >
>  > YAHOO! GROUPS LINKS
>  >
>  >
>  >  Visit your group "AVR-Chat" on the web.
>  >  
>  >  To unsubscribe from this group, send an email to:
>  >  AVR-Chat-unsubscribe@yahoogroups.com
>  >  
>  >  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>  Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
> SPONSORED LINKS
> Atmel avr   Microcontrollers   Intel microprocessors
>   Pic microcontrollers
>
>
> YAHOO! GROUPS LINKS
>
>
>  Visit your group "AVR-Chat" on the web.
>  
>  To unsubscribe from this group, send an email to:
>  AVR-Chat-unsubscribe@yahoogroups.com
>  
>  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

Re: Re: [AVR-Chat] Interrupt routine (now long)

2006-01-03 by Don AE5K

Maybe someone can explain to me why my original and subsequent reply to
the original poster would not work.  Let me recap... the original query was:

> From: Moataz Hussein <husseinmoataz@...>
> Date: Mon Jan 2, 2006  6:19 am
> Subject: Interrupt routine 
> 
> I am working on a test project on AVR 1200, I have a question 
> regarding the external interrupt. I understand that after the 
> interrupt occurs the interrupt handling routine is called, after 
> it is finished the program goes back to where it has stopped.
>  
> I have a question:
>  
> Is it possible and how to; After the interrupt handling routine 
> is completed. Can the program starts from the begining not where 
> it stopped when the interrupt routine was called.
>  
> Thank for help.
>  
> Moataz

I must admit I missed the significance of the 1200 when I first replied.
But as Larry Barello pointed out (later):

> IIR the original post mentioned the AT901200 which does not have a normal
> stack. A hard reset would be the only way to "reset" it.

That's true.  And I believe it makes my reply even easier.

After some speculation as to what Moataz meant, he replied:

> Thanks all for your advice, I was meaning start of program i.e. full reset.
>  
> In a book I have it is mentioned
> "When an interrupt occurs the value of the program counter is 
> stored in the stack so that the program returns to where it was 
> when the handling interrupt is over."
>  
> So is it correct that going to the start (rjmp start) at 
> the end of the interrupt routine instead of the RETI 
> instruction will not help?

My solution was:

> All you need to do is to jump to the beginning of your program at the
> end of the interrupt service routine instead of using the usual RETI
> (return from interrupt) instruction.

And I added some more which is no longer needed as it is a 1200 we are
talking about (regarding initialization, etc.).

Now we have several who say differently and I would appreciate learning
where my understanding is wrong.  Granted, its been a while since I did
anything with the AT90S1200, but looking at its latest data sheet from
Atmel, it describes the stack as follows:

> The AT90S1200 uses a 3 level deep hardware stack for subroutines and interrupts. The
> hardware stack is 9 bits wide and stores the Program Counter (PC) return address while
> subroutines and interrupts are executed.
> RCALL instructions and interrupts push the PC return address onto stack level 0, and
> the data in the other stack levels 1 - 2 are pushed one level deeper in the stack. When a
> RET or RETI instruction is executed the returning PC is fetched from stack level 0, and
> the data in the other stack levels 1 - 2 are popped one level in the stack.
> If more than three subsequent subroutine calls or interrupts are executed, the first values
> written to the stack are overwritten.

Therefore my conclusion is that since there is no load stack
instruction, it is 3 deep (I'd guess it was implemented on the chip
possibly as a circular buffer since they use the term "overwritten"
instead of "lost" or "dropped") and it does not care WHERE it is ... so
at the end of his interrupt service routine, he performs a RJMP START
and proceeds from there.  The next subroutine he calls or the next
interrupt he encounters will merrily push the return program counter on
the stack (no matter where it is pointing).  The oldest value (which he
does not care about) is bit-bucketed.

We can all learn from this simple question, even though the 1200 is an
obsolete part.  Makes the old brain active again.

Regards and Happy New Year to everyone on this list -- I learn a lot
from it!

Don Jackson

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.