Monday 16 July 2018

External Interrupt Using AVR Microcontroller (Atmega-8)

Aim:

Although micro controllers can accept inputs from Digital I/O Ports,interrupts are preferred for accepting inputs generated by external events. This is mainly because of the less attention required for an interrupt based program. An Interrupt Event directs the flow of program execution to a totally independent piece of code, known as “Interrupt Sub-Routine”. There are many sources of Interrupts that are available for a micro controller. Most of them are generated by the internal modules and are known as internal interrupts. And there are two pins that accept external signals directly and allows external sources to generate interrupts.

Description:


External interrupts are fairly powerful, they can be configured to trigger on one of 4 states.  Low level will trigger whenever the pin senses a LOW (GND) signal.  Any Logic Change trigger at the moment the pin changes from HIGH (Vcc) to LOW (GND) or from LOW (GND) to HIGH(Vcc). On Falling Edge will trigger at the moment the pin goes from HIGH (Vcc) to LOW (GND). On Rising Edge will trigger at the moment the pin goes from LOW (GND) to HIGH (Vcc).  The best part is that you can configure each INTx independently.
External interrupts use the below 3 registers.  Which you could find under the “External Interrupts section of the datasheet.
 7 bit6 bit 5 bit 4 bit 3 bit 2 bit 1 bit  0 bit
 MCUCRSESM2SM1SM0ISC11ISC10ISC01ISC00
MCU Control Register
 ISCx1 ISCx0 DESCRIPTION 
00 Low level of INTx generates an interrupt request
01 Any logic change on INTx generates an interrupt request
10 The falling edge of INTx generates an interrupt request
11 The rising edge of INTx generates an interrupt request
ISC Bits Settings
 7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit
GICR INT1INT0IVSELIVCE
General Interrupt Control Register
 7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit
GIFRINTF1INTF0
General Interrupt Flag Register
When the event specified by the Interrupt Sense Control (ISCxy) bits in the MCU Control Register (MCUCR) is sensed on the INTx pin, the External Interrupt Flag x (INTFx) in the General Interrupt Flag Register (GIFR) is set HIGH (1).  If the I-bit in SREG and the INT1 bit in the GICR are both HIGH(1) the MCU will jump to the corresponding vector.  The Flag is set to LOW (0) when the INTx_vect routine is executed.

Block Diagram

3 switch

Schematic

interrupt

Code

// ******************************************************
// Project: Interfacing external interrupt to atmega8
// Author: Hack Projects India
// Module description: Operate single LED
// ******************************************************

#define F_CPU 8000000UL
#include <avr/io.h>
#include<util/delay.h>

#include <avr/interrupt.h>

ISR(INT0_vect)
{
 cli();
 PORTB=0x01;
 _delay_ms(1000);
 PORTB=0x00;
 _delay_ms(1000);
 sei();
}
int main(void)
{
 DDRB=0xff;
 DDRD=0x00;
 MCUCR=0x03;
 GICR=(1<<INT0);
 SREG=0x80;
 while(1);
}

Downloads:

The code was compiled in Atmel Studio 6 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:

No comments:

Post a Comment