K21 temperature sensor transfer function

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

K21 temperature sensor transfer function

Jump to solution
921 Views
kevinledinh
Contributor II

Hi,

I'm working on a K21 target and want to read the internal temperature sensor. I've set up the PE for the ADC and am able to get ADC readings out. However converting from the ADC readings to the actual Temperature reading is proven to be a little bit tricky. I've consulted AN3031 an various threads on here but haven't got a solution yet.

My problem is that the temperature converted from the ADCR is not correct even though it increase and decrease in the right direction, my guess is that my implementation of the transfer function is not correct. Below is my transfer function implementation:

uint32_t GetTemperature(uint32_t ADCR_Temp)

{

  uint32_t Vtemp_mV = ADCR_Temp * 1800 / ( (1 << AdcLdd1_ADC_RESOLUTION) - 1 ) ; //Convert the ADC reading into voltage

  uint32_t Temp1;

  uint32_t Temp2;

  Temp2 = ( Vtemp_mV - 716 ) * 617; // 1 / 0.00162 = 617

  Temp1 = 25000 - Temp2;

  return (uint32_t) (Temp1);

}

}

Here is the printf of the program:

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1711,Temperature: 2.788 ▒C

Vtemp ADCR: 1710,Temperature: 3.405 ▒C

And I'm pretty sure I'm sitting in a room at about 20 degrees C, unless there is something else going on (!?).

And I'm using 1.8V for VREFH and Ground for VREFL. ADC resolution 12 bits

Any help is much appreciated.

Many thanks,

Labels (1)
0 Kudos
1 Solution
641 Views
egoodii
Senior Contributor III

If your Vref (1.8V) is 'tighter' than the internal bandgap (+/-3%), then don't bother with all that from AN3031!  IF you have a 'better absolute voltage' someplace you could use that for a reference point...

Your first equation looks good, assuming Vtemp comes in as a right-justified 'fraction of full scale', where full-scale comes from #of bits=AdcLdd1_ADC_RESOLUTION=12 (so / 0xFFF -- why not just >> AdcLdd1_ADC_RESOLUTION?).

And I assume here that the K21 has the constants of 716mV@25C, and 1.62mV/C, per your math.

But Temp1&2 (and the returned result) will need to be signed integers for all possible calculations to work (above and below 25C[716mV], above and below 0C).

So that said, an AtoD value of 1711, on 12 bits from 1.8V, nets 752mV, or 36mV higher (colder) than 25C.  At 1.62mV/C as indicated, that indeed comes to 22C 'colder' than 25C.

I'm afraid you have to go back to the raw subroutine-input and see that the conversion process is being properly started, from the proper channel.  A 25C 'chip temperature' needs to return 'something close to' the expected 716mV, or 1629 (out of 4096 steps from 1.8V).

OR your 1.8V is running 5% 'low'.  If 1711 counts WERE to truly represent 716mV (+/-10mV chip-tolerance, at 25C, or +/-6C), THEN full-scale represents 1.71V as your Vref.  SO, you might indeed try the concept in AN3031 of calculating 'backwards' to your Vref (but NOT the method!).  If you convert the 1volt bandgap, then ((1 << AdcLdd1_ADC_RESOLUTION) * 1000 /* BandGap mV */ ) / BandGAPresult will return Vref in mV -- inject that into your first equation (instead of a fixed 1800) and see if the temperatures come out better!

View solution in original post

0 Kudos
6 Replies
641 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Phuc,

Before answer your question, I'd like to know the actual value of the VDDA in the board.

I'm looking forward to your reply.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
641 Views
kevinledinh
Contributor II

Hi jeremyzhou,

The actual value of VDDA is 1.8V. And you do mean that I have to re-calculate Vdd as per instructed in the AN3031?

Many thanks,

0 Kudos
641 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Phuc,

I've looked into your equation to calculate the temperature deeper.

Just as the Earl pointed out, I think you'd better to follow this procedure to calculate the temperature.

2015-07-24_9-59-14.jpg


Have a great day,

Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
641 Views
kevinledinh
Contributor II

Hi Jeremy and Earl,

The answer is indeed your first replies.

I've tried both approaches: the AN3031 and the straightforward way of using the transfer function without calculating the bandgap voltage. It turns out that the problem lies in my VDDA. I was so convinced that it was 1.8V so I didn't actually measure it when Jeremy mentioned it first time. When Earl pointed out that the reference voltage might be off by 5%, I suddenly remember that indeed the supply voltage isn't exactly 1.8V. And there it is sitting at 1.71V.

Thanks you two for answering my question.

Have a great weekend.

0 Kudos
641 Views
egoodii
Senior Contributor III

Just to be clear, I don't recommend the particular PROCEDURES of AN3031 -- the equations are unnecessarily complex, and 'millivolt/milliC' are better intermediate units then 'times 10' as in those.  If the internal +/-3% tolerance of the internal bandgap is 'your best source' then by all means just add the additional calculation back to Vref that I added to your existing math (plus, of course, the change to signed results).

0 Kudos
642 Views
egoodii
Senior Contributor III

If your Vref (1.8V) is 'tighter' than the internal bandgap (+/-3%), then don't bother with all that from AN3031!  IF you have a 'better absolute voltage' someplace you could use that for a reference point...

Your first equation looks good, assuming Vtemp comes in as a right-justified 'fraction of full scale', where full-scale comes from #of bits=AdcLdd1_ADC_RESOLUTION=12 (so / 0xFFF -- why not just >> AdcLdd1_ADC_RESOLUTION?).

And I assume here that the K21 has the constants of 716mV@25C, and 1.62mV/C, per your math.

But Temp1&2 (and the returned result) will need to be signed integers for all possible calculations to work (above and below 25C[716mV], above and below 0C).

So that said, an AtoD value of 1711, on 12 bits from 1.8V, nets 752mV, or 36mV higher (colder) than 25C.  At 1.62mV/C as indicated, that indeed comes to 22C 'colder' than 25C.

I'm afraid you have to go back to the raw subroutine-input and see that the conversion process is being properly started, from the proper channel.  A 25C 'chip temperature' needs to return 'something close to' the expected 716mV, or 1629 (out of 4096 steps from 1.8V).

OR your 1.8V is running 5% 'low'.  If 1711 counts WERE to truly represent 716mV (+/-10mV chip-tolerance, at 25C, or +/-6C), THEN full-scale represents 1.71V as your Vref.  SO, you might indeed try the concept in AN3031 of calculating 'backwards' to your Vref (but NOT the method!).  If you convert the 1volt bandgap, then ((1 << AdcLdd1_ADC_RESOLUTION) * 1000 /* BandGap mV */ ) / BandGAPresult will return Vref in mV -- inject that into your first equation (instead of a fixed 1800) and see if the temperatures come out better!

0 Kudos