You must be prepared to discuss your work at the beginning of your laboratory session on Tuesday, November 17, and to demonstrate your program to your TA during that period. This part of the assignment is worth 30 points.
The computer could copy a voltage by sampling it with the A/D converter and writing the samples to the D/A converter. If the signal is to be reproduced accurately, it must be sampled at twice the highest frequency component. For speech, good quality can be obtained with about 8,000 samples per second; music could require up to 40,000 samples per second.
The A/D and D/A converters form an input/output pair in much the same way as the UART forms an input/output pair. Suppose that a program is reading a signal from the A/D converter, possibly processing it in some way, and then writing it to the D/A converter. In this case the same sampling rate should be used to control both the reading and the writing. The simplest implementation ties the two sampling rates by placing both operations -- reading from the A/D converter and writing to the D/A converter -- in the same interrupt handler.
This leads to the idea of an A/D converter module that is similar to the module used to encapsulate the UART in a previous homework: Two circular buffers provide communication between an interrupt handler in the module and the remainder of the program, and the module exports C-callable routines to
Operations that enable and disable counter interrupts are similar to those implemented in the previous assignment.
Obtaining a sample from the A/D converter is simply a matter of reading a byte from location $300001. (Use an EQU to map this address to an appropriate symbol.) The A/D converter works by successively approximating the analog signal, effectively searching for the byte value that best matches the voltage. This process takes time, so when the CPU reads a byte there is a delay before the value becomes available. The result is that a move.b instruction whose source operand is $300001 can take up to 2 microseconds to complete. This is in sharp contrast to the 0.75 microseconds required for the same instruction with a source operand in memory and data register destination.
When an interrupt occurs, the interrupt handler must obtain a sample from the A/D converter and add it to the A/D circular buffer. (Review the earlier discussion about using circular buffers for communication between interrupt handlers and other programs.) It must then remove a sample from the D/A circular buffer and write it to the D/A converter. Thus, for each interrupt, a sample is read and a sample is written. The sampling rates for input and output are therefore the same.
If the sound coming from the headphones sounds distorted, turn down
the volume on the sound source.
Task
Design and implement a program that provides a sound storage and
playback facility.
The overall behavior of your program can be described as follows.
The program samples an input signal by reading samples from the A/D converter at a rate of approximately 15,000 samples per second. Normally, these samples should be written to the D/A converter.
When the user sends the r to UART 2, the program begins to store the samples as well as writing them. Samples are stored until either:
Sending r at any time (including the time during which samples are being stored) starts the storage of samples anew at the beginning of the storage area.
Sending p at any time (including the time during which samples are being played back from the storage area) starts the playback of samples anew at the beginning of the storage area. Stored samples are played back until either:
If the playback is terminated by exhaustion of stored samples, the output of the D/A converter should produce silence. (Thus no sound should reach the headphones.) Sending p will then play the current buffer again, sending r will start recording and copying, and sending any other character will start copying.
Your program must contain at least three source files (it may contain more):
After enabling the A/D conversion process, the main program must enter a loop that monitors the devices. It must copy samples from the A/D circular buffer to the D/A circular buffer when that is appropriate, and alter its behavior in response to characters it receives from the UART. The current behavior (recording, playing, etc.) determines what the program does with extracted samples, and which samples it inserts.
You may use a specific character (like Control-C) to terminate the program, or you may simply let the loop run forever.
No code is supplied in support of this assignment.
Feel free to re-use any code that was given to you earlier or that you
developed for earlier assignments.
Design Questions
| Instructor | Revision $Revision: 1.38 $ ($Date: 2007/08/27 00:15:44 $) |