You will need a computer (mac, pc, linux all supported) with an available USB port, free driver for the USB-Serial adapter, a Boston Android Xmega EVAL-USB-64 development board ($31.99) and an open source AVR chip programming utility called AVRDUDE.
Once set up, you can generate sine, ramp, triangle, square or any waveform you define from 5 to 20KHz with amplitude of up to 3.3Vp-p. It is possible to generate faster waveforms with the arbitrary waveform feature (up to 500KHz).
Step 1: What You Need
2) PC with USB port
3) AVRDUDE (free AVR programing software)
Oscilloscope (to view waveforms)
Headphone or small speaker (to listen to waveforms)
WINAVR and AVRSTUDIO to modify the source code and built your own version of the waveform generator software
Although this example walks through programming and using the EVAL-USB-64 board, you can use any of the EVAL-USB boards from Boston Android. And if you're very experienced you can download the example source code and build for other target hardware such as the Atmel XPLAIN evaluation board, or the Xmega boards available from chips45 and Mattair, Megavore. The xmega family allows effortless migration of code from one chip to another.
Step 2: Solder Lead Wires (optional)
Step 3: Installing AVRDUDE
However, if you use a PC running Windows there is a complete binary distribution (no compiling needed) called WINAVR which includes AVRDUDE, along with the AVR-GCC compiler which will allow you to modify and compile your own version of the waveform generator.
Download WINAVR (includes AVRDUDE)
Then install it.
Step 4: Install USB/Serial Drivers
Download VCP Drivers
Step 5: Download Waveform Generator Application
If you are using an alternative platform you will need to download and compile the source code. All the code is in a single .c file which is written to be compiled with AVR-GCC. If you are running on a Windows PC you can download the following two packages and compile and program the application on to your board.
1) Download WINAVR
2) Download AVR Studio IDE
3) Create new avr-gcc project in AVR Studio and paste the source code into the initial .c file
4) Compile (creates .hex file to load onto target device)
Step 6: Program Board
1) Plug your board into the usb port of your PC.
2) Open a command line window.
3) Locate the hex file you downloaded xmega-waveform-serial.hex
4) Within 10 seconds of plugging in your board, execute the following command to load the program image.
avrdude -p x64a3 -c avr911 -P COM5 -b 57600 -e -U flash:w:xmega-waveform-serial.hex
Your com port may be different. To be sure, in windows go to the Device Manager and check "com ports" to see what port your board is connected to. It is almost always the highest numbered com port on your system since the builtin com ports are assigned COM1-4 typically. On my laptop it comes up as COM5 but your computer will likely be on another numbered port.
If you have an Atmel AVRISP mkii or JTAGICE mkii or compatible device you can use Atmel's AVRStudio to program the .hex file you downloaded in the previous step. See Atmel's documentation for using this utility.
Step 7: Connect to Waveform Generator Over Serial Port
Open a serial terminal to the board. Under Windows XP you can use Hyperterm and open a connection to the COM port your device is on (you should know your COM port number from the previous step). Under Vista/7 you can use TeraTerm. The serial port configuration is 9600 Baud, 8N1, no flow control.
After you connect you should be able to type 'h' which will print out the usage instructions for the waveform generation utility.
Step 8: Generate 1KHz Sine Wave
You should be able to measure 1KHz waveform on your oscilloscope or frequency counter. Alternatively you can hook up a speaker or headphone and hear a low constant tone.
Step 9: Generate 1KHz Ramp, Triangle and Square Waves
Step 10: Frequency Limits
Step 11: Arbitrary Waveforms
w [freq] [num data points] [data1] [data2] ... [dataN]
Here is an example arbitrary waveform which is a square wave with a trapezoidal shape repeated at 1KHz and 20 data points:
w 1000 20 0 0 0 0 0 0 0 0 4095 4050 4000 3950 3900 3850 3800 3750 3700 3650 3600 3550
Note the range of data point values is 0 - 4095 (12 bit resolution)
Once the arbitrary waveform is loaded you can change the frequency without re-entering all the data. To keep the same waveform as above change the frequency:
Step 12: Number of Cycles
This works for arbitrary waveforms as well. To go back to infinite cycles enter the following:
Step 13: Connecting a Speaker
1) Solder a 47uF(or whatever you have handy over 1uF) electrolytic capacitor between PORTB header pin 3 and one of the leads to your speaker.
2) Solder the other speaker lead to PORTB header pin 2 (the Gnd pin)
Electrolytic caps are polarized; make sure you connect the positive end of the cap toward the board (PORTB pin 3)
Now set some outputs and listen to them:
I can hear 16KHz sine wave, but above that it's silent..
USE EAR PLUGS WHEN YOU OPERATE HEAVY EQUIPMENT AND POWER TOOLS KIDS! :-)