Useful C Language Statement Examples
315
SNIU028A – February 2016 – Revised April 2016
Copyright © 2016, Texas Instruments Incorporated
ADC12 Overview
Figure 8-18.
8.17 Useful C Language Statement Examples
#define ADCCTRL_SINGLE_SWEEP
8
#define ADCCTRL_MAXCONV_SHIFT
4
#define ADCCTRL_ADC_ENA
1
#define ADCCOMPEN_COMP0_EN
1
#define ADCCOMPEN_COMP3_EN
8
#define ADCCOMPEN_COMP5_EN
0x20
int Temporary;
AdcRegs.ADCCTRL.all = ADCCTRL_SINGLE (7 << ADCCTRL_MAXCONV_SHIFT) + ADCCTRL_ADC_ENA;
AdcRegs.ADCAVGCTRL.bit.AVG2_EN = 1;
// Means: Averaging on the result of the third measurement in the sequence is enabled
AdcRegs.ADCAVGCTRL.bit.AVG2_CONFIG = 2;
// Means: The third sequence result will undergo moving average of 16 samples
AdcRegs.ADCSEQSEL0.bit.SEQ0 = 15;
//Means that channel 15 (the very last input channel) is selected as the very first measurement
in the measurement sequence.
AdcRegs.ADCSEQSEL1.all = 5 + (6 << 5) + (7 << 10)
//Means, the channels 5, 6 and 7 are set to be the fifth, sixth and the seventh (SEQ4 to SEQ6)
respectively in the measurement sequence.
AdcRegs.ADCCTRL.bit.SW_START = 1;
//Means; the ADC is instructed to start a new conversion sequence
AdcRegs.ADCCTRL.bit.ADC_INT_EN = 1;
// Means: enable interrupt at local ADC level
CimRegs.REQMASK.bit.REQMASK_ADC_CONV =1; // Means: Enable ADC interrupt at CPU level.
if (AdcRegs.ADCSTAT.bit.ADC_INT == 1)
// Means; if ADC measurement completed.
Temporary = AdcRegs.ADCCTRL.all;
// Means :read and clear completion flags
Temporary = AdcRegs.ADCRESULT[3].all;
// Read the fourth raw ( non averaged) result register
Temporary = AdcRegs.ADCAVGRESULT[0].all; // Read the first averaged result register
if (AdcRegs.ADCCOMPRESULT.bit.DCOMP0_LO_RAW == 1)
//Means: if the lower limit is exceeded on the first comparator
AdcRegs.ADCCOMPEN.all = ADCCOMPEN_CO ADCCOMPEN_CO ADCCOMPEN_COMP5_EN;
//Means : Enable the first, the fourth and the sixth digital comparators.
AdcRegs.ADCCOMPEN.bit.COMP5_EN = 1;
// Enable the sixth digital comparison mechanism
AdcRegs.ADCCOMPEN.bit.COMP4_DATA_SEL = 1;
//Means: The fifth comparator is configured to compare the average data from ADC12 and not the
raw data
AdcRegs.ADCCOMPEN.bit.COMP3_UP_INT_EN = 1;