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);}
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; }
TempC = 25.0 - [(Vtemp – 0.7013) ÷ 0.0017] + Tcal
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]
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
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.
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...
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?
Can you calculate the temperature without this calibration process and see by what margin is temperature deviating?
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 typicalTempC = 8ºC