This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

What is a vector?

I am new to the world of microcontrollers.  I come form an iOS background.  I am reading about interrupts and have come across vectors.  Can someone explain what is meant by vector and vector table?  I keep thinking about vector addition.  Is it simple a term used to describe an interrupt or does it mean something specific?

Take care,

Jon

  • Interrupt vector, the location in memory of an interrupt handling routine

  • Thanks old_cow_yellow.  That sums it up.

  • In addition of the sort explanation from OCY, I might add some info, as this term is used elsewhere too...

    Basically, a vector is something that has a value and a direction. So an interrutpt vector directs you to the Interrupt Service Routine (ISR). And the vector table is jsut this, a table of vectors where every entry points to an ISR that is assigned with the location and therefore the meaning of the vector, e.g. location 0xfffe is the reset vector and the word value at 0xfffe directs the CPU to the reset ISR (which isn't exactly an ISR as it never returns).

    But there is a different type of vectors in the MSP: the interrupt vector registers (xxxIV) in several hardwar emodules. These registers contain a vector that points you to the cause of the interrupt. So has the Port1 interrupt mechanism one PORT1_VECTOR in the interrupt table, but 8 possible causes for the interrupt (port pin 0..7). If you read the PORT1IV register, it returns a value that corresponds to the highest priority interrupt source for this interrupt vector. The value is 0 based (0 = no interrupt), and increments in steps of 2. The reason is that you can use this as an offset to the program counter and use a jump table to reach the different handlers inside the ISR. This is extremely fast. If you use the __even_in_range() intrinsic in a switch statement with the IV register as parameter, teh compiler can generate an extermely fast and short way to swithc to all of your cases. Vital for ISRs.
    Also, reading the IV register immediately clears the corresponding IFG bit. So if you read the register again, you'll get the value for the next lower interrupt cause (eventually ending with returning 0 if no more interrupts are pending for this module).

  • Truly awesome info. Thanks for taking the time to write this. 

    Jon

  • Jon Thornham said:
    Thanks for taking the time to write this. 

    You're welcome. I'll copy this to my book if I ever write it :)

**Attention** This is a public forum