AnsweredAssumed Answered

Reading Temperature values from internal sensor

Question asked by lpcware Employee on Jun 15, 2016
Latest reply on Feb 27, 2017 by johanntaferl
Content originally posted in LPCWare by otavioborges on Thu Apr 07 08:04:20 MST 2016
Hello all,

I've trying to get a read from the internal temperature sensor from LPC11eE67JBD48. I've followed the example from LPCOpen "periph_temp". Although, ADC reading seems to be working fine the temperature read is a bit off.

As far as I understand the ADC reading, that varies form 0x0 to 0xFFF, changes inverted with the temperature over the full range of the uC. Therefore 0x0 would be 105ºC and 0xFFF -40ºC, according to the manual. Is that assumption correct?

By using this approach I've been getting temperatures close to 80ºC, the IC is not hot to touch, seems close to environment temperature. That's why I've been finding it weird.
static uint32_t temp[10];
The snappet of the code I've been using follows:


static volatile int tempSample = 0;
static volatile bool tempSeqComplete = false;
static volatile int tempTimer = 1;

static uint32_t temp[10];

uint32_t temp_result;
float temperature;

void ADCA_IRQHandler(void)
{
uint32_t pending;

/* Get pending interrupts */
pending = Chip_ADC_GetFlags(LPC_ADC);

/* Sequence A completion interrupt */
if (pending & ADC_FLAGS_SEQA_INT_MASK) {
if (tempSample < 10) {
/* Save sample */
temp[tempSample] = Chip_ADC_GetDataReg(LPC_ADC, 0);
tempSample++;

if (tempSample >= 10) {
Chip_ADC_StopBurstSequencer(LPC_ADC, ADC_SEQA_IDX);
tempSeqComplete = true;
}
}
}

/* Clear any pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC, pending);
}

...

// Runs every ~10ms
void TIMER32_0_IRQHandler(void){
// Temperature Sequencer
if(tempTimer == 20){
Chip_ADC_StartBurstSequencer(LPC_ADC, ADC_SEQA_IDX);
tempSeqComplete = false;
tempSample = 0;

tempTimer = 0;
}else{
tempTimer++;
}
}

...

// Inside main function

// ADC channel 0 - Temperature sensor
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 9, (IOCON_FUNC3 | IOCON_MODE_INACT | IOCON_ADMODE_EN ));

//*****************************************************************************
// Init and Config ADC
//*****************************************************************************
Chip_ADC_Init(LPC_ADC,0);
Chip_ADC_StartCalibration(LPC_ADC);
while(!Chip_ADC_IsCalibrationDone(LPC_ADC)); // Wait until calibration is done
Chip_ADC_SetClockRate(LPC_ADC,ADC_MAX_SAMPLE_RATE);

Chip_ADC_SetupSequencer(LPC_ADC,ADC_SEQA_IDX,(ADC_SEQ_CTRL_CHANSEL(0) | ADC_SEQ_CTRL_MODE_EOS));

// Enable temperature sensor on ADC channel 0
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_TS_PD); // Clear TEMPSENSE_PD
Chip_ADC_SetTrim(LPC_ADC,ADC_TRIM_VRANGE_HIGHV);

Chip_ADC_SetThrLowValue(LPC_ADC, 0, ((1 * 0xFFF) / 4));
Chip_ADC_SetThrHighValue(LPC_ADC, 0, ((3 * 0xFFF) / 4));

/* Clear all pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC));

Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC));

/* Enable ADC sequence A completion interrupt */
Chip_ADC_EnableInt(LPC_ADC, ADC_INTEN_SEQA_ENABLE);

/* Enable ADC NVIC interrupt */
NVIC_EnableIRQ(ADC_A_IRQn);

while(1){
if(tempSeqComplete){
temp_result = ADC_DR_RESULT(temp[9]);
temp_result = 0xFFF - temp_result;
temperature = ((temp_result/4095.0)*145.0)-40.0;
}
}


Thanks.

Outcomes