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
Message
Re: Re: [AVR-Chat] Interrupt routine (now long)
2006-01-03 by Don AE5K
Attachments
- No local attachments were found for this message.