Hi,
I can't figure out why the temperature reading is about 10 degC lower than expected. (I know the data sheet says accuracy +/-5degC).
My room ambient is about 22degC. My processor is on a board that consumes very little power and is not even warm to the touch. I am expecting to find the internal temp sensor reading at least 25 degC but it consitently gives me around 15 degC. It is the same on several different boards. I have checked the package temperature with an infra-red thermometer which is reading around 24 degC.
Below is my code for initialising the ADC and then the code for reading the temperature which is run once a second in my application.
Can anyone spot an error or come up with an explanation please?
Thank you.
Richard
void initTemperature(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
while(!(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_ADC1))); //wait for peripheral ready
//ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
ROM_ADCReferenceSet(ADC1_BASE, ADC_REF_INT);
//need to discard first 3 samples of temp sensor - errata
ROM_ADCSequenceDisable(ADC1_BASE, 2); //disable sequence before we change it
ROM_ADCSequenceConfigure(ADC1_BASE, 2, ADC_TRIGGER_PROCESSOR, 1); //select processor (software) trigger
ROM_ADCSequenceStepConfigure(ADC1_BASE, 2, 0, ADC_CTL_TS); //
ROM_ADCSequenceStepConfigure(ADC1_BASE, 2, 1, ADC_CTL_TS); //
ROM_ADCSequenceStepConfigure(ADC1_BASE, 2, 2, ADC_CTL_TS); //
ROM_ADCSequenceStepConfigure(ADC1_BASE, 2, 3, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); //
ROM_ADCIntClear(ADC1_BASE, 2); //clear the interrupt status flag
ROM_ADCSequenceEnable(ADC1_BASE, 2); //enable sequence
}
#define OFFSET 147 //from data sheet
#define MULTIPLIER 247 //75*3.3 3.3V ref
uint32_t ADC1_value[8];
uint32_t raw_temp;
uint8_t temperature, last_temperature;
uint8_t getTemperature(void)
{
uint8_t chng;
ADCProcessorTrigger(ADC1_BASE, 2); //trigger
while(!ADCIntStatus(ADC1_BASE, 2, false)) //wait complete
{
}
ADCIntClear(ADC1_BASE, 2); //clear the ADC interrupt flag
ADCSequenceDataGet(ADC1_BASE, 2, ADC1_value); //read ADC values
raw_temp = ADC1_value[3];
temperature = (uint8_t)(OFFSET - ((MULTIPLIER * raw_temp) >> 12)); //temperature in degC
chng = 0;
if(temperature != last_temperature) {
last_temperature = temperature;
chng = 1;
}
return chng;
}