Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Use math for NTC temperature calculations

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various
View previous topic :: View next topic  
Author Message
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 185
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Sat Aug 17, 2019 4:46 pm    Post subject: Use math for NTC temperature calculations Reply with quote

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
View user's profile Visit poster's website
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 185
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Sat Aug 17, 2019 5:14 pm    Post subject: Reply with quote

… 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 o---NTC---o---R1-----|

'Farnell 732-138
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 ADC-units (0-1023)

'convert ADC-output 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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum