Temperature Sensor

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

while(!(AIE & 0x20)); // Wait for data ready lr = bipolar(); // Dummy read to clear ADCIRQ

}

samples = 10; // The number of voltage samples we will average while(1)

{

ave = 0;

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

{

while (!(AIE & 0x20)); // Wait for new next result ave += bipolar() * LSB; // This read clears ADCIRQ

}

volts = ave/samples;

temp = ALPHA * volts − 282.14;

printf (”V=%f, resistance=%f, Temp=%f degrees C\n”, volts, resistance, temp);

}// while } //main

This program first configures the ADC, allows the ADC to self-calibrate, and then enters a loop where the temperature is sampled and reported to the user via the serial interface.

12-6

Page 142
Image 142
Texas Instruments MSC1210 manual 12-6