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, two line (16x2), LCD display will
show the frequency for the sinewave generator. The display we are using has
an industry-standard interface. A more detailed data
sheet for a similar display shows the command set. 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 lower-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 VTG pin for
+5 volts. You will need a 10k or 20k trimpot to adjust display contrast connected
as shown in the following program. The 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. Note that this program uses
a software delay to time the display, something you should never do if your
program has to respond to external events.
- The character representation is identical to ASCII codes for numbers, letters
and most symbols. Refer to the data sheet above for a complete listing.
- The LCD display is arranged as 2 lines of 16 characters and is addressable
on a per-character basis.
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 5 kHz (with an 8 MHz crystal).
- 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 10 kHz (with at least
16 samples/cycle) with an 8 MHz crystal.
Your written lab report should include:
- The scheme you used to decode commands.
- The scheme you used to convert the character 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 Jan 2002