Overview

The purpose gain experience with the hardware interrupt and timer/counter subsystems.

Problem Statement

In this lab, you will design, code, assemble, simulate, download and run a program. Your program should make it appear as if two programs are running simultaneously on our board:

  1. Your bouncing light program from lab 3.
  2. A program that displays the number of seconds that have elapsed on the LCD.

Details

You should use your code from lab 3 to implement the functionality for the first program.

The functionality for the second program should be implemented by making use of the interrupt and timer/counter0 subsystems. The LCD should display a decimal value between 0 and 99. A 0 should appear approximately one second after a 99 (counter value wraps around at 99).

Counting in Decimal

Note that your program should count up from 0 to 99 in decimal. This means that you must display "10" and not "A" (the hexadecimal equivalent). The count value should be Binary Coded Decimal (BCD). Basically we need to ensure that if we add 1 to 9 we get "10" and not "A". We can do this using the following fairly involved algorithm:

Many CPUs have an instruction called Decimal Adjust for Addition (DDA) that does this for us. However, the ATmega32 has a RISC (Reduced Instruction Set Computer) type architecture and doesn't provide this instruction. For this assignment, you may use this function to handle the correction for BCD.

Achieving Sufficient Delay

You must use the Timer/Counter0 to provide a delay of approximately 1 second between counter increments. (Your program should take between 97 and 103 seconds to count from 0 to 99.) Recall from lecture that the maximum time between overflows (counting from 0 to 255 in TCNT0) is 32.768ms. As a result, the ISR for the timer overflow interrupt will be called every 32.768ms. Within the ISR you'll need to keep track of when to actually implement the count that is displayed on the LCD (and then display it). To do this, you'll need to keep track of two counts: a) counter for how many times to run the ISR without incrementing the LCD counter and b) the LCD counter. Keep in mind that you'll need to store these values in SRAM so that they are available to you the next time you enter the ISR.

Other Notes

Most of the code for this lab should already be written. You'll need to write code to configure the interrupt and timer/counter subsystems. You'll then need to write the ovf0ISR function that handles the overflow timer interrupt.

Pre-laboratory activity (due on entering the week 8 lab)

Prior to entering the room, you must submit a documented lab7.lst file using the online submission form. The file should contain a complete solution for this lab assignment except that your ovf0ISR function can just have a return from interrupt instruction. The program that you submit as part of the pre-lab should run on your board but will not show the updates to the LCD.

Laboratory Demonstration (due 5pm the day prior to the week 9 lab)

You must demonstrate your program working on your board.

Laboratory Report (due 11pm the day prior to the week 9 lab)

You should submit the documented .lst file for your program using the online submission form.

In addition to the standard documentation, your source file should contain a couple of sentences that describe one thing that you discovered about the interrupt and/or timer/counter subsystems that you learned but didn't need to know in order to complete the assignment.

Also, you must log the time you spent on this assignment (including the pre-laboratory activity) in FAST (in the week 8 column).

Acknowledgment

This assignment is based on a similar assignment developed by Prof. Bill Barnekow.

I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to.
© 2001-2007 Dr. Christopher C. Taylor Office: L-343 Phone: 277-7339