CSE 477 – Hardware Design Capstone
Spring 2003
Carl Ebeling

Lab 3 : 8051 Timers and Interrupts

Objectives:

The goal of this lab is for you to get experience with the timers and interrupts of the 8051, and the stereo codec.  In this lab you will: 

1.      Write a 8051 program that interfaces to an ultrasonic rangefinder or accelerometer.

2.      Complete the 8051 interface to the stereo codec.

By the end of this lab, you will have a complete hardware system that uses inputs from the ultrasonic rangefinder or accelerometer to change the stereo codec output.

8051 Interrupt Example

Make a Keil project using the button.c file in the \\ifilesrv1\courses\cse477\Spring2003\lab3 directory. This program displays a count on 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 use this program in your design for the XSV board.  Don't forget that you need to connect one of the pushbuttons to the appropriate interrupt pin on the DW8051.

8051 Timer Example

The inter.c program in the lab3 folder demonstrates how to time the period of an external clock signal (we will use the clock generator probe 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 using the inter.c file. Attach the clock generator probe from your Lab Kit to the appropriate pin of the DW8051.  The probe only has a pulldown – you must supply a 110 ohm resistor pullup to 5v.  Make sure you connect grounds!

DISCONNECT THE POWER
STRAP YOURSELF IN against static
Make sure you have all grounds connected together
Have someone else double-check your connections before you power up.

 


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

Stereo Codec Interface

You should now complete the stereo codec interface to the 8051.  We will send a sine wave to the codec at varying frequencies.  One way to do this is to look up the sine value from a table. The 8051 has barely enough MIPS to do this at the rate 48KHz, so instead we will build the oscillator in hardware.  This will comprise a counter which is then used to address the sine table.  For example, if we build a 1K table and use a simple counter, we will generate a sine wave with frequency 48KHz/1024 = 48Hz.  To generate higher frequencies, we can increment the counter using larger deltas.  We will allow the 8051 to determine the frequency by supplying the delta value to the counter.  The counter should increment every time the LRCLK ticks.  (This is a relatively low-tech implementation.  For better results, you should use a larger counter and use the low-order bits to interpolate between two entries in the sine table.)

Build and test a design that tests this oscillator by slowly varying the output frequency over a range from 48 to 10,000 Hz.  You should use a simple program to generate the ROM Verilog program for the sine table.  A 1Kx16 ROM will fit into 4 block RAMs.

The final step will be to interface either the ultrasound rangefinder or accelerometer to the project and use that to control the pitch and perhaps volume of the audio output.

The Sonar Rangefinder

The sonar range finder will be used to determine the distance to the closest object directly in front of it. The transducer of the sonar is the black perforated disk with a metal disk behind it. (Note: a transducer is a device that converts signals from one form to another, in our case, from electrical to sound and vice-versa.) The disk generates the sound and vibrates to the echo. The small board that accompanies the disk is its controller. It generates the sound given a rising edge on a digital input and detects the echo by providing a rising edge on a digital output. There is interesting analog circuitry on the controller board that charges up the transducer to the high voltages needed to both generate and sense ultrasound.

The sonar device sends out 16 pulses at 49.5 kHz that travel from the disk and reflect off of the objects in front of it. The first echo to return (from the closest object) is used to raise the output signal. The range finder is started by raising the INIT signal. When the echo returns the ECHO signal goes high. INIT has to stay high at least until ECHO goes high. The sonar board operates this way in the mode you will using (when both BINH and BLNK are low).

Make sure to be careful in handling the board. The device generates high voltages on the controller board and at the transducer leads (in the range of 200 to 400 volts). Touching the sonar circuit board while it is powered up and/or operating may result in a burn.

The range finder board should be connected as follows:

 

Name

GND

BLNK

INIT

ECHO

BINH

VDD

Pin

1 *

2

4

7

8

9

Connect to

0 V

0 V

input

output

0 V

5 V

* Pin 1 is the pin closest to J1

The sonar transducer should be connected to the range finder board as follows:

E1 on the range finder board --> (+) brass tap on black disk
E2 on the range finder board --> (-) black tap on black disk

The ECHO output of the range finder board is an open collector output and should be connected to a 4.7 Kohm pull-up resistor (i.e. connected to 5 V).

Try the following procedure to make sure that your sonar is working properly. Connect INIT to high to start the range finding operation. You should hear a scratching, which is the transducer sending off the 16 pulses. In addition, ECHO goes high immediately. Reset the sonar range finder by making INIT low and ECHO should go low as well. Your can find more documenation about the sonar range finder at the Acroname Web site.  You should also use the logic analyzer to examine the operation of the range finder.

Remember, when connecting the sonar rangefinder to the XSV board:

DISCONNECT THE POWER
STRAP YOURSELF IN against static
Make sure you have all grounds connected together
Have someone else double-check your connections before you power up.

To use the sonar range finder, your program should assert the INIT line high and then wait for the ECHO signal to go high.  It should then use the timer to measure how long it takes for ECHO to be received.  You can convert this into distance using the fact that sound travels through air at 343 m/s.  Your program should use the distance measured to vary the frequency of the audio oscillator.

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. 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. You should use the oscilloscope or logic analyzer to view the accelerometer output signals and that you understand how the PCM output signals work.

Remember, when connecting the accelerometer to the XSV board:

DISCONNECT THE POWER
STRAP YOURSELF IN against static
Make sure you have all grounds connected together
Have someone else double-check your connections before you power up.

Next, you must decide how to interface the accelerometer to the microcontroller so that the two acceleration values are available to a program running in the microcontroller.  You should use tilt on one axis to vary the pitch, and the tilt of the other axis to vary the volume of the audio signal.  Write a program that measures the tilt of both axes and uses one to change the delta presented to the audio oscillator, and the other to change the scale factor that is applied to the oscillator output.

What to Turnin

  1. Demo your final project and have it signed off.  Turn in the signed off schematics and Verilog programs.