Reading Temperature values from internal sensor

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading Temperature values from internal sensor

3,199 Views
lpcware
NXP Employee
NXP Employee
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.
Labels (1)
0 Kudos
Reply
5 Replies

2,121 Views
johanntaferl
Contributor I

I think this answers the question.

0 Kudos
Reply

2,121 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos
Reply

2,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by af_bln on Thu Apr 21 04:49:52 MST 2016
>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?
I think you are on a wrong way I think your uC has a 10 bit ADC. There is an example how to convert the value to temperature value based on lpc11axx uC example:

adcVal= ADCRead(7);
voltVal= (adcVal * 3300) / 1024; /* voltage value (in mV)of the ADC is: (ADC/1024)*3.3*1000 mV */
tempVal= (voltVal - 578.34) / (-2.366);/* voltage = -2.366*temperature + 578.34 */
0 Kudos
Reply

2,119 Views
johanntaferl
Contributor I

PS: If he means LPC11E67JBD48, than he has a 12bit ADC as well.

(LPC11E6X.pdf)

0 Kudos
Reply

2,121 Views
johanntaferl
Contributor I

Hello!

I am using an LPC11U68 which has a 12 bit ADC and a temperature range from -40 to 105°C. At least the data sheet says so.

I also do get a value of about 80°C.

My calculation was:

auto temp = 105 - ((int)(rawValue * 145 / rawMax));

How do you get the values "-578,34" and "-2,366"?

Thanks!

0 Kudos
Reply