Shop OBEX P1 Docs P2 Docs Learn Events
Thermistor with steinhart problems [Solved] — Parallax Forums

Thermistor with steinhart problems [Solved]

CrosswindsCrosswinds Posts: 182
edited 2016-08-20 17:50 in Propeller 1
Hello!

So ive found a small snippet of code on the forums that is used for calculating temperature from a thermistor.

Ive tried do incorporate that in my larger program, but failed. So ive made a small version just as a test to rule out everything else. I still get the same problems.

Here is the code:

CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000


one = 1.0

OBJ


debug : "FullDuplexSerial"
G : "Float32"
FS : "FloatString"

VAR


long kel




PUB main

debug.start(31,30,0,19200)

repeat 'just so we dont miss out on the pst start..
waitcnt(clkfreq * 1 + cnt)


debug.str(string(16))
kel := Calc_StHart(2.108508173,0.7979204727,6.535076315,10000.0)
debug.str(FS.FloatToString(kel))



Pub Calc_StHart (A,B,C,Resistance) : kelvin | B_x_Rlog , C_x_Rlog , Rcubed, Rlog, Addit

G.start ' Start math32

Rlog := G.log(Resistance) ' Take the log of the Resistance
B_x_Rlog := G.FMul(B,Rlog) ' Multiply B to log of R

RCubed := G.FMul(Rlog,Rlog) ' Cube the log of R by R * R * R
RCubed := G.FMul(Rlog,RCubed) ' Finish the Cube

C_x_Rlog := G.FMul(RCubed,C) ' Multiply C to log the cubed log R

Addit := G.Fadd(C_x_Rlog,B_x_Rlog)
Addit := G.Fadd(Addit, A) ' Add all A,B,C together
Kelvin := G.Fdiv(one,addit) ' Kelvin = 1/ all added

G.stop





Now, i just have used hardcoded values just to test it. And it still fails. it gives me 0.000195487 as a result.
However, the result should be around 25c (in kelvin right now though)

To get the A B C values ive used SRS thermistor calculator. Dont know if that one is OK or not. And ive used another one but it failed in the same way.
Iam using vishay NTCLG100E2 thermistor..

Comments

  • Howdy - I plugged your A,B,C, and R into the standard equation (just with a calculator) and got nonsense results as well, which leads me to think the numbers are bogus. Can you use the simplified formula? According to the data sheet that B constant would be 3977. In that case you solve the equation attached and get reasonable numbers (use consistent units).





    180 x 44 - 857B
  • Hello!

    Yeah, they probably are. I dont know why though.

    Iam not familliar with the simplyfied formula. (Ive read so much about this the last couple of Days that i cannot keep them separated anymore) Any instructions for it?
  • That's odd - I uploaded a render of it.... Anyhow it is just

    (1/T) = (1/T0) + (1/B) ln(R/R0)

    Where T0 is 25 C, R0 is 10000 Ohms, and B is 3977 for your case. Not quite as accurate at the full equation, but much easier to use as long as it works for your application!
  • geo_leeman wrote: »
    That's odd - I uploaded a render of it.... Anyhow it is just

    (1/T) = (1/T0) + (1/B) ln(R/R0)

    Where T0 is 25 C, R0 is 10000 Ohms, and B is 3977 for your case. Not quite as accurate at the full equation, but much easier to use as long as it works for your application!

    Thank you very much for your help!

    Its strange that we cant seem to figure out the right ABC for this thermistor, ive used some calculators found online, and for some reason they all give different results(!)

    Ive just confirmed this, by taking the ABC values, found from an arduino project online, and then it works. Actually its really pretty close with my datasheet table.. But it would be great to know or find a calculator that can do the right calculations for my thermistor..



  • Hello again!

    i di find this link: rusefi.com/Steinhart-Hart.html

    And after converting three Celsius values to Fahrenheit it did the trick, and work with my sensor!

    The code above works, with the right ABC
  • Great! That is a really useful calculator link!
Sign In or Register to comment.