EE 476: Laboratory 5
Sinewave generator.
Introduction.
You will produce a sinewave generator which is controlled by a 16-key keypad
and which shows the frequency on a LCD display.
Procedure:
You will need to build a simple digital-to-analog converter as shown below.
The Liquid Crystal Display (LCD):
A 16 character, one line (16x1), LCD display will show the frequency for the
sinewave generator. The display we are using has an industry-standard interface.
A data sheet for a similar display shows
the connections. There are several aspects of the display you should note:
- Connecting the power backwards will destroy it.
Always check the polarity before connecting the display.
- The 14 pin header is on the upper-left corner of the display. Pin 1 is
closest to the left edge of the pc-board.
- Since the display only draws about 1-2 mA, you can use port pin 10 for
power. You will need a 10k or 20k trimpot to adjust display contrast as shown
in the following program. The C LCD interface to the mcu is documented in
the CodevisionC libraries and in a short C program
which you can use to test your LCD connections.
- The character representation is identical to ASCII codes for numbers, letters
and most symbols. Refer to the data sheet above for a complete listing.
Here is a sample C code which outputs a sinewave of
a user-selectable, fixed frequency. The program
organization page has an example of squarewave synthesis in C
and ASM.
The same program is recoded using a mixture
of C and ASM (as you will need to do for this assignment).
Be sure to read the serial
communication page if you are going to debug using the time-honored printf
.
Assignment
Write a program and build a circuit which will:
- Generate sinewaves with 16 samples (or more) per cycle and a frequency range
from 500 to 5000 Hz (or more). The sinewaves should be built from 8-bit samples
and converted to a voltage with a DAC. Note that you will need to use assembly
language ISRs to get much above 2.6 kHz.
- Scan the keypad for one of three commands (which could be single keystrokes):
- stop the sinewave
- start the sinewave
- clear current entry
- When started, produce a sinewave from the DAC, and display the sinewave
frequency on the LCD display.
- When stopped, accept a four digit number from the keypad to set a new frequency,
and display the frequency on the LCD. Clear entry should erase any digits
on the display.
When you demonstrate the program to a staff member, you should exercise the
keypad commands and show that the generated frequency is correct. Full credit
will be given only if you can generate sinewaves above 5 kHz (with at least
16 samples/cycle).
Your written lab report should include:
- The scheme you used to decode commands.
- The scheme you used to convert the ASCII input to a frequency.
- A heavily commented listing of your code.
- A schematic of your circuit.
- A waveform captured from the oscilloscope showing the waveform you generated.
Copyright Cornell University December 2000