Lab 5: Timer and Multiple Interrupts | EECS 373, Lab Reports of Electrical and Electronics Engineering

Material Type: Lab; Class: Des Microproc Syst; Subject: Electrical Engineering And Computer Science; University: University of Michigan - Ann Arbor; Term: Fall 1998;

Typology: Lab Reports

Pre 2010

Uploaded on 09/02/2009

koofers-user-7lp-1
koofers-user-7lp-1 🇺🇸

7 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Page 1 of 7
EECS 373 Fall 1998
Lab 5: Timers & Multiple Interrupts
Introduction:
In this lab, you will modify your lab 4 code so that all events are interrupt
driven. Currently, your lab 4 code uses interrupts for serial communication, but
your LED flashing is still done with a busy wait. To make the LED flashing inter-
rupt driven, you will use timers to periodically interrupt your program and flash the
LED. The interrupt method is a much more effective way to produce the delay
because you waste no CPU cycles doing a busy wait.
To show that you will have greater control over the timing with an actual
timer, you will use the timer to very rapidly blink the LED. Instead of reading a
pattern string, a single variable will indicate the duty cycle (ratio of on-time vs. off-
time) for the LED blinking. By flashing the LED rapidly, while controlling the per-
centage of time that the LED spends in the on state, you can control the apparent
intensity (brightness) of the LED. (For example, if your duty cycle is 20%, the LED
will be in an on state 20% of the time and have roughly 20% of its normal inten-
sity.) You will implement new command-line instructions in your serial handler to
control the brightness.
The MPC823 chip has many timers intended for various different purposes.
In addition to the very fast timer that you will be using to control the duty cycle of
the LED, there is a real-time counter (RTC) on chip. This counter ticks once per
second and can be set to interrupt the processor each time the clock ticks. At pro-
gram startup, you will initialize this counter to zero, and you will implement a com-
mand to print out the number of seconds since program startup.
Finally, to demonstrate the fact that a computer can accomplish many things
at once, your main program will be required to generate prime numbers, and you
will implement a command to display the largest prime that has been computed at
that time.
Since this lab is heavily focused on working with the hardware, it is difficult to
simulate this program. You should concentrate on the prelab and on developing
and testing individual pieces of code separately. (For example, you should cer-
tainly be able to use the simulator to test the prime number generation code that
you write. You can also test your ISR code on the simulator by manually setting
the PC and other register values and stepping through it.)
NOTE: Read through this entire lab before you begin. There is a great deal of
useful information available to you. Focus on understanding the big picture before
you begin. If you do not get it, please see a TA in office hours.
pf3
pf4
pf5

Partial preview of the text

Download Lab 5: Timer and Multiple Interrupts | EECS 373 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

EECS 373 Fall 1998

Lab 5: Timers & Multiple Interrupts

Introduction:

In this lab, you will modify your lab 4 code so that all events are interrupt driven. Currently, your lab 4 code uses interrupts for serial communication, but your LED flashing is still done with a busy wait. To make the LED flashing inter- rupt driven, you will use timers to periodically interrupt your program and flash the LED. The interrupt method is a much more effective way to produce the delay because you waste no CPU cycles doing a busy wait.

To show that you will have greater control over the timing with an actual timer, you will use the timer to very rapidly blink the LED. Instead of reading a pattern string, a single variable will indicate the duty cycle (ratio of on-time vs. off-

time) for the LED blinking. By flashing the LED rapidly, while controlling the per- centage of time that the LED spends in the on state, you can control the apparent

intensity (brightness) of the LED. (For example, if your duty cycle is 20%, the LED will be in an on state 20% of the time and have roughly 20% of its normal inten- sity.) You will implement new command-line instructions in your serial handler to

control the brightness.

The MPC823 chip has many timers intended for various different purposes. In addition to the very fast timer that you will be using to control the duty cycle of the LED, there is a real-time counter (RTC) on chip. This counter ticks once per

second and can be set to interrupt the processor each time the clock ticks. At pro- gram startup, you will initialize this counter to zero, and you will implement a com- mand to print out the number of seconds since program startup.

Finally, to demonstrate the fact that a computer can accomplish many things

