Docsity

ECE 331 Spring 2009 HW 11 Solutions: Stack, Timer, Interrupts - Prof. Andrew Mason, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 331 Spring 2009 Homework 11-Solution
Due Wed April 29 at the beginning of class.
1. The table to the right represents the stack contents at an instant in time.
a. If the main program just jumped to a subroutine, what is the subroutine
return address (i.e., where will it return after the subroutine is complete)?
Return address is the last thing stored on the stack before
jumping to the subroutine. The two-byte return address is
stored low bit first, then high byte. So the return address is
$4356.
b. If accA then IY were pushed to the stack before calling a subroutine that is
currently being executed, what was the value in accA?
The top of the stack holds the return address (2 bytes). IY (2
bytes) was pushed on after accA on thus occupies the next 2
locations from the top. Thus, accA would have the value $21.
c. If the subroutine currently being executed pushed IX to the stack, what is the subroutine return
address?
Two bytes of IX would occupy the top of the stack, so the return address. So the
return address is $73D2.
2. Briefly describe the following timer functions
a. Input capture
Captures and stores the free running counter value when a signal transition is
observed on a specific timer port pin.
b. Output compare
Generates an output signal at a specific value of the free running counter.
c. Pulse accumulator
Counts pulses (signal transitions) on a specific timer port pin.
3. In the world of microcontrollers, what is an exception?
Break (disruption) in normal program flow.
4. List two types of resets generated by internal factors.
Computer Operating Properly (COP) Reset, Clock Monitor Reset
5. What is the purpose of an interrupt?
Enables a microcontroller to respond to higher priority events than the normal
program.
6. Exception priority:
a. What exception has the highest priority?
Power-On Reset
b. What interrupt has the highest priority?
Unimplemented Instruction (SWI is wrong but acceptable)
c. Of maskable and non-maskable interrupts, which has the highest priority?
Non-maskable
SP
43
56
c. PC
73
D2
b. accA
21
CB
16
37
55
F4
bottom of
stack
pf3

Partial preview of the text

Download ECE 331 Spring 2009 HW 11 Solutions: Stack, Timer, Interrupts - Prof. Andrew Mason and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

ECE 331 Spring 2009 Homework 11-Solution

Due Wed April 29 at the beginning of class.

  1. The table to the right represents the stack contents at an instant in time. a. If the main program just jumped to a subroutine, what is the subroutine return address (i.e., where will it return after the subroutine is complete)? Return address is the last thing stored on the stack before jumping to the subroutine. The two-byte return address is stored low bit first, then high byte. So the return address is $. b. If accA then IY were pushed to the stack before calling a subroutine that is currently being executed, what was the value in accA? The top of the stack holds the return address (2 bytes). IY ( bytes) was pushed on after accA on thus occupies the next 2 locations from the top. Thus, accA would have the value $. c. If the subroutine currently being executed pushed IX to the stack, what is the subroutine return address? Two bytes of IX would occupy the top of the stack, so the return address. So the return address is $73D.
  2. Briefly describe the following timer functions a. Input capture Captures and stores the free running counter value when a signal transition is observed on a specific timer port pin. b. Output compare Generates an output signal at a specific value of the free running counter. c. Pulse accumulator Counts pulses (signal transitions) on a specific timer port pin.
  3. In the world of microcontrollers, what is an exception? Break (disruption) in normal program flow.
  4. List two types of resets generated by internal factors. Computer Operating Properly (COP) Reset, Clock Monitor Reset
  5. What is the purpose of an interrupt? Enables a microcontroller to respond to higher priority events than the normal program.
  6. Exception priority: a. What exception has the highest priority? Power-On Reset b. What interrupt has the highest priority? Unimplemented Instruction (SWI is wrong but acceptable) c. Of maskable and non-maskable interrupts, which has the highest priority? Non-maskable

SP  43

c. PC 73

D

b. accA 21

CB

F

bottom of stack

d. What tells us the (default) priority of maskable interrupts? Interrupt Vector Map

  1. Describe an example of a real life event that could be managed by polling or interrupt type mechanisms and identify which mechanism is polling and which is interrupt. Do not use the example given in class. Answers will vary. Example from class was instructor asking for questions (polling) vs. students raising hand (interrupt).
  2. Answer the following questions about interrupts: a. What is the main difference between a maskable and a non-maskable interrupt? Maskable interrupts can be turned off by user/program, non-maskable are always active and can not be turned off b. What is the difference between XIRQ’ and IRQ’ interrupts? XIRQ is non-maskable, IRQ is maskable. c. What is an ISR? Interrupt Service Routine d. What information is stored on the stack during an ISR? Return vector (PC value for RTI instruction), all values in the register file (A, B, X, Y, CCR)
  3. Using the table above from Problem 1, determine the following if an interrupt subroutine is currently being executed and the automatically saved register values have already been pushed to stack. a. What value was in the CCR when the interrupt occurred? CCR is at the top, so $ b. What value was in IX when the interrupt occurred? IX is at SP +3 & +4, so $D c. What is the return address for the interrupt routine? Return address is at SP +7&+8, so $
  4. Assume you have a microcontroller with a single non-maskable interrupt pin NMI and an 8-bit bidirectional I/O port PT[7:0]. Using external logic gates, show how you could create a system with two maskable (software enabled/disabled) interrupts using input signals ITN1 & INT2. Sketch the schematic. Assume it is necessary to determine which signal caused the interrupt. This requires 3 pins of port PT. One is an output (o) to generate an active-high interrupt enable (INTen) that can be ANDed with the interrupt signal to create a maskable interrupt. The two interrupt sources can be ORed together to form a single interrupt source. Connecting INT1 and INT2 to PT input (i) pins allows the port to be polled to determine the source of the interrupt.