Interrupts

ssuser92b33b 6,149 views 26 slides Nov 05, 2013
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

No description available for this slideshow.


Slide Content

Interrupts
Copyright © 2012 Embedded Systems
Committee
Eman Aboelatta

Copyright © 2012 Embedded Systems
Committee
Agenda:
•Introduction
•Interrupts
•Interrupt sequence
•So how to we define an ISR?
•Interrupt Vector Table
•Modifying Interrupt Vector Table of ATmega16
•Registers Used
•Interrupt priorities
•Interrupt nesting
•Nested Interrupt Priorities

Copyright © 2012 Embedded Systems
Committee
At first we have two methods for receiving data or get status

Introduction:
Polling Interrupt

Copyright © 2012 Embedded Systems
Committee
which involves reading the status of the port at fixed intervals to
determine whether any data has been received or a change of status
has occurred. If so, then we can branch to a routine to service the
ports requests.

oTakes CPU time even when no requests pending.

oOverhead.




Other alternative would be to use Interrupts.


“Polling is like picking up your phone every few seconds to see if
you have a call. …”

Polling :
Introduction:con’t

Copyright © 2012 Embedded Systems
Committee

 Interrupts can be used to interrupt the sequential execution of
the program flow(called asynchronous processing - that is, we are
processing the interrupt events outside the regular execution of the
main program.)

 Interrupt sources can be
- external events (e.g. change of signal at PORTB2).
- internal events.



Interrupts (IR):
Hardware interrupt
(e.g. timer
overflow).
Software interrupt
(which occur in response
to a command issued in
software-Exception
Handling )

Copyright © 2012 Embedded Systems
Committee
Non Maskable Interrupts :

doesn’t depend on global interrupt enable in processor status word
Usually it’s external interrupt(Ex : Reset).

Maskable Interrupts:

Depends on global interrupt enable in processor status word
May be :
External interrupt from external pin
Internal interrupt from peripheral
Interrupts (IR):con’t

Copyright © 2012 Embedded Systems
Committee
Interrupts (IR):Con’t
In the case of an interrupt event
the execution of the main
routine is interrupted and the
interrupt service routine (ISR)
of the according event is
executed.


After executing the ISR the
execution proceeds where it has
been interrupted.

Copyright © 2012 Embedded Systems
Committee
When the CPU detects
The CPU finishes its current instruction.
The contents of the program counter and the condition code
register(status register or Processor status word) are pushed
onto the stack(because the interrupt routine will almost
certainly modify the condition code bits).
Further interrupts are disabled to avoid an interrupt being
interrupted.
The CPU deals with the cause of the interrupt by executing
a program called an interrupt handler(ISR)(Interrupt service
routine).
The CPU executes a return from interrupt instruction at the
end of the interrupt handler. Executing this instruction pulls
the PC and PSW off the stack and execution then continues
normally—as if the interrupt had never happened.

Interrupt sequence:

Copyright © 2012 Embedded Systems
Committee
Interrupt sequence: con’t
o PSR : Processor Status
Register ==status
register==Condition Code
register

o PC : Program Counter
(contains Address of next
instruction to be executed)

Copyright © 2012 Embedded Systems
Committee
For an ISR to be called, we need three conditions to be
true:

Firstly, the AVR's global Interrupts Enable bit (I) must be set in
the MCU control register SREG.

Secondly, the individual interrupt source's enable bit must be
set. Each interrupt source has a separate interrupt enable bit in
the related peripheral's control registers, which turns on the
ISR for that interrupt.

Thirdly, The condition for the interrupt must be met - for
example, for the USART Receive Complete (USART RX)
interrupt, a character must have been received(i.e flag that
indicate interrupt raised)

So how to we define an ISR?

Copyright © 2012 Embedded Systems
Committee
So how to we define an ISR?con’t
Execute ISR
Enable Global interrupt (I)
Enable peripheral interrupt
Interrupt occurred (flag
raised)

Copyright © 2012 Embedded Systems
Committee
•Constant table in ROM.

•Special addresses with respect to CPU.

•Each interrupt has specific address in interrupt vector
table .

•This specific address should be programmed to have the
address of ISR of this interrupt.

•At interrupt processing PC will contain this address or it
will be an instruction to jump to this address

Copyright © 2012 Embedded Systems
Committee
Interrupt Vector Table:cont
•From Datasheet ATmega32/16.

Copyright © 2012 Embedded Systems
Committee
 Assembly 






 C 

Modifying Interrupt Vector Table of
ATmega16:
.org $000
rjmp Reset
.
.
.
.
.
Reset:
//instructions
ISR ({Vector Source}_vect)
{
// ISR code to execute here
}

Copyright © 2012 Embedded Systems
Committee
• The status register contains:
– Six bits status indicators ( Z,C,H,V,N,S )
– One bit for global interrupt enable ( I )

• The status bits reflect the results of CPU operation as it executes
instructions
Status Register (SREG):To Enable Global Interrupt
Registers Used

Copyright © 2012 Embedded Systems
Committee
•Clear global interrupt enable: (prevent)
•Set global interrupt enable: (Allow)
To Set/Clear global interrupt enable:
The I-bit is cleared by hardware after an interrupt has
occurred, and is set by the RETI instruction to enable
subsequent interrupts.
Registers Used with Atmega32/16:

Copyright © 2012 Embedded Systems
Committee
GICR (General Interrupt Control Register):P.no 47
Registers Used with Atmega32/16:

Copyright © 2012 Embedded Systems
Committee
MCUCR (MCU Control Register) P.66
Registers Used with Atmega32/16:

Copyright © 2012 Embedded Systems
Committee
MCUCSR (MCU Control and Status Register) P67
Registers Used with Atmega32/16:

Copyright © 2012 Embedded Systems
Committee
GIFR (General Interrupt Flag Register)
Registers Used with Atmega32/16:

Copyright © 2012 Embedded Systems
Committee
• ISR(Interrupt Service Routine)
Defining ISR :
#include <avr/interrupt.h>

ISR({Vector Source}_vect)
{
// ISR code to execute here
}

Copyright © 2012 Embedded Systems
Committee
Interrupt priorities:
•Each interrupt has default priority by its location in
interrupt vector table

•Some controllers provide more intelligent interrupt
controller which give interrupt priority level for each
interrupt

•If two interrupts have a same priority level then the rule
to return to the default priority

Copyright © 2012 Embedded Systems
Committee
Interrupt nesting:
•Interrupt Nesting: ability to leave the current interrupt
and serve another interrupt

•Usually done if global interrupt is enabled and this
interrupt has more priority

•Some controllers support the nesting of context switching
in hardware and others leave it to be done in software

Copyright © 2012 Embedded Systems
Committee
Nested Interrupt Priorities:

References
Copyright © 2012 Embedded Systems
Committee
•ATmega16 Datasheet.


•http://www.avrfreaks.net/

[email protected]
Copyright © 2012 Embedded Systems
Committee
Tags