Interrupts - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Interrupts

Description:

1. Interrupts. Polling vs. Interrrupts. Interrupt Sources. 1 ... Is Polling Bad? Eats up a lot of CPU cycles doing nothing! We're repeatedly checking the button ... – PowerPoint PPT presentation

Number of Views:289
Avg rating:3.0/5.0
Slides: 35
Provided by: ecse1
Category:

less

Transcript and Presenter's Notes

Title: Interrupts


1
Interrupts
  • Polling vs. Interrrupts
  • Interrupt Sources

2
Example Task
3
One Method...
Why do we have this? Software switch debouncing
4
Is Polling Bad?
  • Eats up a lot of CPU cycles doing nothing!
  • Were repeatedly checking the button
  • Each time the button is pressed, we delay by 1 ms
    by going around in a loop, wasting time
  • We could do better if only we could somehow grab
    the CPUs attention momentarily whenever the
    button is pressed!
  • We could do even better if the 1 ms delay could
    be achieved without a delay loop!

5
Introducing Interrupts
A mechanism to interrupt the CPU, i.e., steal it
for a little while to service the interrupting
device (a button in our example)
6
Why are Interrupts Important?
They allow multiple processes to run on a
computer They allow the CPU to be shared,
greatly extending its ability For example, the
CPU can be doing something else when waiting for
the button to be pressed
7
Interrupt Method (1)
8
Interrupt Method (2)
9
Interrupts are Transparent
The program that was interrupted does not have a
clue that it was interrupted!! Interrupt Service
Routines need to leave registers
untouched Interrupt Service Routines need to be
extremely short and quick WHY??
10
Interrupts vs. Subroutines
Interrupt Service routines may look a bit like
subroutines, but they are very different. Subrout
ines are not transparent. The calling routine is
aware of the subroutine call. Interrupt Service
Routines are initiated by hardware, with some
exceptions (e.g., SWI). The CPU hardware
automatically saves and restores all registers.
With subroutines, the programmer has to write
code for saving and restoring.
11
Interrupt Sources
Hardware Sources External Pushbuttons Timers
Serial Communication Systems ... Software
Sources SWI instruction
12
Interrupt Priority
For example, sources requiring a more timely
response get higher priority. At 9600 bits/sec,
the RS-232 port on your PC produces an interrupt
about once every 2000 CPU cycles. The 68HC11
timer produces an interrupt once every 216 CPU
cycles. The timer has higher priority in this
case.
13
Timer Interrupts
  • How to get a 10 ms delay
  • Interrupt Service Routines

14
Timer Interrupts
Several options for delays Real Time Interrupt
(RTI) Pulse Accumulator Overflow (PAOV) Timer
Output Compare (TOC)
15
Real Time Interrupt
Question How do we get 10 ms? How close can we
get? 2 x 4.096 ms 8.192 ms (-1.808 ms) 3 x
4.096 ms 12.288 ms (2.288 ms)
16
Pulse Accumulator Overflow
Question How do we get 10 ms? How close can we
get? One interrupt 8.192 ms (-1.808 ms) 2
interrupts 2 x 4.992 ms 9.984 ms (-0.016 ms)
Minimum period depends on length of time spent
in the Interrupt Service Routine - generally
greater than 25 ?s
17
Timer Output Compare
18
TOC Interrupts

Question How do we get 10 ms? Add 20,000 to
TCNT and put it into TOCx This generates an
interrupt after 10 ms To continue TOCx TOCx
20,000 at each subsequent interrupt
Minimum period depends on length of time spent
in the Interrupt Service Routine - generally
greater than 25 ?s
19
Interrupt Initialization
Initialize Stack Area Stack Pointer Setup
interrupt vector jump table Clear old interrupt
flags Write a 1 to clear timer flags Enable
local interrupt masks Enable global I-bit
interrupt with CLI
20
Interrupt Service Routines
Clear the interrupt flag LDAA FLAG STAA TFLG1
Do the task
Return from interrupt RTI
21
TOC5 ISR
ISR_TOC5 LDAA OC5_BIT STAA
TFLG1 LDD TOC5 ADDD 20000 STD TOC5 INC
COUNT END_ISR RTI
22
Hardware Details
  • Port Selection
  • Detecting Pushbutton Events
  • 7-Segment Display Patterns

23
Studio Preparation
24
Connecting External Hardware
Connect the 4 Switches to Input pins Connect the
Display to Output pins Connect the Push Button to
an Input pin
25
68HC11 Port Summary
26
Port Selection
Easy Selection Display PORTB (Output
only) Switches PORTC (Program for input) No
data manipulation
Elegant Selection Display PORTC lo-nibble
(Out) Switches PORTC hi-nibble (In) Shift
input data right 4 places
27
Setting I/O Pin Directions
PORTC EQU 1003 DDRC EQU 1007 IO_PAT EQU 1111000
0 NUMBER EQU 10010011 ... LDAA IO_PAT STAA DD
RC LDAA NUMBER STAA PORTC LDAA PORTC
30
74
1001
28
Port and Pin Selection
Connect the 4 Switches to PORTC Input pins e.g.,
PORTC lo-nibble PC30 Connect the Display to
PORTB Output pins e.g., PORTB lo-nibble
PB30 Connect the Push Button to an Input pin
29
The Strobe A Input Pin
A normal input pin produces a level i.e., either
a 1 or 0 Requires switches to be debounced
Strobe A (STRA) STRA is edge sensitive i.e.,
reacts to either rising edge 0 ? 1 or falling
edge 1 ? 0 Requires the transition to be
noticed
30
How STRA Works (1)
The STRA edge transition is specified by EGA
STRA has a flag that is set when the specified
edge transition occurs STAF Clearing STAF is
a 2 step procedure LDAA PIOC (1002) LDAA
PORTCL (1005) STRA also has an interrupt mask
bit STAI
31
How STRA Works (2)
The STRA edge transition is specified by EGA
STRA has a flag that is set when the specified
edge transition occurs STAF Clearing STAF is
a 2 step procedure LDAA PIOC (1002) LDAA
PORTCL (1005) STRA also has an interrupt mask
bit STAI
Where can I find EGA, STAF, STAI? Look in the PRG
under 1002 PIOC
7 6 1
32
Ports Pins Specified
33
Review of Interrupts
34
7-Segment Display
Write a Comment
User Comments (0)
About PowerShow.com