Lab 6: Analog-to-Digital Converter
6 - 34 TMS320F2837xD Microcontroller Workshop - Analog Subsystem
• Highlight DEBUG_TOGGLE with the mouse, right click and select “Add Watch
Expression…” and then select OK. The global variable DEBUG_TOGGLE should
now be in the Expressions window with a value of “1”.
• Enable the Expressions window for continuous refresh
• Run the code in real-time mode and change the value to “0”. Are the results shown
in the memory and graph window as expected? Change the value back to “1”. As
you can see, we are modifying data memory contents while the processor is running
in real-time (i.e., we are not halting the MCU nor interfering with its operation in any
way)! When done, fully halt the CPU.
Setup DAC to Generate a Sine Waveform
Next, we will configure DACB to generate a fixed frequency sine wave. This signal will
appear on an analog output pin of the device (ADC-A1). Then using the jumper wire we will
connect the DACB output to the ADCA input (ADC-A0) and display the sine wave in a graph
window.
24. Notice the following code lines in the ADCA1 ISR in DefaultIsr_6.c:
//--- Write to DAC-B to create input to ADC-A0
if(SINE_ENABLE == 1)
{
DacOutput = DacOffset + ((QuadratureTable[iQuadratureTable++] ^ 0x8000) >> 5);
}
else
{
DacOutput = DacOffset;
}
if(iQuadratureTable > (SINE_PTS – 1)) // Wrap the index
{
iQuadratureTable = 0;
}
DacbRegs.DACVALS.all = DacOutput;
The variable DacOffset allows the user to adjust the DC output of DACB from the
Expressions window in CCS. The variable Sine_Enable is a switch which adds a fixed
frequency sine wave to the DAC offset. The sine wave is generated using a 25-point
look-up table contained in the SineTable.c file. We will plot the sine wave in a graph
window while manually adjusting the offset.
25. Open and inspect SineTable.c. (If needed, open the Project Explorer window in the
CCS Debug perspective view by clicking View Project Explorer). The file
consists of an array of 25 signed integer points which represent four quadrants of
sinusoidal data. The 25 points are a complete cycle. In the source code we need to
sequentially access each of the 25 points in the array, converting each one from signed
16-bit to un-signed 12-bit format before writing it to the DACVALS register of DACB.
26. Add the following variables to the Expressions window:
• Sine_Enable
• DacOffset
27. Adjust the jumper wire to connect the ADCINA0 (header J3, pin #30) to DACB (header
J7, pin #70) on the LaunchPad. Refer to the following diagram for the pins that need to
be connected.