beautypg.com

Texas Instruments MSC1210 User Manual

Page 157

background image

Interrupt-Driven ADC Sampling

12-21

Analog-to-Digital Converter

ADCON2 = decimation & 0xFF; // LSB of decimation

ADCON3 =(decimation>>8) & 0x07; // MSB of decimation

ADCON1 = 0x01; // bipolar, auto, self calibration, offset, gain

printf (”Calibrating. . .\n”);

for (k=0; k<4; k++)

{

// Wait for Four conversions for filter to settle

// after calibration. We go to sleep. When we wake

// up, the interrupt will have read the sample.

PCON |= 0x02; // Go to power−down until sample ready

}

samples = 10; // The number of voltage samples we will average

while(1)

{

ave = 0;

for (i = 0; i < samples; i++)

{

PCON |= 0x02; // Go to power−down until sample ready

ave += bipolar() * LSB; // This read clears ADCIRQ

}

printf(“Average sample=%f\n”, ave / samples);

}// while

} //main