HOME

Lab components

Objective

Reading

Part 1

Part 2

Part 3

Part 4

Turnin

CSE 477: Embedded System Design
(Spring 2002)
Lab 3: 
Microcontrollers: Part III
Timers and Interrupts

Objectives:

In this lab will you will learn the following: 

  • Timers and Interrupts
    • how to write an interrupt routine using the Keil C compiler.
    • how to set up timers and counters using the special function registers (sfr), such as TCON and TMOD.
    • how to use multiple interrupts to do timing.
  • Microcontrollers
    • how to find and read pinouts from specifications
  • Two-axis Accelerometers
    • how to interface an accelerometer to a microcontroller.
This lab comprises several parts and will take both lab periods of the second week.

Reading

You will need to understand how to use the timers and interrupts and write interrupt routines.  These are covered in the:

  • DW8051 Datasheet
  • Keil Compiler Manual
  • We will also be using an Analog Devices two-axis ADXL210 Accelerometer

Part 1- Using the External Program Memory

We are going to start using the external memory for programs instead of the ROM since we don't want to reimplement the FPGA every time we try a new program.  Use the left memory bank for this purpose.  You will need to wire the IROM bus to this memory instead of the ROM we were using before.  This includes the address bus and the CE, WE and OE signals to the memory.

To simulate with this external memory, you can still use the ROM solution that we used before, but when implementing the chip, you need to replace this with the external memory connection.

The 8051 Lab page describes how to generate a file that can be downloaded into one of the RAMs on the XSV board.  You first convert the HEX file to binary, and then download it to memory using a special bit file.  After the program has been downloaded, you can download your project bit file.

Try this out with the program you wrote for Lab 2.


Part 2 - External Interrupt Example 

Make a Keil project using the existing button.c file found in the \\ifilesrv1\courses\cse477\lab3 directory. This program displays a count on the the 7-segment display, but an interrupt routine has been added that lights up all the LEDs on the digit display when the button is pressed. The trigger for this interrupt routine comes from an external interrupt pin. This interrupt is generated by a pin on the DW8051, which must be connected to one of the push buttons on the XSV-300 board.

Compile and download this program to the XSV board using the external memory.  Don't forget that you will need to wire one of the pushbuttons to the appropriate interrupt pin on the DW8051.


Part 3 - Clocking Example 

The inter.c program in the lab3 folder demonstrates how to time the period of an external clock signal (this clock is the oscillator that is found in the lab kits). In summary, one interrupt routine keeps track of elapsed time and the other interrupt routine counts 10 cycles of the clock. The 7-segment display is changed every 10 cycles to show the current clock frequency.  What code is used to display this frequency?

Make a Keil project with the inter.c file. Attach the clock generator probe from your Lab Kit to the appropriate pin of the DW8051.
 


(You can check that the output of the  clock goes high and low with the probe) 


Part 4 - Accelerometer Interface 

The accelerometer we will give you measures acceleration along two orthogonal axes.  It can be used to measure tilt in the X and Y dimensions by measuring the force of gravity in each dimension.  The measured acceleration is given on two pins, one for each dimension, using a pulse width code as described in class and in the documentation.  You should decide how to interface the accelerometer to the microcontroller so that the two acceleration values are available to a program running in the microcontroller.

Write a program that uses the 7-segment display to implement an electronic level that shows the tilt of the accelerometer.  Light up a segment (or two) to show in which direction the accelerometer is tilted.  If there is no tilt, light up the center segment.  For extra credit, flash the lights to indicate the degree of tilt.  Think about the user interface when designing this part.  For example, you need to figure out how to re-zero the tilt-o-meter.

This is a good time to play with the SFR's to customize our 8051.  Choose some addresses that are not used and create the following registers:

  1. Display 1 Direct: The low-order 7 bits drive the segments of the high-order display directly
  2. Display 0 Direct: The low-order 7 bits drive the segments of the low-order display directly
  3. Display encoded: The two-digit number encoded in the 8 bits is displayed using HEX.
Use the information and programs from previous parts to get started. The accelerometer works in a simple way. There are outputs for the x direction and y direction (one pin x, one pin y). When the duty cycle of the output pin is about 50%, then the accelerometer is level in that direction. If the duty cycle is bigger or smaller than 50%, the accelerometer is tilted to one side or the other in that direction. The resistor added to the accelerometer determines the period of the output. The 1.2 Mohm gives a 10 ms period.
 
 
Careful:
WATCH POWER AND GROUND
DON'T DROP, OR IT BREAKS

Here is the interface to the accelerometer:
 
E B D C A
Common (Gnd) self test Xout Yout Vdd

 


What to Turnin
Demonstrate part all parts and hand in the code for interfacing to the accelerometer. You should also be able to answer detailed questions about every part.

 BACK TO TOP

 Last Updated:
4/3/00

Contact the instructor at:cse477-webmaster@u.washington.edu