Sound Wave Player Using the ATMEL AT90S8515 Micro-controller
By Ariel Paling
The sound wave player, based on the EOD generator by Prof. Bruce Land, takes a number of digitized signals and plays them back with the appropriate user specifications. The player is the basis for a field-portable sound player that replays animal calls and sounds.
1. Store and play up to 8 waveforms
2. Handle waveforms sampled up to 100kHz with anywhere from 1-32Kbytes
3. Use byte size (8-Bit) samples
4. Play up to 255 repetitions of the waveform
5. Variable time between repetitions of up to 1 sec
6. Allow the download of several waveforms of variable lengths
7. Display the current song number
In the AT90S8515, there are four interrupts used. A reset interrupt executes on power-up. Counters keep track of the time for each sample value and the time delay between the waveforms. A compare-register interrupt keeps track of the sample playtime. A counter-overflow interrupt sends a signal when the time for each delay unit expires on the delay-between-waveforms counter. Finally, an interrupt is used for the RS-232 download function; this interrupt signals the arrival of a new byte on the RS-232 line. The RAM is extended to 32Kb to hold the waveforms, and divided into 8 slots. These slots may be overwritten when a song is bigger than one slot. For each song, the ending address of the song is stored in the first 2-bytes of the slot space. The slot space is as follows:
Slot 1 - 0x0100
Slot 5 - 0x4080
Slot 2 - 0x10E0
Slot 6 - 0x5060
Slot 3 - 0x20C0
Slot 7 - 0x6040
Slot 4 - 0x30A0
Slot 8 - 0x7020
Assembly code is used to control each of the modules mentioned above. The above MatLab file creates a waveform for the circuit. The assembly behaves in the following:
1. After the reset interrupt is given, the counters are stopped and cleared, the input and output ports are initialized, timer interrupts are set, UART initialized, and RS-232 rate set. The RAM is cleared, and the first 2 bytes of each slot are set to point to themselves. The slot number variable is initialized to 1, slot pointer is set to the first slot address, and the sample pointer is set to the first sample address at 0x0102. The download state machine goes into the idle state.
2. A play-loop, which runs concurrently with the RS-232 and the counters, always outputs the slot number of the current song to the LEDs, checks for either a forward signal, play signal, or for a non-idle RS232, and allows each to run independently and exclusive from one another.
3. Play executes from the play loop. It starts the first counter, t1, which starts the song.
4. t1 executes, checks for the total number of waves played, and starts the delay counter, t0, while shutting itself off, or shuts both counters off depending on the number of waves to be played.
5. An overflow of t0 runs an interrupt that checks for the correct amount of delay, and starts t1 immediately after itself.
6. On a RS-232 character receive, the recieve interrupt executes and downloads the necessary values for the new song, the song itself, runs a preview of the song, and restarts the play loop.
After setting up the Atmel STK 200 Board with the computer serial cable connection and programming the microcontroller with the assembly code or hex file provided, the board is ready to download songs from the computer. The number of the song being played is given in binary with LED's. The LED's connect to pins from port D (PD); the pins are PD1 (Least Significant Bit), PD2, and PD3 (Most Significant Bit). The binary output, or each sample of the song, is accesible through pins from port B, PB0 being the least significant bit, and PB7 the most significant bit. The D/A converter (We used the AD557, from Analog Devices) should be connected as shown in Fig. 2 of the AD557 PDF Data Sheets, to port B. The output of the D/A goes to an amplifier and then to the speakers.
Note: If you have a computer with speakers and a sound card, you can test the setup by connecting the output of the D/A converter to the MIC input of the soundcard in your computer. The soundcard acts as an amplifier, and takes the song to the speakers of your system.
The board is now ready to play songs directly to the speakers. You may use one of the song files provided (Sine Waves: 100Hz, 200Hz, 400Hz. Square Waves: 100Hz, 500Hz), or create a new song file. By using the MATLAB script provided, songs directly downloadable to the board may be created. First, open MATLAB, and edit the provided MATLAB file. Under the USER section, the parameters to creating new songs are found. Edit these parameters as needed by your song. On the MATLAB file you can find a small description of each user-defined parameter. After you run the matlab file, a new file ready to download is produced. Use Microsoft's Hyperterminal, with 9600 BPS, 8 Data bits, no parity, 1 stop bit, and no flow control, to send the file produced by MATLAB; the "Send Text File.." under the "Transfer" menu choice must be used to send the song file to the board. After downloading the song, the board plays it back.
Note: If the song is not heard immidiately, then download the song again. Other PC tasks and interrupts may cause glitches that may send a reset-download signal through the serial port to the board while downloading a song, preventing the sample play function to execute.
The user interface push buttons are:
PD5 - Forward (Advance to next song) Button
PD4 - Play Song
Ø Up to 8 songs
Ø Max frequency of 520KHz
Ø Min frequency of 2KHz
Ø Max delay between waves of 0.969 sec
Ø Max repetitions of 255
Known Circuit Behavior
Playing a non-existing song, or a song from reset, will give the reset values, and the delay between waves that is common to all songs. This could be improved by checking a NULL value from the calculation of the ending byte and the initial byte of each song, and cancelling the delay loop if no song is found.
The download of the program into the microcontroller sends noise into the output due to the use of port B as an incoming data port. This is tolerable since the player will not be used while downloading a song into it.
If song is not heard immidiately after download, then download the song again. Other PC tasks and interrupts may cause glitches that may send a reset-download signal through the serial port to the board while downloading a song, preventing the sample play function to execute.