Interrupt-Driven ADC Sampling

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

Analog-to-Digital Converter

12-21

 

Page 157
Image 157
Texas Instruments MSC1210 manual Analog-to-Digital Converter 12-21