at once, your main program will be required to generate prime numbers, and you will implement a command to display the largest prime that has been computed at that time.

Since this lab is heavily focused on working with the hardware, it is difficult to

simulate this program. You should concentrate on the prelab and on developing and testing individual pieces of code separately. (For example, you should cer-

tainly be able to use the simulator to test the prime number generation code that you write. You can also test your ISR code on the simulator by manually setting the PC and other register values and stepping through it.)

NOTE: Read through this entire lab before you begin. There is a great deal of

useful information available to you. Focus on understanding the big picture before you begin. If you do not get it, please see a TA in office hours.

Goals:

  1. To understand how interrupt controllers are used.
  2. To understand how nested interrupts work.
  3. To learn about timers and their uses.
  4. To learn how to make a machine accomplish several tasks at once.

Definitions:

  • SIU – System Interface Unit

Chapter 12 of the manual describes this unit. This unit contains the main MPC823 interrupt controller (among other things).

  • CPM – Communications Processor Module The MPC823 chip contains a second processor (in addition to the Pow- erPC core) that is responsible for handling low-level communications tasks. Chapter 16 of the manual describes this piece of the processor. (Don’t worry, we don’t expect you to read all of it.)
  • Nested Interrupt A nested interrupt occurs when you are in an Interrupt Service Routine and

that routine gets interrupted. Remember that when the processor enters an ISR, interrupts are disabled. You must re-enable them manually in your ISR to allow

nested interrupts. You should be doing this for this lab.

Prelab:

NOTE: Important information about each of the components that you will be deal-

ing with can be found further on in the lab.

  1. Draw a block diagram showing the interrupt structure for all of the interrupts that you must be able to handle. This block diagram should include the proces- sor, the devices and the interrupt controllers that you are working with.
  2. Write C-style pseudocode that shows how your external interrupt handler will work. You only need to show the checks that you need to do to determine which interrupts are called. Remember that you always have to check the SIU on an external interrupt, and you may have to check registers in the CPM as well to determine exactly which interrupt is occurring. (See hints section.)
  3. Draw individual flow charts for the handler routines that service the serial inter- rupt, the Real-Time Counter (RTC) interrupt, and the timer interrupt. Be detailed enough that you indicate what you must do to each register.
  4. Write the assembly code required for initializing each of the devices that you will be working with.
  5. Write assembly code that reads the IMMR value, and uses it as the base address to access another memory-mapped MPC823 register.
  6. Assuming a 24 MHz system clock and an LED blinking rate of 10 kHz, give a range of timer input clock rates that would be reasonable for using the timer to control the LED. Remember that you need to take separate interrupts to turn the LED on and off, and that you need to time those interrupts with an accu-

The Timer Handler: (NOTE: There are four timers on the MPC823. Use Timer1.) This handler will be responsible for handling the interrupts from the timer. Your this handler will be responsible for resetting the timer counter register and setting the value that should be in the timer reference register.

The Prime Number Generator: The purpose of this portion of the lab is to show that interrupts allow the pro- cessor to accomplish a lot of things at once efficiently. The main portion of the program should be continuously calculating prime numbers. You should start with 2 and keep trying to find larger and larger prime numbers. Each time you find a prime, you should save that number in memory and then search for the next larger prime number. It is not necessary for this code to be extremely efficient in finding prime numbers, but it should be able to find prime numbers in the thousands and even higher in a reasonable amount of time.

Add, + This command takes two integer parameters (signed words) and displays the sum. Sub, - This command takes two integer parameters (signed words) and displays the difference. (Parameter 1 – Parameter 2) Help,? This command should print out a help message which describes all of the available commands. It should be multi line and take up at least 100 bytes. (This is mostly for testing purposes). Led This instruction takes a single parameter in the range 0-100 and alters the duty cycle of the timer accordingly. Numbers should be treated as unsigned, and numbers greater than 100 should be treated as 100. If 0 (zero) is input, disable the interrupt and turn the LED off. Remember that you will have to re-enable the inter- rupt in order to start the routine again. Time This command will print the number of seconds since program began. Prime This command prints out the largest prime number that has been calculated in decimal format.

Details:

