EE 476: Laboratory 4

Serially controlled, sinewave generator.

Introduction.

You will produce a sinewave generator which is controlled from an RS-232 serial line connected to a PC window (e.g. hyperterm). The sinewave generator frequency will be set by numbers typed on the PC keyboard. The code will display the frequency in the terminal window on the PC.


Procedure:

You will need to build a simple digital-to-analog converter as shown below.

You may want to make a table of sinewave values in flash memory and read them back at a variable rate to make different frequencies. I suggest using timer 1a to generate the timebase for samples. The following code fragment (in a .cseg) produces such a table.

 ;***************************
   ;table of values for a sinwave with peaks of 0xff and 0x00,
   ;and a period of 16 samples 

   sintbl: .db 0x80, 0xb1, 0xda, 0xf6, 0xff, 0xf6, 0xda, 0xb1 
           .db 0x80, 0x4f, 0x26, 0x0a, 0x00, 0x0a, 0x26, 0x4f
 ;*************************** 

Later in the program, you can use an LPM command indexed with the Z register to read out the table.

See the Atmel application notes for 16x16 bit fixed point divide code. There is also a 24x16 bit divide code written locally.

There are at least two ways of handling serial i/o:

The serial port (connector J131) should be connected to COM2 of the PC. You should use a simple terminal program, such as Hyperterminal, on the PC connected to COM2. The terminal program should be set to 9600 baud, no parity, one stop bit, and no flow control. You can use either demo program as a test that the RS232 connnections and terminal program on the PC are correct.

The UART receive is on PortD0, which should be connected to J132, pin1 (the left pin when the buttons are near you). The UART transmit is on PortD1, which should be connected to J132, pin2. These connections assume a RS232 cable to the PC with straight-through connection.

 


Assignment

Write a program and build a circuit which will:

When you demonstrate the program to a staff member, you should exercise the keyboard commands typed from the PC and show that the generated frequency is correct.

Your written lab report should include:


Copyright Cornell University December 1999