Assembly Interrupts

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why is that when you are declaring the first bits of the program, and you are declaring interrupts, that you have to put somthing inthe missing address:

Example in 8515's the interrupts are sequetiol

reset 0000
int 1 0001
int 2 0002

and so on ...

In the Atmega103, it skips

reset 0000
empty(so I placed reti) 0001
int1 0002
empty(so I placed reti) 0003
int2 0004
empty(so I placed reti) 0005

Why is this like that? and is there a better away, for instance if I want to use timer counter0 over flow it is 32 address spaces down, I have to fill my code with 31 reti's just to use the interrupt ?

can I just assign values in the program like
0020 rjmp tmr0ovr

Thanks again for everyones help !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

use the ".org" set program origin
.org 0x...
rjmp ....

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I'm not your local AVR whis kid here as I am new to microcontrollers, however I think I can answer some of what you are asking.

>>> Why is that when you are declaring the first bits of the program, and you are declaring interrupts, that you have to put somthing inthe missing address: <<<

I don't know why you would have to put anything in the missing addresses. Unless you have setup an interrupt to occur, the controller will never come looking for a vector address here so no address needs to be here. You stated that you placed an reti instruction here. This area of memory is for ADDRESSES only, not instructions. In order to execute reti, you would place a vector address here to point to the reti instruction that you would have placed somewhere within program memory. But like I said, the controller would never come here in the first place unless you caused it to by initiating an interupt.

I have never used the ATmega series devices but it would be my guess that the reason there are "empty" addresses (say between 0000 and 0002) is because the ATmega series have a greater addressing range than the others and the word at location 0001 is part of the address of location 0000. In other words, the 16 bits at location 0000 plus maybe 8 bits of location 0001 both make up a 24 bit address to reach beyond a 64k address range. 0000 + 0001 = address, 0002 + 0003 = address, etc.

I hope this is of help.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, Mark, it ain't quite so--

The vector area in the AVR architecture indeed has INSTRUCTIONS not addresses.

Different processor architectures have interrupt tables at low or high address locations, some relocatable (including newest AVRs), and some are addresses and some are actual instructions.

In AVRs, the processor actually branches to that address when the event occurs. So a valid instruction must be located there.

The most typical example in a non-Mega AVR is to have a series of RJMP instructions to comprise the interrupt vector table. Each of these is exactly one word wide, and keeps everything lined up. Another method is to use the one-word-wide RETI instruction to keep everything lined up.

Yet another method is to use the .ORG statement to place each vector at the correct address.

There is no rule to say that you cannot place code or data at adresses where you will not use the interrupts. That is too scary for me, unless I really, really need those last few words of space. Just in case the "unused" interrupt triggers, I write all my code so that every vector goes to an RETI. Paranoid? Perhaps. But if my code inadvertantly sets an interrupt-enable bit, I want the device to handle it gracefully, and not try to execute an arbitrary code sequence.

Note that on larger AVR devices that each vector is two words wide, so that a JMP instruction can be accomodated which can reach anywhere in the program memory space. So then when you move from an '8535 to a Mega163 [IIRC] the interrupt vector table must be modified accordingly. The .ORG method would minimize the impact on this case.

So my answer to Jokerz original question is: 1) Use the .ORG directive using the siymbolic address from the include file for the chip you are using. 2) Begin your real code after the interrupt vector table 3) Ensure that ALL vectors go to a safe place.

Lee

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ooops. Thanks for the heads up on this one. I am used to i86 assembly and I assumed the ivt contained addresses. Glad I found that out! And yes, I see that it would be good practice to provide for unintentional interrupts. Again, thanks for the correction as I don't want to say anything any more stupid than absolutely necessary (lol!).

admin's test signature