Using the CODEC ReadMeFirst Lab Summary This lab covers the use of the CODEC that is necessary in nearly all of the future labs. This lab is divided into three parts. In the first part, you will work with the use of the CODEC on the DE2 board to examine basic signals from the benchtop function generator in both the analog and digital domain. In Part 2, you will use the CODEC to observe an audio signal from an MP3 player or the ipad. In the third part, you will send in an analog signal into the DE2 board and observe the converted digital waveform in Signal Tap II. Please note that much of this lab was developed for the previous version of the DE2 FPGA boards. Please be patient when viewing the video as portions that are describing the creation and configuration of the CODEC no longer apply to your lab. Lab Background Most real world signals are analog. In order for a digital device such as an FPGA to communicate with the outside world, an analog to digital (A/D) conversion using a CODEC is essential. Once the digital circuitry processes the digitized signal, it must be converted back as a modified analog signal using the digital-to-analog convertor (DAC). You can use the CODEC whenever an external signal (such as one from the signal generator) must be processed, or when sending a signal from the DE2 Board to an external device (such as on the oscilloscope or a speaker). Lab Preparation Supplies DE2 Board x 1 USB Blaster Cable x 1 BNC Coaxial Cable x 2 BNC to RCA Adapter x 2 RCA to 3.5 mm Cable x 2 3.5 mm to 3.5 mm Cable x 1
Documents Review the following documents: Sampling.pdf DE2_CODEC_use.pdf Videos Watch the following screencasts prior to performing the lab: 1) Sampling.mp4 2) Using the Codec.mp4
Part 1: The CODEC In this part, you will be learning how to use the CODEC interface. To test the CODEC, you will input a wave from the signal generator and convert it to a digital wave. You will then convert the digital wave back to an analog wave and observe the result on the oscilloscope. Begin by downloading the archived project named CODEC_Proj into your working directory on the Z drive. This can be found in the 2060 Labs website under Lab 04 and Files on the lab computer desktop. Create a folder of the same name. Place the archive in the folder, and double click on the archive ICON. NOTE 1 : Any project requiring a CODEC will be available for you on the website. Do not Create a new project. Open the project provided and continue the lab by adding to it. NOTE 2 : It is not necessary to configure the CODEC as it was on the old Cyclone II boards. Please ignore any reference to Configure CODEC either in the videos or in any of the other support documentation. NOTE 3 : It is not necessary to change the Core Voltage to 1.2V for any of the projects downloaded from the website. This step has already been performed for you when the CODEC project was created. Construct the schematic shown below. NOTE 4 : This is the CODEC that comes with the project. JUST MODIFY it. DO NOT create another CODEC.
Procedure: 1) Connect the AUD_in and AUD_out buses as shown in the schematic. 2) Program the DE2 Board with your circuit. 3) Use the RCA to BNC adapters and the RCA phono jack splitter cables to connect a BNC coaxial cable between CH1 of the signal generator and either the red or white connectors on the splitter cable that is plugged in to the Line In on the DE2 board (BLUE). 4) Use a second set of cables and adapters to connect the DE2 board Line Out (GREEN) to CH1 of the oscilloscope. 5) Set the signal generator to produce a 1 khz, 1 Volt peak-to-peak Sine wave. 6) Observe this wave on the oscilloscope. NOTE 5 : Remember to ENABLE the Output on CH1 of the Signal Generator. NOTE 6 : Check both the red & white connectors on both of splitter cables (4 combinations) in order to patch your signals through to the correct places in the set-up wave. The left and right color coding varies with brand of RCA/35mm adapter. NOTE 7 : You may also find the Autoscale button (white) on the oscilloscope very helpful when look for the waveform. Result 1: Take a screenshot of the sine wave on the oscilloscope and include this in your lab report. Result 2: Export the oscilloscope data and plot the data in MATLAB. Include this in your lab report. 6) Using the signal generator, produce a Square Wave with the same frequency and peakto-peak voltage as the above sine wave. Observe this wave on the oscilloscope and save the waveform. Result 3: Take a screenshot of the wave on the oscilloscope and include this in your lab report. Result 4: Export the oscilloscope data and plot the wave in MATLAB. Include this in your lab report. Checkpoint 1: Show the lab monitor both of your MATLAB plots.
Part 2: Codec Application In this part, we will observe the signal from an MP3 player on the oscilloscope, using the circuit from the last project. Procedure 1. Connect the Line in of the DE2 board to a MP3 player (or the ipad, computer, etc.) using the 3.5 mm to 3.5 mm cable. 2. Play any sort of file that contains audio. (Your favorite song?) 3. Change the time base on the oscilloscope to a low setting, 50 milliseconds/divisions, 4. Change the vertical scale on the oscilloscope to 1.00 Volts/division to begin with. You may adjust it later to be able to better see your music signal. 5. Observe the signal on the oscilloscope. 6. Now try changing the volume of the device. What happens to the amplitude on the oscilloscope? Result 5: Take a screenshot of the music signal on the oscilloscope and include it with your lab report.
Part 3: The A/D Converter In this part, you will use Signal Tap II to plot the digitalized waveform. ***************************************************************************** NOTE: You will need to use this part of the lab to answer Topic 4 in the discussion questions ***************************************************************************** Procedure 1) Create two output (bus) pins for both AUD_inL[15..0] and AUD_inR[15..0] separately. 2) Run Analysis & Synthesis (the 1 st stage of compilation) and set up Signal Tap. The Analysis & Synthesis button is as shown in the figure below. Select the clock in Signal Tap to be AUD_ADCLRCK and add AUD_inL[15..0] and AUD_inR[15..0] to node list. If you have trouble, review the Signal Tap II Logic Analyzer Screencast from the previous lab. 3) Connect the Signal Generator to the Line In of the DE2 board (BLUE). Use 2 cable sets and connect the signal to both the red and white RCA input channels. Set the signal generator to generate a sine wave with 2 Vpp and 1 khz frequency. 4) Recompile and Reprogram. Observe the results from the two AUD_in pins in Signal Tap II. Verify that you are getting a sine wave. 5) Set the signal generator to generate a sine wave with a frequency such that the normalized frequency is 1/10. Recall that the sampling rate (Fs) of the CODEC is 48000 Hz and the normalized frequency is related to the frequency by the equation f = F/Fs. (i.e. f = 1/10, set the signal generator to F = 48000 Hz/10).
6) Rerun the Signal Tap II Program and observe the results as a Signed Bar Chart. Select the signal name -> right clock -> Scroll down to Bus Display Format -> Second setting from the bottom is Signed Bar Chart. Results 6: Take a screenshot of the Signal Tap results and include it in your lab report. Checkpoint 2: Show your results to the lab monitor. Checkpoint 3: Clean up and show your workbench to the lab monitor. Discussion Questions Topic 1: What is the sampling frequency of the CODEC? Topic 2: What frequency should the signal generator be set at to achieve a normalized frequency f = 0.5? Topic 3: Explain why the units of the normalized frequency are in cycles/sample. In other words, what does it mean to have a signal that oscillates at 1/3 cycles/sample? What is the relationship between actual frequency, normalized frequency and cycles per sample. Topic 4: Use the circuit you developed in part 3 of the lab to find at what normalized frequency do you begin to stop seeing a signal? Set your function generator to 2 V peak-peak. Figure out the frequency in Hertz at which Signal Tap stops reproducing a signal. Then divide by the sampling frequency to calculate the normalized frequency. Remember that F = f*fs (Assume Fs = 48,000 Hz). What you are examining is referred to as aliasing and the Nyquist criteria for sampling. Hint: Use Autorun Analysis to change the frequency and observe the signal in real time. Topic 5: CODEC stands for Encoding and Decoding. How are each of these functions accomplished at the hardware level?