Sunteți pe pagina 1din 15

INTERRUPTS

IN ATMEGA16

What is an INTERRUPT???
A signal that temporarily stops the execution of a process so that another procedure can be carried out In general sense means "breaking the flow of some process A classroom is the best example of Interrupts Interrupts are nothing more than subroutines or functions that put on hold normal program flow while they are executed.

Applications
RESET is an INTERRUPT!!!!!! In Computer Games and Robotics In many Hardware applications, like RTC(Real Time Clock), Watch Dog Timer etc.. Interrupts are used in almost all complex embedded applications Line follower, Maze Solver

Broad Classification of Interrupts


INTERRUPTS

EXTERNAL or HARDWARE INTERRUPTS

INTERNAL or SOFTWARE INTERRUPTS

Hardware Interrupts: If the interrupt occurred is due to a change in an external signal i.e. a hardware signal external to code written, then it is called an hardware or external interrupt. Software Interrupt: If an interrupt occurs inside the software like finishing the execution of a process etc. then it is called an software or internal interrupt. ATMEGA16 has 3 external interrupts and more than 17 software interrupts designed for specific functions.

How to use these Interrupts???


Interrupt are handled by Interrupt Service Routines(ISR). ISR are like functions that are called when an interrupt occurs (software or Hardware). Ex. ISR(INT0_VECT), ISR(ADC_VECT) After the execution of ISR, the control is returned to the normal program flow We can write our required code in ISR depending on our application. Writing code in ISR is like Writing Code in a Function. Ex. ISR(ADC_vect) { //Your code here }

External Interrupts
INT0, INT1, INT2 are the three external interrupts. These External Interrupts are triggered by the INT0, INT1, and INT2 pins.(PINS 16, 17 and 3) The external interrupt can occur in any of the following conditions: (Only for INT0 and INT1) 1. The low level signal on the Interrupt pins can generate an interrupt request. 2.Any logical change in the signal on the Interrupt pins can generate an interrupt request. 3.The falling edge of the signal on the Interrupt pins can generate an interrupt request. 4.The rising edge of the signal on the Interrupt pins can generate an interrupt request.

For INT2??
For interrupt at INT2 pin, the interrupt can occur only if the signal is either at falling edge the signal is at rising edge.

What are rising and Falling Edges???


Falling Edge High Level

Rising Edge

LOW LEVEL

Enabling the Interrupts


The bits INT2, INT1 and INT0 in GICR(General Interrupt Control Register) are used to enable these interrupts.

But the I-bit in SREG(Status Register) must also be set 1 i.e. Logic High to enable the interrupts.

Only enabling the bits INT2, INT1 and INT0 in GICR doesnt enable the interrupts.

Handling External Interrupts


To set the level at which the interrupt has to occur, we need to configure MCUCR.

Bits 3,2 are used to configure for INT1 pin Bits 1,0 are used to configure for INT0 pin INT2 is configured using another register(MCUCSR)

INTRODUCTION ABOUT INTERRUPT FLAGS

Algorithms are to be written now


Algo for INT0, INT1 Algo for INT2 Algo for Line follower This closes External Interrupts

S-ar putea să vă placă și