View previous topic :: View next topic 
Author 
Message 
Per Svensson
Joined: 03 Oct 2004 Posts: 207 Location: Gothenburg, Sweden

Posted: Sat Aug 17, 2019 4:46 pm Post subject: Use math for NTC temperature calculations 


Using tables for calculating temperature from thermistor readings is not very flexible when Alfa and Beta parameters varies
A more general method is to use the formula Temp(Celcius) =Ro*EXP(Beta/(273.15+$A32)Beta/(273.15+25))
See attached Excel sheet where you can simulate all variants as long as Alfa and Beta are known.
If there is an interest I can also upload a bascom implementation so you don't have to figure out the math coding
/Per 

Back to top 


Per Svensson
Joined: 03 Oct 2004 Posts: 207 Location: Gothenburg, Sweden

Posted: Sat Aug 17, 2019 5:14 pm Post subject: 


… And here is the code
'************************************************************************************
' A thermistor is connected from Vref (+5V) to GND via a resistor R1.
' The voltage to the ADC is a nonlinear representation of the temperature.
' NTC resistance is nominally Res25 ohm at 25degC and R1 is fixed and can be any value. But..
' the best accuracy when R1 is selected to equal NTC's resistance at the temp where best accuracy is desired.
' See Excel spreadsheet "NTC beräkningar.xls"
' /> To ADC
' 
'Vref oNTCoR1
'Farnell 732138
Const Beta = 3620 'Thermistors Beta value
Const Res25 = 10000 'Thermistors resistance at 25 deg C
Const Res1 = 10000 'Fixed resistor to ground (Ususally close to Res25)
Function Adc_to_temp(byval Adcval As Word) As Single
'****************************************************************
' Convert from ADC reading to temperature Celsius
' T = 1/Beta(ln(R1/R25((1024/ADCVAL)1))+1/(273.15+25))  273.15
'****************************************************************
Local X As Single
X = Adcval 'Avarage voltage expressed in ADCunits (01023)
'convert ADCoutput to temperature using a logarithmic relation:
X = 1024 / X 'Ratio of max value
X = X  1
X = X * Res1 'Resistor connector to ground
'X is now the resistance of the thermistor. Compute the temperature this represents
X = X / Res25 'NTC resistance at 25 deg C
X = Log(x)
X = X / Beta
X = X + 0.003354
X = 1 / X
X = X  273.15 'Kelvin > Celsius
'T is now the true temperature in degrees Celsius
Adc_to_temp = X + Temp_offset 'adjust sample with offset and Return result
End Function 

Back to top 


