EVM5509A Tone Example
The tone example is a slightly more complicated program that directs the AIC23 codec to generate a 1KHz sine wave on the line and headphone outputs. Follow these instructions to load and run the tone example.
Close and projects you were working with previously by selecting Project -> Close. You should also close any open files you have open in your workspace avoid confusion. Click on the X in the upper right hand corner of their windows to close them.
Plug a pair of headphones or speakers into the EVM5509A’s headphone jack
Open the tone.pjt Code Composer project using Project -> Open and selecting tone.pjt. It is in the directory
c:\ti\boards\evm5509a\examples\tone
Load the tone.out executable file. Select File -> Load Program. It will open a file browser dialog. Select the tone.out file in the tone\Debug directory in the file browser and hit "Open" to load the executable file.
Select the Debug -> Run option under the Debug menu. You will hear a 1KHz tone.
After 5 seconds the sound will stop.
When you are satisfied that the program is indeed running correctly, stop the program by selecting Debug -> Halt.
The array sinetable contains a pre-generated sine wave using signed 16-bit data that matches the AIC23. The data covers exactly one period and the amplitude matches the full range of the codec.
#define SINE_TABLE_SIZE 48
/* Pre-generated sine wave data, 16-bit signed samples */
Int16 sinetable[SINE_TABLE_SIZE] = {
0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};
The main loop of the code writes each data point in the sine wave table out to the codec using the AIC23 codec package of the BSL. Each write function sends a single 16 bit sample to the codec. In this case the same data is sent out twice, once to the left channel and once to the right channel. The codec is configured to accept data at a rate of 48,000 stereo samples per second. Since the sine table is 48 entries long, the resulting output wave will be a 1KHz sine wave with the same output on both the left and right channels.
/* Generate a 1KHz sine wave for 5 seconds */
for ( msec = 0 ; msec < 5000 ; msec++ )
{
for ( sample = 0 ; sample < SINE_TABLE_SIZE ; sample++ )
{
while (!EVM5509_AIC23_write16(hCodec, sinetable[sample]));
while (!EVM5509_AIC23_write16(hCodec, sinetable[sample]));
}
}
The McBSP2 serial port is used to transmit data to the codec at a much slower rate than the DSP can process data. It accepts data 16 bits at a time and shifts them out slowly one at a time. The write function returns a 1 if the write is completed successfully or a 0 if the serial channel is busy. The while() loop around the writes waits while the serial port is busy so program can be synchronized to the data rate of the codec.
The following two commands are used to initialize and shut down the codec and are found at the beginning and end of all programs that use BSL codec module. The EVM5509_openCodec() command returns a handle that is passed each of the other codec functions.
/* Start the codec */
hCodec = EVM5509_AIC23_openCodec(0, &config);
/* Close the codec */
EVM5509_AIC23_closeCodec(hCodec);
|