Internal Memory Map Register (IMMR) The IMMR is described on p12-34 of the manual. Most of the device registers that you will be using in this lab are memory mapped. Because there are many different ways that you may want to configure your memory map, it is possible to move the location of these registers. These registers are offset from a base register called IMMR (e.g. the SIPEND register is located at (IMMR & 0xFFFF0000 + 0x10.) The IMMR is a special purpose register (number 638), and it can be read using the mfspr instruction. You should read the value of the MSR into a register at the beginning of each handler and offset from that value. Machine Status Register (MSR) The bit assignments for the MSR can be found on p6- In the MSR, you will need to Enable External interrupts, and clear the Interrupt Prefix bit. Each time you enter an ISR, the External Interrupt Enable (EE) bit will be cleared to disable all external interrupts. To allow nested interrupts, you will have to reenable the interrupts near the beginning of your ISR. System Clock and Reset Control Register (SCCR) The bit assignments for the SCCR can be found on p5- The real-time counter has several options for input clocks In this lab, we want the RTC to trigger once every second, so to do that, we will want to use the Main Clock Oscillator (OSCM), and divide by four to properly prescale the OSCM. SIU Interrupt Controller Section 12.3 of the manual deals with the SIU Interrupt Controller SIPEND – SIU Interrupt Pending Register p12-

This register contains a list of interrupts that are currently pending.

SIMASK – SIU Interrupt Mask Register p12-

This register is used to set a mask indicating which interrupts you are interested in handling. In this lab, you are only interested in handling interrupts for the RTC and the CPM. You can clear the rest of the mask bits. SIVEC – SIU Interrupt Vector Register p12-

When handling the external register, you will check this register to determine which event triggered the external interrupt. You will use the value in INTC to vector from a base address into a jump table. Real-Time Couter Section 12.7 of the manual deals with the real-time clock RTCSC – Real-Time Clock Status and Control Register p12-

There are several things that you will have to set up in this register to configure the real-time counter. The RTCIRQ should be set so that it will trigger the Level 0 interrupt. The value that we get from table 12-1 is 00000100b The SEC bit must be cleared each time you handle the interrupt and at startup. The 38K bit should be cleared. Set the SIE bit. Clear the ALE bit Clear the RTF bit Set the RTE bit. RTC – Real-Time Clock Register p12-

You should initialize this register to zero on program startup. You can read this register at any time to determine the current number of sec- onds since the program has begun.

Notes and hints:

  1. The main code for your interrupt handler should take care of the register sav- ing, and then use if-then type statements to determine which external interrupt was handled. When you know which handler you have to work with, your pro- gram should branch to that point.
  2. You can find helpful information in the white MPC823 manual on how many of these things work. If you need help, the book is a very good resource.
  3. To allow the board to handle the external interrupt, you will need to enter the following command in the SDS command window: @ der = 0xFDE7400F

Procedure (in the lab):

  1. After you have verified as much of your program as possible using the simula- tor, start the SingleStep OnChip debugger and download your program to the target board.
  2. Test your program thoroughly. Be sure to try a variety of LED duty cycles while typing ‘help’repeatedly to print the help message. This should stress your interrupt handlers the most.
  3. Once you have tested your program thoroughly, use the oscilloscope to probe the voltage on the LED (BE CAREFUL). Observe and measure the duty cycle as you vary the intended duty cycle from the command line. Report your find- ings.
  4. Print a listing file of your complete program and demonstrate it to the TA. The TA will sign your listing. Turn the signed copy in with your lab report.

Lab report: (due at the beginning of your next lab section)

  1. Briefly summarize the function of your program.
  2. Describe how your program operates: the individual steps and algorithms involved. Be thorough but not verbose; two or three paragraphs should be suf- ficient.
  3. Include a well-commented listing of your program. Comments should include register usage (i.e. which variables are kept in which registers), descriptions of all symbols, and explanation of all derived expressions. If you add comments after you demonstrate to the TA, be sure to include both the commented listing and the signed listing.
  4. Discuss any difficulties you may have had in getting your program to work cor- rectly: what parts of the program were hard to write initially, what types of bugs did you have to fix, etc.
  5. Discuss any limitations your program may have.