0% found this document useful (0 votes)
8 views

Lab Report 6_dsp

The document outlines Experiment No. 6 for Electrical and Computer Engineering students at Air University, focusing on interfacing the TLV320AIC23 codec for digital audio processing. It details the objectives, equipment required, and the functionality of the codec, including ADC and DAC operations, interrupt handling, and sine wave generation. The lab assessment criteria and a sample code for generating a sinusoidal waveform using a lookup table are also included.

Uploaded by

AHMAD MEHMOOD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lab Report 6_dsp

The document outlines Experiment No. 6 for Electrical and Computer Engineering students at Air University, focusing on interfacing the TLV320AIC23 codec for digital audio processing. It details the objectives, equipment required, and the functionality of the codec, including ADC and DAC operations, interrupt handling, and sine wave generation. The lab assessment criteria and a sample code for generating a sinusoidal waveform using a lookup table are also included.

Uploaded by

AHMAD MEHMOOD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO 6

Lab Title: INTERFACING TLV320AIC23 CODEC, USE OF DAC AND ADC


Student Name: Ahmad Mehmood Reg. No: 212097
Objective: Familiarization with AIC23 CODEC

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes (5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows the
lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Obtained Marks:

Date: 24-10-2024 Signature


Mark

1|Page
Lab Report 6

INTERFACING TLV320AIC23 CODEC, USE OF DAC AND ADC


Objectives:

• Introducing students to AIC23 Codec in DSK


• Generation of sinusoidal waveform through a lookup table and displaying output on
oscilloscope
• Using AIC23 codec to take real time input signal from Function Generator and display the
waveform on oscilloscope

Equipment required:

• C6713 DSK
• Power Cable
• USB Cable
• Code Composer Studio v5.1.0
• Function Generator
• Oscilloscope

Background Knowledge:
AIC23 Codec:
The DSK uses a Texas Instruments AIC23 (part #TLV320AIC23) stereo codec for input and output of
audio signals.

DSP system with input and output


The codec samples analog signals on the microphone or line inputs and converts them into digital
data so it can be processed by the DSP. When the DSP is finished with the data processing, it uses the
codec to convert the samples back into analog signals on the line and headphone outputs so the user
can hear the output. The codec, located on DSK, interfaces the DSP chip to the analog environment,
such as signal generator, oscilloscope, or stereo headphones. The ADC circuitry on the codec converts
the input analog signal to a digital representation to be processed by the DSP.

The codec communicates using two serial channels, one to control the codec’s internal configuration
registers and one to send and receive digital audio samples. McBSP0 is used as the unidirectional
control channel. It should be programmed to send a 16-bit control word to the AIC23 in SPI format.
The top 7 bits of the control word should specify the register to be modified and the lower 9 should

2|Page
contain the register value. The control channel is only used when configuring the codec, it is generally
idle when audio data is being transmitted, McBSP1 is used as the bi-directional data channel. Many
data formats are supported based on the three variables of sample width, clock signal source and
serial data format. The DSK examples generally use a 16-bit sample width with the codec in master
mode, so it generates the frame sync and bit clocks at the correct sample rate. The preferred serial
format is DSP mode which is designed specifically to operate with the McBSP ports on TI DSPs.
The codec has a 12MHz system clock. The 12MHz system clock corresponds to USB sample rate mode,
named because many USB systems use a 12MHz clock and can use the same clock for both the codec
and USB controller. The internal sample rate generate subdivides the 12MHz clock to generate
common frequencies such as 48KHz, 44.1KHz and 8KHz. The sample rate is set by the codec’s
SAMPLERATE register. The figure below shows the codec interface on the C6713 DSK.

DSK6713 Codec Interface


Once the digital signal is processed, a DAC is used which performs the reverse operation of ADC. An
output filter smooths out or reconstructs the output analog signal. ADC, DAC, and all required filtering
operations are performed by the single-chip codec AIC23 on the DSK. The coder and decoder support
data word lengths of 16b, 20b, 24b, and 32b. The ADC converts an input signal into discrete output
in a 2’s complement format which corresponds to the analog signal value. The DAC includes an
interpolation filter and a digital modulator. A decimation filter reduces the digital data rate to the
sampling rate. The DAC’s output is first passed through an internal lowpass reconstruction filter to
produce an output analog signal.
Sampling:
Internally, the sampler is over-sampling at 250-384 times fs, depending on fs. This is a common
practice when using delta-sigma modulators. A delta-sigma modulator takes the current sample and
compares it with the previous sample. If the current sample is larger (or smaller) than the previous
sample, it makes the current sample the previous sample plus (or minus) some fixed amplitude δ. An
additional advantage of over-sampling is that images of the input signal spectrum created by
sampling are shifted to very high frequencies. For example, with fs = 8KHz and an oversampling ratio
3|Page
of 250, the first image occurs at 2MHz, so the anti-aliasing filter need only roll-off at 90% of 1MHz,
which is much easier to implement than a filter for a Nyquist-rate converter which would require a
4KHz roll-off. Only every 250th to 384th sample point is needed to accurately represent the
bandlimited signal, so a decimation filter is used to decrease the word rate to the desired rate of
8KHz. These 16-bit finite-length words are then transmitted to the CPU via serial port 0 on the DSP
chip. The CPU will treat these 16-bit finite length words as 16-bit signed integers (-32768 to +32767).
Reconstruction:
The discrete-time signal is artificially increased in rate by a factor of M (zero-filled up-sampling).
Here M = 250 to 384, just as with the coder (ADC). A high rate discrete-time LPF is used to interpolate
the M −1 newly inserted samples. The up-sampled signal is then converted from a discrete-time
signal to a continuous-time signal by a DAC and finally, a smoothing filter (anti-imaging filter) is used
to create a continuous-time signal. As with the ADC, the higher output rate of the DAC, combined with
the interpolating filter, considerably simplifies the analog LPF on the output of the DAC. The figure
given below shows the generic input/output DSP system:

Codec Connectors:
Four connectors on the board provide input and output capabilities:

• MIC IN for microphone input (J301)


• HEADPHONE for headphone output (multiplexed with line output) (J302)
• LINE IN for line input (J303)
• LINE OUT for line output (J304)

Interrupts:
Interrupts are used to handle asynchronous events on the DSP chip and may be generated either
internally through software or externally by other components on the DSK. Interrupt handling
requires extra hardware that operates autonomously from the CPU. The C6713 chip is equipped with
this hardware (timers, McBSP, etc.) and is the preferred way to time events on the DSP chip. When
interrupts are used to establish the real-time link between the on-board codec and the CPU, the
interrupt registers in SP0 are configured to handle interrupts. When the codec sets the transmit ready
bit in the SPCR, the McBSP will generate an interrupt. When an interrupt occurs, the following events
happen:

4|Page
• The current program execution is halted.
• The current execution state is saved (in a CPU register).
• The program branches to and processes the interrupt.
• Upon completion of the interrupt processing, the execution state is restored, and the program
continues executing.

On the C6713 DSP chip, there are thirty-two possible interrupt sources, but only twelve may be
assigned by the programmer, namely INT4 through INT15. These twelve interrupts are prioritized
by the ‘Interrupt Selector’. Using interrupts requires that each interrupt be mapped to an interrupt
service routine (ISR). This is done by a Vectors file that, in our case, maps INT11 to the C coded ISR
c_int11(). In addition, INT11 must be selected to handle interrupts from XINT0, and the DSP chip
must be set up to accept programmer assigned interrupts. These tasks will be done by the C coded
function comm_intr().
Sine Wave Generation using Interrupt:
The code given below reads real time input signal from the function generator, passes it through ADC
and DAC and then displays the output on oscilloscope.
#include "DSK6713_AIC23.h" //codec support
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
#define DSK6713_AIC23_INPUT_MIC 0x0015
#define DSK6713_AIC23_INPUT_LINE 0x0011
Uint16 inputsource=DSK6713_AIC23_INPUT_LINE; //select input
interrupt void c_int11() //interrupt service routine
{
short sample_data;
sample_data = input_left_sample(); //input data
output_left_sample(sample_data); //output data
return;
}
void main()
{
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
}

In function main() , comm_intr() function is initialized which initializes the DSK, codec, and McBSP,
and sets up interrupts such that the AIC23 codec will sample the analog input signal and interrupt
the C6713 processor, at the sampling frequency defined by the line Uint32
fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate. It also initiates communication with the codec
via the McBSP. For example, when sampling rate is 8 kHz an interrupts will occur every 0.125 ms.
(Sampling rates of 16, 24, 32, 44.1, 48, and 96 kHz are also possible.) Following initialization, function
main() enters an endless while loop, doing nothing but waiting for interrupts. The functions that will
act as interrupt service routines for the various different interrupts are specified in the interrupt
service table contained in file vectors_intr.asm. This assembly language file differs from the file
vectors_poll.asm in that function c_int11() is specified as the interrupt service routine for interrupt
INT11. On interrupt, the interrupt service routine (ISR) c_int11() is called and it is within that routine
that the most important program statements are executed.

5|Page
Other AIC23 configuration settings are determined by the parameters specified in file c6713dskinit.h.
The two settings, sampling rate and input source, are changed sufficiently frequently, from one
program example to another, that their values are initialized as fs and inputsource. In function
dsk6713_init() in file c6713dskinit.c, these values are used by functions DSK6713_AIC23_setFreq()
and DSK6713_AIC23_rset(), respectively. A variable is declared in dsk6713init.h file which may be
handled either as one 32-bit unsigned integer (AIC_data.uint) containing left and right channel
sample values, or as two 16-bit signed integers (AIC_data.channel[0] and AIC_data.channel[1]). Most
of the program examples use only one channel for input and output and for clarity most use the
functions input_left_sample() and output_left_sample(). These functions are defined in the file
c6713dskinit.c, where the unpacking and packing of the signed 16-bit integer left channel sample
values out of and into the 32-bit words received and transmitted to and from the codec are carried
out.
Input and Output Functions Defined in Support File c6713dskinit.c:
The functions input_left_sample() , output_left_sample() , comm_poll(), and comm_intr() are defined
in the support file c6713dskinit.c. This way the C source file loop_intr.c is kept as small as possible
and potentially distracting low level detail is hidden. Further calls are made by input_left_sample()
and output_left_sample() to lower level functions contained in the board support library
DSK6713bsl.lib. Within the function input_sample, support functions from the BSL are included to
read a 32-bit data. The function input_sample captures 32-bit data, 16 bits from the left input channel
and 16 bits from the right input channel. The union statement is used to process each channel
independently. The union of AIC23_data contains these 32-bit input data. The line of code for output
is from the left channel (by default) to output 16-bit data from the left input channel.
Polling:
The polling technique uses a continuous procedure of testing when the data is ready. Although it is
simpler than the interrupt technique, it is less efficient since the input and output data need to be
continuously tested to determine when they are ready to be received or transmitted. Function
comm_poll() initializes the DSK and, in particular, the AIC23 codec such that its sample rate is set
according to the value of the variable fs (assigned in loop_poll.c ), its input source according to the
value of the variable inputsource (assigned in loop_poll.c), and polling mode is selected.
Sine Wave Generation Using Eight Points:

This example generates a sinusoid using a lookup table method. The C source program to implement
the sine generation is given below:
#include "dsk6713_aic23.h"
Uint32 fs = DSK6713_AIC23_FREQ_8KHZ;
#define LOOPLENGTH 8
short loopindex = 0;
short sine_table[LOOPLENGTH] = {0,7022,9930,7022,0,-7022,-9930,-7022};
void main()
{
comm_poll();
while(1)
{
output_left_sample(sine_table[loopindex++]);
if(loopindex >= LOOPLENGTH) loopindex = 0;

6|Page
}
}

As an example, when sampling rate is 8 kHz, an array called sine_table, of eight 16-bit signed integers
is declared and initialized to contain eight samples of exactly one cycle of a sinusoid. The value of
sine_table is equal to 1000 ∗ sin(𝑡), where, t = 0, 45, 90, 135, 180, 225, 270, and 315 degrees. Within
the main function, another function, comm_poll, is called that is located in the communication and
initialization support file c6713dskinit.c. Within c6713dskinit.c, the function DSK6713_init initializes
the BSL file, which must be called before the two subsequent BSL functions, DSK6713_LED_init and
DSK6713_DIP_init, are invoked that initialize the four LEDs and the four dip switches.
The while (1) statement is used to create an infinite loop. The function output_sample, located in the
communication support file C6713dskinit.c, is called to output the first data value in the buffer or
table sine_table[0] = 0. The sample values read from the array sine_table are sent to output, and a
sinusoidal analog output waveform will be generated via the left-hand channel of the AIC23 codec
and the LINE OUT and HEADPHONE sockets. Each time a sample value is read from the array
sine_table, multiplied by the value of the variable gain, and written to the codec, the loopindex is
incremented and when its value exceeds the allowable range for the array (LOOPLENGTH - 1), it is
reset to zero.
Each time the function output_left_sample() , defined in source file C6713dskinit.c , is called to output
a sample value, it waits until the codec, initialized by the function comm_poll() to output samples at
a rate of 8 kHz, is ready for the next sample. The sampling rate at which the codec operates is set by
the program statement Uint32 fs = DSK6713_AIC23_FREQ_8KHZ.
Every sample period T = 1/Fs = 1/8000 = 0.125 ms, a subsequent data value in sine_table is sent for
output. Within one period, eight data values (0.125 ms apart) are output to generate a sinusoidal
signal. The period of the output signal is T = 8(0.125 ms) = 1 ms, corresponding to a frequency of f =
1/T = 1 kHz. Consequently, one cycle of the sinusoidal analog output waveform corresponds to eight
output samples and hence the frequency of the sinusoidal analog output waveform is equal to the
codec sampling rate (8 kHz) divided by eight, that is, 1 kHz.
In polling mode, function input_left_sample() polls, or tests, the receive ready bit ( RRDY ) of the
McBSP serial port control register ( SPCR ) until this indicates that newly converted data is available
to be read using function MCBSP_read(). Function output_left_sample() polls, or tests, the transmit
ready bit ( XRDY ) of the McBSP serial port control register ( SPCR ) until this indicates that the codec
is ready to receive a new output sample. A new output sample is sent to the codec using function
McBSP_write() .
Visualizing Output on Oscilloscope:
Compile and load the program onto the DSK and run it. Connect the signal generator to one end of
the stereo audio cable and plug the other end into the line-in jack on the DSK (J303). Plug the second
cable into the line-out jack on the DSK (J304) and the other end to oscilloscope channel 1. (Make sure
that the oscilloscope is calibrated beforehand). Set the signal generator to a 1KHz sinusoid with
amplitude 1Vpp (peak-to-peak voltage) and observe a 1KHz sinusoid on oscilloscope. Change the
peak-to-peak voltage and the frequency on the signal generator and observe the effects on the
oscilloscope. If the voltage input to the codec exceeds 3.3V, then the codec will be overdriven. When
the codec is overdriven, the output on the codec will reveal either amplitude clipping of the input

7|Page
sine wave. If the voltage input is too small (around 100mV or less), then coupling effects from the
internal hardware will be observed. For frequency, keep in mind that there is a lowpass filter that
cuts off frequencies above 4KHz. Vary the frequency of the sinusoid on the signal generator and
observe that sinusoids above 4KHz are suppressed. (Note that sinusoids around 4KHz are decreased
in amplitude, but not fully suppressed. This is due to the fact that the anti-aliasing filter is not ideal
and therefore has a non-zero roll-off around 4KHz.)

8|Page
Lab Tasks:
1. Write a code in CCS to read analog input from the function generator, converts it to digital
signal and then converts it back to analog signal. Display the results on oscilloscope.
The input signal from function generator should be a 1Vpp sine wave with frequency of 1 kHz.
Note: Use sampling rate = 16 kHz.

Code:
#include "DSK6713_AIC23.h"
Uint32 fs=DSK6713_AIC23_FREQ_16KHZ;
#define DSK6713_AIC23_INPUT_LINE 0x0011
Uint16 inputsource=DSK6713_AIC23_INPUT_LINE;
interrupt void c_int11()
{
short sample_data;
sample_data = input_left_sample();
output_left_sample(sample_data);
return;
}
void main()
{
comm_intr();
while(1);
}
Output:

Fig 1

9|Page
2. Write a code in CCS which generates a 1 kHz sine wave with 1Vpp voltage level using lookup
table method, when switch 3 is pressed. Use sampling rate = 8 kHz.

Code:

#include "DSK6713_AIC23.h"
#include<dsk6713_dip.h>
#include "dsk6713_aic23.h"
Uint32 fs = DSK6713_AIC23_FREQ_8KHZ;
#define LOOPLENGTH 8
short loopindex = 0;
short sine_table[LOOPLENGTH] = {0,7022,9930,7022,0,-7022,-9930,-7022};
void main()
{
comm_poll();
while(1);
if(DSK6713_DIP_get(3) ==0)
{
output_left_sample(sine_table[loopindex++]);
if(loopindex >= LOOPLENGTH) loopindex = 0;

}
}
MATLAB code to calculate sine table values:
Vref = 3.3;
A = 1000;
N = 8;
scale_factor = (2^15 - 1) / Vref;

sine_table = zeros(1, N);

for i = 0:N-1
angle_deg = i * (360 / N);
sine_wave_value = A * sind(angle_deg);
sine_table(i+1) = round(sine_wave_value * scale_factor / 1000);
end
disp('Sine table values:');
disp(sine_table);

10 | P a g e
Output:

Fig 2

Fig 3

11 | P a g e
3. Write a code in CCS which generates a 1 kHz triangular wave with 1Vpp voltage level using
lookup table method.
Note: Use sampling rate = 16 kHz.

Code:
#include "DSK6713_AIC23.h"
#include "dsk6713_aic23.h"

Uint32 fs = DSK6713_AIC23_FREQ_16KHZ;
#define LOOPLENGTH 16

short loopindex = 0;
short tri_table[LOOPLENGTH] = {
-9929, -7447, -4965, -2482, 0, 2482, 4965, 7447,
7447, 4965, 2482, 0, -2482, -4965, -7447, -9929
};

void main() {
comm_poll();

while (1) {
output_left_sample(tri_table[loopindex++]);
if (loopindex >= LOOPLENGTH) loopindex = 0;
}
}
Matlab code for lookup table values:
Vref = 3.3;
Vpp = 1;
Fs = 16000;
f = 1000;
N = Fs / f;
scale_factor = (2^15 - 1) / Vref;

tri_table = zeros(1, N);

for i = 1:N
if i <= N/2
tri_wave_value = (2 * Vpp * (i - 1) / (N/2)) - Vpp;
else
tri_wave_value = (2 * Vpp * (N - i) / (N/2)) - Vpp;
end
tri_table(i) = round(tri_wave_value * scale_factor);

12 | P a g e
end

disp('Triangular wave lookup table values:');


disp(tri_table);

Output:

Fig 4

Conclusion:
In this lab we interfaced the TLV320AIC23 CODEC to read and process analog signals. We
converted a 1 kHz sine wave from analog to digital and back, generated a sine wave using a lookup
table when a switch was pressed, and produced a triangular wave using the same method. We
observed the accurate signal output on the oscilloscope.

…THE END…

13 | P a g e

You might also like