Professional Documents
Culture Documents
Rohan Bansal
Edward Chyau
Anirudh Rudraraju
Telephone Analogy
• How do we know if someone is calling?
– Use polling
• Pick up the phone periodically and check if
someone is there.
– Wait for an interrupt
• Wait until the phone rings, then answer it.
Polling
• Loops and checks a register until a certain
state is found
LDX #$1030
WAIT BRCLR 0,X #$80 WAIT
Interrupts
• A way to get the microcontrollers attention
Applications of Interrupts
• Critical signals
– Switch power sources on power failure
– Turn on fans when overheating
– Notify the CPU when an error occurs
• Timers
– Create interrupts at specified real times
• Receive input
– Check when a button is pushed on a
controller
Interrupts and Resets 5
Georgia Institute of Technology ME4447 / ME6405
Drawbacks of Interrupts
• Interrupts can occur randomly
– Makes testing and debugging difficult
Interrupt Flow
1. Complete the current instruction
Interrupt Flowchart
SOFTWARE HARDWARE
INTERRUPT INTERRUPT
Interrupt Vector
Vector Address BUFFALO Address Interrupt Source CCR Mask Bit
FFC0 – FFC1 to FFD4 – FFD5 – Reserved –
FFD6 – FFD7 C4 – C6 SCI Serial System I
FFD8 – FFD9 C7 – C9 SPI Serial Transfer Complete I
FFDA – FFDB CA – CC Pulse Accumulator Input Edge I
FFDC – FFDD CD – CF Pulse Accumulator Overflow I
FFDE – FFDF D0 – D2 Timer Overflow I
FFE0 – FFE1 D3 – D5 Timer Input Capture 4/Output Compare 5 I
FFE2 – FFE3 D6 – D8 Timer Output Compare 4 I
FFE4 – FFE5 D9 – DB Timer Output Compare 3 I
FFE6 – FFE7 DC – DE Timer Output Compare 2 I
FFE8 – FFE9 DF – E1 Timer Output Compare 1 I
FFEA – FFEB E2 – E4 Timer Input Capture 3 I
FFEC – FFED E5 – E7 Timer Input Capture 2 I
FFEE – FFEF E8 – EA Timer Input Capture 1 I
FFF0 – FFF1 EB – ED Real-Time Interrupt I
FFF2 – FFF3 EE –F0 IRQ (external pin) I
FFF4 – FFF5 F1 – F3 XIRQ pin X
FFF6 – FFF7 F4 – F6 Software Interrupt None
FFF8 – FFF9 F7 – F9 Illegal Opcode Trap None
FFFA – FFFB FA – FC COP Failure None
FFFC – FFFD FD – FF Clock Monitor Fail None
FFFE – FFFF – RESET None
Interrupt Example
IRQHANDLE ORG $3000
LDAA COUNT * A <-- current count
INCA * increment count
STAA COUNT * write back count
IRQ Handler LDX #MSG * print out msg
Routine JSR OUTSTRG
LDX #COUNT * print out count
JSR OUT1BYT
RTI * all done – return
ORG $00ee
Main IRQ Routine JMP IRQHANDLE
Types of Interrupts
• Non-Maskable Interrupts
– Has priority over maskable interrupts
– Always Interrupts program execution
– 6 available non-maskable interrupts
• Maskable Interrupts
– Adjustable priority level
– Can be disabled by the I-bit of CCR
– 15 available maskable interrupts
XIRQ
When a non-maskable interrupt occurs…
S X H I N Z V C
1 1
IRQ
When a maskable interrupt occurs…
S X H I N Z V C
0 1
S X H I N Z V C S X H I N Z V C
0 0 0 1
S X H I N Z V C S X H I N Z V C
0 1 1 1
OPTION $1039
7 6 5 4 3 2 1 0
ADPU CSEL IRQE DLY CME CR1 CR0
Types of Interrupts
• Power-On Reset (POR)
• External RESET pin
• COP Watchdog timer Reset.
• Clock Monitor Reset
• Interrupt vectors:
• COP timer rate can be set by using CR1 and CR0 pins of
System Configuration Options (OPTION) register.
External RESET
• External Reset is generated when the user
manually presses the Reset button.
• As soon as the RESET pin goes to Zero, and
internal Nchannel device is turned on.
• This device holds the RESET pin to zero for 4 E-
clock cycles (Redundantly) after which it releases.
• RESET pin is sampled after 2E clock cycles from
the time the Nchannel releases the pin.
– If low : External Reset
– If high: Internal Reset : either COP Watchdog or
Clock Monitor
• Chance of Misinterpretation
Reset Priority
• If in case of External Reset, when RESET
pin is not held long enough, the reset is
tentatively assumed to have come from
COP or Clock Monitor Systems.
• First checks for Clock monitor and then
checks COP watchdog.
• If neither pending, normal reset vector is
selected by default.
Memory Map
• RAM and I/O mapping register (INIT) is
initialized to $01, putting 256 bytes of RAM
at locations $0000-$00FF and control
registers at locations $ 1000-$103F.
• 8KB of ROM and 512 B of EEPROM may or
may not be present depending on the values
of the two bits in CONFIG register that enable
them.
• CONFIG register being a EEPROM cell is not
affected by reset or power-down.
• PortC, Port D(bits 5-0), PortA(bits 0,1,2, and 7), and Port E are configured as general
purpose high impedance inputs.
• Port B and bits 6-3 of PortA have their directions fixed as outputs and their reset state is
logic 0.
Timer
• Initialized to count of $0000
• All output compare (OC) registers are
initialized to $FFFF
• Use OC to program an action to occur at a
specific time (when counter matches OC
register, task is executed)
• Input capture registers are indeterminate.
• IC records the time that an external event
takes
• Real-Time Interrupt:
– RTI interrupt flag is cleared, automatic
hardware interrupts are masked.
• Pulse Accumulator
– Disabled (PAI pin defaults to a general
purpose input).
• Mode of operation
– Determined by bits set in the HPRIO register
WAIT mode
• Command: WAI
• CPU always shut down during wait mode
• CPU registers are stacked
• Program is suspended until interrupted
• On-chip crystal oscillator remains active
• Power conservation depends on number of peripheral
systems shut down
– A/D converter current can be eliminated by writing the ADPU bit
to 0
– The SPI system is enabled or disabled by the SPE control bit
– The SCI transmitter is enabled or disabled by the TE bit, and the
SCI receiver is enabled or disabled by the RE bit.
References
• Interrupts made Easy by Mark Minasi (COMPUTE! ISSUE 149 / FEBRUARY 1993 / PAGE 60,
http://www.atarimagazines.com/compute/issue149/60_Interrupts_made_easy.php )
• http://coecs.ou.edu/Erik.E.Petrich/ddl/interrupts.html
• Reference Manual, Technical Data, and User Guides for the HC11