Thursday, 14 November 2024

External Interrupt Using Arduino

 

Aim:

Adruino has several types of interrupts.Interrupt is a process by which arduino stops its regular task or stop its looping and go to interrupt function to complete its given interrupt function task.External interrupt created externally.There are only two external interrupt pin in arduino uno. They are Digital pin 2 and Digital pin 3.
After initialization of external interrupt if there is any change in signal in this pin. Then that will create external interrupt.

Description:


The processor at the heart of any Arduino has two different kinds of interrupts: “external”, and “pin change”. There are only two external interrupt pins on the ATmega168/328 (ie, in the Arduino Uno/Nano/Duemilanove), INT0 and INT1, and they are mapped to Arduino pins 2 and 3. These interrupts can be set to trigger on RISING or FALLING signal edges, or on low level. The triggers are interpreted by hardware, and the interrupt is very fast. The Arduino Mega has a few more external interrupt pins available.
On the other hand the pin change interrupts can be enabled on many more pins. For ATmega168/328-based Arduinos, they can be enabled on any or all 20 of the Arduino's signal pins; on the ATmega-based Arduinos they can be enabled on 24 pins. They are triggered equally on RISING or FALLING signal edges, so it is up to the interrupt code to set the proper pins to receive interrupts, to determine what happened (which pin? ...did the signal rise, or fall?), and to handle it properly. Furthermore, the pin change interrupts are grouped into 3 “port”s on the MCU, so there are only 3 interrupt vectors (subroutines) for the entire body of pins. This makes the job of resolving the action on a single interrupt even more complicated.

Block Diagram

3 switch

Schematic

Code

// ******************************************************
// Project: Interfacing external interrupt to Arduino
// Author: Hack Projects India
// Module description: Operate single LED and switch
// ******************************************************
#define LED 13
volatile byte state = LOW;

void setup() {
  pinMode(LED, OUTPUT);
  attachInterrupt(0, toggle, RISING);
}

void loop() { 
  digitalWrite(LED, state); 
}

void toggle() { 
  state = !state; 
}

Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:

You may also like,

No comments:

Post a Comment