LC60: Again On-Chip Temperature Calibration

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

LC60: Again On-Chip Temperature Calibration

3,925 Views
BasePointer
Contributor II
Hi,
 
I want to calibrate internal temperature sensor at single point by using floating-point math.
 
Temperature(in C) = 25.0 - ((Vtemp - Vtemp_offset) / m);
 
According to the formula above, I'm recalculating Vtemp_offset value at a known temperature(not always 25C) by using default hot or cold slope values. To do this, I'm calling CalcTempOffset function below with a accurately measured ambient temperature value. After calculating Vtemp_offset value at calibration state, I'm always using this calculated value and default slope values to measure actual temperature with ReadInternalTemperature function bottom.
 
 
Code:
unsigned char CalcTempOffset(signed char temperature){  unsigned int adc_temp, adc_ref;  signed int off;  double Vtemp, m;   DisableInterrupts;    SPMSC1_BGBE = 1; // Bandgap buffer enable.    adc_temp = ReadADCChannel12(26); // Vtemperature     adc_ref = ReadADCChannel12(27);  // Vref = 1.2V      SPMSC1_BGBE = 0; // Bandgap buffer disabled.  EnableInterrupts;    Vtemp = (double)adc_temp*12000/adc_ref; //read temperature sensor voltage    m = 17.075;  if(temperature > 25) m = 17.69;        // hot slope   else if(temperature < 25) m = 16.46;  // cold slope      Vtemp_offset = (Vtemp + (m*(temperature-25)) + 0.5);}

 
Code:
void ReadInternalTemperature(signed char* temperature){  unsigned int adc_temp, adc_ref;  double Vtemp, m;    *temperature = 25; // default value  if(!CheckTempOffsetValid()) return;   DisableInterrupts;    SPMSC1_BGBE = 1; // Bandgap buffer enable.      adc_temp = ReadADCChannel12(26); // Vtemperature     adc_ref = ReadADCChannel12(27);  // Vref = 1.2V      SPMSC1_BGBE = 0; // Bandgap buffer disabled.  EnableInterrupts;    Vtemp = (double)adc_temp*12000/adc_ref;    m = 17.075;  if(Vtemp > Vtemp_offset) m = 16.46;  // cold slope   else if(Vtemp < Vtemp_offset) m = 17.69; // hot slope *temperature = (double)25.0 - ((Vtemp - Vtemp_offset)/m) + 0.5; }

 
The MCU is powered via battery, so the Vdd can vary (1.8V-3.5V) after my calibration.
For example, when ambient temperature is 19 C degree, Vdd is 3.2V, I'm calibrating the MCU by calling CalcTempOffset(19) to determine Vtemp_offset value. After determining this value once, I'm always using ReadInternalTemperature function to measure actual temperature at different Vdd.
I just expect 5 C degree accuracy over VDD and -40 / +85C. But the functions above can't qualify for this.
Do you have a better solution for single point calibration?
Do you think my implementation is applicable?
The datasheet says that 4.5Cdegree error is possible with single point calibration, but I couldn't realize it.
 
10x,
BP.


Message Edited by BasePointer on 2008-03-27 03:33 PM
Labels (1)
0 Kudos
24 Replies

986 Views
BasePointer
Contributor II
Hi,
 
The equation indicated in LC60 datasheet was misprinted.
It should be:
 
TempC = 25 - [(VtempVtemp25) ÷ M]
 
Vtemp: Measured Internal Temperature Sensor Voltage
Vtemp25: Internal Temperature Sensor Voltage at 25ºC
M: Slope values
 
TempC: Calculated temperature in ºC
------------------------------------------------------------
The device datasheet also contains typical values for Vtemp25 and M.
 
Vtemp25: 701.2mV
Mcold: 1.646 mV/°C (used if Vtemp > Vtemp25)
Mhot: 1.769 mV/°C (used if Vtemp < Vtemp25)
------------------------------------------------------------
 
For the calibration, I'm calculating Vtemp25 value by using typical slope values. For example, when ambient temperature is 19 ºC and the supply voltage is 3.3V, I calculate Vtemp25 with:
19 = 25 - [(VtempVtemp25) ÷ Mcold]
 
After that calibration, I'm always using calculated Vtemp25 value for my measurements.
 
Vtemp25 value is my Vtemp_offset value in my code at the top of the post.
I'm not calculating an Offset like you mentioned. Just calculating Vtemp25.
"+0.5" is for rounding up a double value to the integer value.
 
To Mac:
You suggested to calculate Tcal value instead of Vtemp25 value at calibration. Am I right?
TempC = 25 - [(VtempVtemp25) ÷ M] + Tcal
When I'm doing this, should I use typical Vtemp25 value?
The related application notes (AN3031 and AN3570) say Vtemp25 to recalculate for calibration at single point.

Using Tcal instead of Vtemp25 is more suitable?
 
Thank you,
BP.
0 Kudos

986 Views
bigmac
Specialist III
Hello,
 
My understanding is that the formula given in the datasheet uses a reference temperature of 0C (and not 25C).  Using the single point calibration method, it should be possible to calibrate for any known temperature, and this is what my post on the earlier thread attempted to do.
 
i.e. Temp - Tcal = (Vtemp - Vcal) / m
 
where Vcal is the measured voltage at a known temperature Tcal, and m is the nominal slope in volts per degree C.  However, I do suggest that you multiply by the reciprocal slope (degrees C per volt), to give more manageable values, and permit use of integer arithmetic.
 
Errors above and below Tcal will depend on variation of the actual slope from its nominal value.  The error at Tcal will be a minimum, but will still be significant because of the uncertainty associated with the limited ADC resolution.
 
For an unregulated supply, you will definitely need to make allowance for supply voltage variation, using a measurement of the internal reference.  This was covered in the earlier post.
 
Regards,
Mac
 
0 Kudos

986 Views
BasePointer
Contributor II
Hi Mac,
 
When temperature is rising, measured Vtemp voltage is decreasing (typical diode characteristic).
So the measured temperature should be proportional to "-Vtemp".
So the correct formule in datasheet should be 
 
TempC = 25.0 - [(Vtemp – 0.7013) ÷ 0.0017]
 
If we calibrate it by adding an offset to it Tcal:
TempC = 25.0 - [(Vtemp – 0.7013) ÷ 0.0017] + Tcal
I can write it as
TempC = 25.0 - [(Vtemp – 0.7013+ (Tcal*0.0017)) ÷ 0.0017]

If I call "0.7013 - Tcal*0.0017" as Vtemp25 and 0.0017 as M

The formula becomes:

TempC = 25.0 - [(Vtemp – Vtemp25) ÷ M]
The difference between your solution and mine are non-constant slope values.
Your Vtemp25 value contains constant slope value "0.7013 - Tcal*0.0017".
 
I mean with your way, I need to calculate two Tcal value, for cold and hot such as M.
 
BP.
0 Kudos

986 Views
bigmac
Specialist III
Hello BP,
 
I take your point.  I re-checked the datasheet, and the formula given there seems to be incorrect on two counts (assuming AN3031 is correct) -
  1. The data sheet formula uses a positive slope (this is not an obvious error as some temperature sensors do provide a positive slope).
  2. The data sheet implies a reference temperature of 0C, but then states that the 0.7013 volt is applicable to a termperature of 25C.

Slightly re-arranging formula 1 of AN3031 -

Temp - 25 = -(Vtemp - Vtemp25)/m

 

My previous point was that, if you use a single point calibration at a known temperature, the nominal value of Vtemp25 given in data sheet becomes irrelevant, and the formula would then become -

Temp - Tcal = -(Vtemp - Vcal)/m

 

Since the value of m is a very small, I would choose to make the substitution k = 1/m, to give the possibility of using integer arithmetic, rather than floating point -

Temp - Tcal = -(Vtemp - Vcal)*k

 

Based on the values of m given in the application note, the following values of k would apply -

k(cold) = 600  degree C per volt

k(nom) = 588

k(hot) = 569

 

You would apply the slope required, based on the value of Vtemp.

 

Regards,

Mac

 



Message Edited by bigmac on 2008-03-29 01:44 PM
0 Kudos

986 Views
bigmac
Specialist III
To continue the my previous post ...
 
Since Vtemp and Vcal will be measured using the ADC, this will give ADC results of Ntemp and Ncal, where -
Vtemp = Ntemp*Vdd/Nmax
Vcal  = Ncal*Vdd/Nmax
 
Nmax = 1024 for 10-bit resolution, or Nmax = 4096 for 12-bit resolution.  However, if a further reading of the bandgap reference is taken, the expression Vdd/Nmax may be substituted with Vref/Nref.  The temperature calculation would then become as follows -
Temp = Tcal - (Ntemp - Ncal)*(k*Vref)/Nref
 
This means that the calculation becomes independent of Vdd, and will work for any ADC resolution (provided the same resolution is used for all three measurement values).
 
The expression (k*Vref) will be a constant, with one of the following values ...
 
Cold value    720
Nominal value 706
Hot value     683 
 
Regards,
Mac
0 Kudos

986 Views
bigmac
Specialist III
Further to my previous post ...
 
If the Vdd supply is from an unregulated (battery) source, it is probable that the calibration process would have occurred at a different Vdd than the current reading.  This is easily compensated by simply measuring Vref at the time of calibration.  Therefore, the following calibration parameters would need to be stored:
Calibration temperature Tcal
ADC reading for the calibration Ncal
ADC reading for Vref measurement Nref(cal)
 
Using these parameters, the following can be calculated once, prior to commencement of temperature readings:
Kcal = Ncal*(k*Vref)/Nref(cal) + Tcal
 
Then for each new temperature reading, the two ADC readings of Ntemp and Nref would be made.  The following calculation would then be used to derive the temperature value:
Temp = Kcal - Ntemp*(k*Vref)/Nref
 
These formulae will easily accommodate fixed point, integer calculations.  To improve the calculation precision (but not necessarily the accuracy of the reading), it would be desireable for the temperature value integers to be expressed in tenths of a degree, i.e 20.0 degree C = 200.  This can be achieved by using the multiplier value (10*k*Vref).  In all cases, the multiplication must occur prior to the division.  The intermediate calculation, after the multiplication, will need storage as a long (32-bit) value.
 
Regards,
Mac
 
0 Kudos

986 Views
BasePointer
Contributor II

Hi Mac,

 

Since we are using single point Vtemp25 calibration, but due to error of measurement can occurs at +-15 °C, I have to check my calibration process.

 

My calibration process is based on measuring enviorement temperature. We are holding assembled PCB at same place for an hour. I'm measuring enviorement temperature with a reference thermometer. And assume the MCU has same temperature with the enviorement's after this process. Then immediately start calibration operation to calculate Vtemp25 by using enviorement temperature measured.

 

Do you know, effective, faster, more accurate way to make this calibration?

 

Thank you so much for your patient.

Regards,

BP.



Message Edited by BasePointer on 2008-04-01 11:06 AM
0 Kudos

986 Views
bigmac
Specialist III
Hello BP,
 
I don't know whether you are implying +/-15C variation from unit-to-unit, or when you calibrate a single unit at different times.
 
For calibration accuracy, all equipment would need to be in an air-conditioned room with closely regulated temperature, perhaps to a "laboratory" standard, rather than a "factory" standard.  The units to be calibrated would need to "soak" for a number of hours prior to calibration.  The equipment should be shielded from any drafts, and the measurement of "environment" temperature should utilize a thermometer situated in close proximity to the boards being calibrated.  It would be a good idea to initially log the ambient temperature over a period of a day or so, to check for any unexpected variation.
 
Self-heating of the MCU may possibly be an issue.  The device should operate in stop mode for a period prior to calibration, and the calibration should be done very soon after wake-up.  Keep in mind that the thermal time constant of the die itself will be much shorter than that for the package or the board.
 
If some self-heating is likely to occur during normal operation, it is still probably better to do the calibration with minimal self-heating, for consistency of measurement.  You might then apply a self-heating correction during normal operation, by estimating the number of degrees of self-heating under different operational circumstances.  You could initially conduct experiments to determine variation of the temperature measured by the MCU over a relatively short time interval, starting from wake-up.
 
Regards,
Mac
 
0 Kudos

986 Views
JimDon
Senior Contributor III
And, when the chip is running, there will be internal self heating.

The purpose of the sensor is to measure the internal temperature of the chip, not room temperature.
If you want to user to know room temperature, you will need an external sensor, which can be had for as little as little 0.35.

0 Kudos

986 Views
Styra
Contributor I

 Hello,

   I made some experiments using internal MS9S08SG16 in ragge from minus40C to +100Cand it works fine without any calibration.  I use 5V voltage stabilizator in my hardware and very simple calculation with single slope coefficient: Temp [deg C] = 25-(ADC26-286)*11/8 .

    Instead of slope coefficient m I recomend to use n=1/m, in my case n = 11/8 = 1.375

   In my case single point calibration at 25C has no effect or effect is neglectible - results are almos the same like without callibratyion.  Using dual slope coefficienta and single point calibration - has no effect also.  Only 3 point calibration has small positive effect...  

  

0 Kudos

986 Views
Denn
Contributor I
Hello BP,
Is the error of +/- 15 C or error occuring at +/- 15C ?
 
If its the error of +/- 15 C, I would suggest you to have a relook into the code and run without the calibration and see the error margin.I feel the margin shouldn't be more than 5C because my system gets around 29- 30 C when temp is 24 C. (Also note this temperature is also influenced by chip heating/IO pins temperature)
 
 
If you don't mind can I look into the code just in case its different from previously posted code.
 
Regards,
Denn. 


Message Edited by Denn*** on 2008-04-01 12:37 PM
0 Kudos

986 Views
Denn
Contributor I
Hello BP,
 
"If I call "0.7013 - Tcal*0.0017" as Vtemp25 "
 
I think Vtemp25 = 0.7013 ==> 701.2mV .see LC60 datasheet Page 336.
 
And moreover the reference voltage is for 25 C not 0 C.
 
 
Regards,
Denny
 
0 Kudos

985 Views
Denn
Contributor I
Hi BP,
 
By how much is your calibrated Vtemp25 different from datasheet value of Vtemp25 (i.e. 701.2mV).
 
And one more thing, Vtemp25 decided by FSL is done at 3.0 V and 25C. and you are doing is at 3.3V  and 19C right?
 
I'm not sure whether this deviation of 0.3 V will impact the calibration process to that level it will bring temperature calculated by +/-15 %.
 
Can you calculate the temperature without this calibration process and see by what margin is temperature deviating?
 
Regards,
Denn.
0 Kudos

986 Views
BasePointer
Contributor II
Hi Denn,
 

By how much is your calibrated Vtemp25 different from datasheet value of Vtemp25 (i.e. 701.2mV).

 
As I see, Vtemp25 (Vtemp_offset in the code) value varies between 7000 and 7500 that means 700.0mV and 750.0mV.
 

And one more thing, Vtemp25 decided by FSL is done at 3.0 V and 25C. and you are doing is at 3.3V  and 19C right?

Yes, you are right, I also make calibration at so different supply voltage other than 3.3V. It depends on the batery voltage 2.8V-3.6V and ambient temperature may change between 15ºC-35ºC. It is not always 19ºC.
 

Can you calculate the temperature without this calibration process and see by what margin is temperature deviating?

For example
Now the environment is 28 ºC for 5-6 hours.
And the calibrated product measures 28 ºC exactly at VDD=3.6V and 27 ºC at VDD=2.2V.
It uses 734.2mV precalculated value as Vtemp25.
 
 
 
If I used typical value for Vtemp25:
Measured internal temperature voltage(Vtemp) for 28ºC is 729mV.
TempC = 25 - [729mV - 701.2mV] / 1.646 // cold slope because of Vtemp > Vtemp25 typical
TempC = 8ºC
 
Regards,
BP.
 
 


Message Edited by BasePointer on 2008-03-28 12:47 PM
0 Kudos

986 Views
Denn
Contributor I
Hi BP,
 


BasePointer wrote:

 
If I used typical value for Vtemp25:
Measured internal temperature voltage(Vtemp) for 28ºC is 729mV.
TempC = 25 - [729mV - 701.2mV] / 1.646 // cold slope because of Vtemp > Vtemp25 typical
TempC = 8ºC
 


But if you manually calculate  temp comes around 24.9831 C not 8C.
 (for TempC = 25 - [729mV - 701.2mV] / 1.646)
 
 
(28C - 24.9831)/28 = 10.77% deviation from actual reading !!!
 
I suspect some sort of programming error as a reason for 8 C value in "C code " maybe in typecasting or maybe ....
 
Regards,
Denn
 
0 Kudos

986 Views
BasePointer
Contributor II
Hi,
 
[729mV - 701.2mV] = 27.8mV
 
27.8mV ÷ 1.646 mV/°C = 16.889
 
25 - 16.889 = 8.11 °C ? Am I wrong?
 
BP.
0 Kudos

986 Views
Denn
Contributor I
Hi BP,
 
Yes ..You are right .I calculated the slope as 1.646  and not 1.646 mV/C and hence wrong in my calculations.Sorry for confusing atleast for few seconds.
 
Regards,
Denn.


Message Edited by Denn*** on 2008-03-28 11:25 AM
0 Kudos

986 Views
Denn
Contributor I
Hello BP,
 
Equation from AN 3031 "Temperature Sensor for the HCS08 Microcontroller Family, Rev. 0"
 
Temperature(in C) = 25.0 - ((Vtemp - Vtemp25) / m));
where Vtemp25 is the ADC value of temp sensor at 25 deg C, normally a constant given in datasheet,but varies from part to part by a small margin.
 
And my guess is that for calibrating you ned to give a "known temperature" of 25 C rather than 19 C.
 
 
But from your MC9S08LC60 datasheet the equation is different.Page 268
 
TempC = (Vtemp – 0.7013) ÷ (0.0017)
 
Comparing this equation with the above eqn with generic eqn I can see
Vtemp25 =  0.7013
m             = 0.0017 (0.001769-Hot slope, 0.001646- Cold Slope)  from Page 336,LC datasheet
 
 
 
In short " 25 - " is missing in LC controller datasheet.Let me hope this is not print mistake from FSL. In that case I feel we should also try with the "new" equation.
 
 
 
Regards,
Denn.
0 Kudos

986 Views
allawtterb
Contributor IV
The Vtemp_offset calculation seems wrong.  When you calibrate you have a measured temperature and a known good tempature.  You want to take the difference between these 2, not add them together.  I would subtract the measured temperature from the good temperature to calculate the Offset.  Then when calculating temperatures add the offset to the measured temperature. 
 
Offset = Known_Temp - Measured_Temp
 
Temp_With_Offset = Measured_Temp + Offset 
 
Also, you added a + 0.5 to your conversion between Vtemp units and ºC but you don't mention it in the formula you want to use to calculate ºC at the top of the post.  Can you clarify?
0 Kudos

986 Views
JimDon
Senior Contributor III
Also keep in mind that the internal temperature sensor is on the chip, and will be subject to any heat generated by the chip. Also, it is thermally isolated in the chip, and will not change as fast as an external sensor.
It is meant to monitor the chip temperature. If you need to measure ambient temperature, you really need and external sensor.
0 Kudos