On this page the basics of the interrupt system on an AVR 328P (Arduino UNO) is given as an example on interrupt systems.
It only deals with the basic functionallity.
More modern CPU architetures may have more complicated ISR systems so take this as a teaser.

Interrupts

An interrupt (caused by external activation on digital pin or internal affairs) is the ablility to stop execution of main code
and jump to code associated with the interrupt and after execution continue the main code.
Its a wellknown feature and is used everywhere.

In many system a couting timer is issuing interrupts with fixed intervals.
The interrupt service routine (IRS) is then maintaining a clock - like in the primitive example below.

volatile unsigned long sysTime;
ISR(TIMER_ISR)
{
  sysTime++;
}

The standard Arduino way is explained here.
You are not directly installing your function as an interrupt service routine (ISR). Instead an Arduino ISR is installed on and your code is called from this one.
This in someway to ensure or prevent you dont to do anything that may harm the system - like misconfigure the ISR system.
Interrupts can on AVR can be configured to react one

  • LOW - continous interrupt triggered

  • RISING - level change low to high

  • FALLING - level change high to low

  • CHANGE - level change either ways


Example below is from this Arduino page

(click for code)


Interrupts directly on the HW

A 328P has two direct external interrupts

  • INT0 - port PD2 - D2 pin

  • INT1 - port PD3 - D3 pin

(click for image)

Interrupt vector table

Interrupt handling is vectorized/table controlled.
When an interrupt takes place a jump address is in vectorized in a table in RAM:

(click for table)

We do have some help to get our ISR called from the ISR vectortable. The macro ISR and the predefined address references INT0 and INT1 get reference to the ISR code to written in the vector table.

In addition the ISR does also take care of preserving state of the interrupted program by pushing CPU registers on the stack somethe ISR can 1) use themm 2) reestablish them when interrupt is finish.

(click for code)

Links

(click for code)