$29
Objectives
The student should be able to operate an analog to digital converter (ADC) and a digital to analog converter (DAC) on the microcontroller to produce a varying frequency sine wave.
Overview
In this lab we will write a C program that generates a sinusoid using a DAC connected to the microcontroller at a frequency specified by the user—i.e. we'll turn the microcontroller into a sinusoidal waveform generator. The user will be able to select the frequency of the sine wave by varying the level of a voltage source connected to the ADC.
Preparation
Become familiar with the operation of your microcontroller’s onboard ADCs (see the corresponding sections in the TM4C123GH6PM Data Sheet). You will find the ADC corresponding pins in section 13-‐2.
Familiarize yourself with the following:
MCP4725 External DAC data sheet
Analog test board (speaker) schematic
LM386M Amplifier datasheet
Prepare the following parts
Tiva C series development board
Analog test board module
Jumpers and wires
10nF capacitor
MCP4725 12-‐bit DAC
Power Supply
Answer the following questions:
What is the input voltage (Vss) range for the DAC?
What is the function of the A0 pin of the DAC? Select a value for A0. Using your value of A0, what is the I2C address of the DAC? (A2 = 0, A1 = 1).
Draw a wiring diagram connecting your microcontroller to the needed components.
Requirements
Use the external 16 MHz crystal with the PLL to set the system clock (configure the PLL to produce whichever frequency is most convenient). This is necessary to produce consistent output on the DAC.
Connect one of the analog board potentiometers to ADC0. Connect the output of the DAC to the analog test board (AIN or AUDIO_IN), you will be ableto hear as the frequency changes. It is not a pleasant noise.
Use a timer to configure the ADC to automatically sample the input line (i.e. initiate a conversion) every 2 ms.
Make use of an interrupt (no polling) to copy the converted voltage value fromhet ADC's registers.
Produce a sine wave using a look-‐up table with 40 entries.
Configure I2C to communicate with the DAC in fast mode (400 kHz).
Update the DAC as a result of a timer (auto-‐reload) using an interrupt.
Set the DAC output as a result of an interrupt.
Use the capacitor to filter the square edges of the DAC waveform.
You only need to check to see if the user has adjusted the voltage every 500 ms.
Table 1: List of timers and interrupts
Timer / Interrupt needed
Function
Frequency
Timer A
Initiate ADC conversion
2ms
ADC Interrupt
Copy voltage from ADC to appropriate place
n/a
Timer B
Update the Timer C frequency using data from the
500ms
ADC Interrupt
Timer C + Interrupt
Send to I2C to update the output voltage of the DAC
Varies
Figure 1: Conceptual flow chart of program functionality
Verify Requirements
Demonstrate to your TA that you have met the above requirements
Include in your lab report a discussion of how the voltage is used to determine the frequency.
Use the oscilloscope to view the filtered waveform from the DAC and verify the frequency. Include a picture of the waveform from the oscilloscope in your lab report.
Show that the correct frequencies are produced for the following codes: 0, 1023, 2047, 3071, and 4095. Measure the voltages these correspond to. The frequencies must be accurate to within 2 Hz.
Notes and Tips
Since you are sampling the line 250 times as often as you'rechecking to see if the user wants to output a different frequency, you should use the extra samples to mitigate the effects of noise and power supply jitter on the measurements; i.e. you should average the ADC code values for the 250 samples to determine the actual ADC code to use for the frequency calculation.
The DAC has an output buffer that changes the output impedance. This may be something to consider when filtering the rigid edges of the waveform.