



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 7
This page cannot be seen from the preview
Don't miss anything!




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.)
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.
Chapter 12 of the manual describes this unit. This unit contains the main MPC823 interrupt controller (among other things).
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.
NOTE: Important information about each of the components that you will be deal-
ing with can be found further on in the lab.
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.
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.