Shop OBEX P1 Docs P2 Docs Learn Events
RCdecay calculate temperature from a thermistor — Parallax Forums

RCdecay calculate temperature from a thermistor

Hello!

I'm trying to make a program that is measuring temperature from an thermistor.

I need a thermistor because they seem to be the only ones to take temps up to 200celcius.
I don't need 0,1c accuracy.

I have in my datasheet a table that shows resistance vs temperature.

And i have via RCdecay in the kit labs book, page 126 made a experimental circuit to see what times shows up on three different resistance.

Example:
10K = 65500
1K = 6300
68 ohm = 220


Now i don't mind making some kind of look-up table for this, by using the datasheets 5degrees "steps" but i cannot find a good way to calculate what resistance that gives what times.
Now my math is not the best, so this might be the cause! :)


Does someone have any tips on calculating a given resistance from the table to a RCtime value? Maybe it is not even possible to do that?





Comments

  • jmgjmg Posts: 15,173
    Use a number of resistor values in your area of interest, and then fit this equation.

    https://en.wikipedia.org/wiki/Time_constant

    a46f9dcf564bebc67c377f985203d301.png
  • kwinnkwinn Posts: 8,697
    Posting the circuit you are using and the part number or resistance table of the thermistor would help a lot.
  • A quick look at my fav website for temperature questions is Omega Engineering. They are the best. First measuring temperature at 200 degrees C is almost 400 degrees F. It is hard enough under the best of conditions to measure temperature even at "room" temperature.
    Second, looking at common thermistors, they appear to top out at 250 degrees F. So being a resistive element, thermistors are likely to either burn up or become unstable at 400 degrees F. Maybe you are thinking of thermoCOUPLES, which are good up to 1000 degrees or more. They are made up of two dissimilar metal alloy wires welded together.
    Using an RC circuit under these conditions just has too many variables and instabilities to get a good reading - Best to use a good op amp and ADC chip for best results. There are many circuits and software examples to do this.
  • I found thermistors that were good into 500*F / 250*C. The ones used in 3D printer hot ends are cheap and easy to find. If you look at the datasheet for the thermistor, you should see a table of resistance values for a given temperature. I used this table in an excel spreadsheet to figure out what the decay time would be for each resistance value given my specific capacitor, and turned that into a number of clocks at 80MHz.

    For example:
    10*C = 201660ohms

    The decay time to fall below threshold voltage is 0.693 * capacitance * resistance. So for a 1uF cap, it becomes 0.693 * 0.000001 * resistance, which is a decay time of 0.13975038 sec. That number * 80M clocks per second gives 11180030 clocks.

    Do that for ALL the temperatures in the table and you get something like this:
    'Resistance table
    '                   Temp    Clocks  (49 entries, x 2 longs)
    ResistTable   long   50,    11180030
    ResistTab01   long   59,    8787240
    ResistTab02   long   68,    6956057
    ResistTab03   long   77,    5544000
    ResistTab04   long   86,    4447563
    ResistTab05   long   95,    3590239
    ResistTab06   long  104,    2915534
    ResistTab07   long  113,    2381203
    ResistTab08   long  122,    1955480
    ResistTab09   long  131,    1614357
    ResistTab10   long  140,    1339486
    ResistTab11   long  149,    1116783
    ResistTab12   long  158,    935495
    ResistTab13   long  167,    787137
    ResistTab14   long  176,    665169
    ResistTab15   long  185,    564435
    ResistTab16   long  194,    480887
    ResistTab17   long  203,    411309
    ResistTab18   long  212,    353097
    ResistTab19   long  221,    304199
    ResistTab20   long  230,    263007
    ResistTab21   long  239,    228136
    ResistTab22   long  248,    198531
    ResistTab23   long  257,    173305
    ResistTab24   long  266,    151739
    ResistTab25   long  275,    133278
    ResistTab26   long  284,    117366
    ResistTab27   long  293,    103617
    ResistTab28   long  301,    91753
    ResistTab29   long  311,    81441
    ResistTab30   long  320,    72460
    ResistTab31   long  329,    64643
    ResistTab32   long  338,    57824
    ResistTab33   long  347,    51809
    ResistTab34   long  356,    46531
    ResistTab35   long  365,    41879
    ResistTab36   long  374,    37771
    ResistTab37   long  383,    34140
    ResistTab38   long  392,    30913
    ResistTab39   long  401,    28047
    ResistTab40   long  410,    25497
    ResistTab41   long  419,    23218
    ResistTab42   long  428,    21178
    ResistTab43   long  437,    19354
    ResistTab44   long  446,    17713
    ResistTab45   long  455,    16238
    ResistTab46   long  464,    14913
    ResistTab47   long  473,    13710
    ResistTab48   long  482,    12629
    

    Note that I also converted the Deg*C into Deg*F for my use, so the Temperature list there is in Fahrenheit.

    Once you have this table, do your RCTime measurement as usual and just figure out which table entries it's between, and interpolate.
      repeat
    
        reading := RCTIME( 1 )
    
        i := 1
        repeat while ( (long[@ResistTable][i] => reading)  AND  (i =< constant(49*2)) ) 
          i += 2
    
        i -= 3
    
        t2 := long[@ResistTable][i+0]     
        t1 := long[@ResistTable][i+2]     
    
        r2 := long[@ResistTable][i+1]     
        r1 := long[@ResistTable][i+3]     
    
        rd := r2 - r1
        td := t2 - t1
    
        t := t1 + ((((reading - r1) << 8)  / rd) * td) ~> 8        
        
        dbg.dec( reading )
        dbg.tx( 32 )
        dbg.dec( t )
        dbg.tx(13)      
      
        waitcnt( 800_000 + cnt )
    

  • Hello everyone!

    Thanks for your help.

    Jason, your entry seems to be exactly what i meant! Thank you very much.
    This will probably give me the ~5 degree resolution i need since the table from the datasheet is is 5 degree incraments.

    Thank you!
  • Hello again Jason.

    Im still missing something.

    When i use the Testrcdecay example and the circuit from page 127 PElabs book, and use a 220k resistor, my time returns as around 4418543.
    However, calculating as you said: 0.693 * 0.000001 * 220000 gives me 0.15246
    Clearly i have misunderstood something :)

    Any ideas?
  • I'm not sure if the RCDecay code returns the same results as the RCTime() function. RCTime returns how long it took for the pin to drop below the threshold voltage, in clock cycles. Clock cycles are typically 80MHz (80,000,000 / sec). It appears that's what RCDecay does too, but it's one difference.

    The circuit you're referring to also uses a 0.01uF cap, whereas my example was for a 1uF. Your multiplier should be 1/100,000,000, not 1/1,000,000. That wouldn't account for all your difference though. If you're using long wires or a breadboard, there may be extra capacitance in your circuit. You might have better luck using a larger cap, as it'll be less sensitive to additional capacitance in the circuit.

    The formula you wrote above where you get 0.15246 - That result is in seconds, not cycles. Multiply by 80,000,000 and you get 12,196,800 cycles. Your measured result is off by about a factor of 3, so look over your components and make sure you have all the values correct.
  • CrosswindsCrosswinds Posts: 182
    edited 2015-09-05 13:55
    JasonDorie wrote: »
    I'm not sure if the RCDecay code returns the same results as the RCTime() function. RCTime returns how long it took for the pin to drop below the threshold voltage, in clock cycles. Clock cycles are typically 80MHz (80,000,000 / sec). It appears that's what RCDecay does too, but it's one difference.

    The circuit you're referring to also uses a 0.01uF cap, whereas my example was for a 1uF. Your multiplier should be 1/100,000,000, not 1/1,000,000. That wouldn't account for all your difference though. If you're using long wires or a breadboard, there may be extra capacitance in your circuit. You might have better luck using a larger cap, as it'll be less sensitive to additional capacitance in the circuit.

    The formula you wrote above where you get 0.15246 - That result is in seconds, not cycles. Multiply by 80,000,000 and you get 12,196,800 cycles. Your measured result is off by about a factor of 3, so look over your components and make sure you have all the values correct.

    Again thanks for your help.

    I did actually adopt my circuit to include the 1uF cap as stated in your example. But i did use the RCdecay instead.
    So i made a new program, using RCtime instead.

    With that, and a 1K resistor, i get a time output directly from RCtime 3891

    But, by the calculation 0,693*0,000001*1000 = 0,000693 and that 0,000693 * 80000000 = 55440

    There is still someting wrong that im missing, but cannot figure out what..

    Edit: oh, and also, it does react accordingly, larger resistor, longer "time"


  • kwinnkwinn Posts: 8,697
    I don't know if it is practical for you to do this, but I avoid the whole issue of complex calculations by producing a calibration curve based on the inputs available and outputs desired.

    For temperature I have a thermocouple for my multimeter from which I get the temperature in C or F, and a small box with a fan and heater that I can put my thermocouple and the temperature measurement boards into. A simple spin program reads and stores the RC time from each board when I press a button and sends it to teraterm. Using that temperature and time data table I can convert RC time to temperature and get very consistent and accurate results.

    You could do something like that if you have something that can measure up to the 200*C with reasonable accuracy. The other option would be to use resistors or a potentiometer to measure the RC time for each value in the table to create a temperature vs RC time table. Either way simplifies the calculations.
  • Personally I would get rid of the capacitor and look at the thermistor through a voltage divider and an external ADC or sigma delta ADC.

    The output will be exponential, not unlike the output from an RC, and probably more stable to work with.
  • kwinnkwinn Posts: 8,697
    Personally I would get rid of the capacitor and look at the thermistor through a voltage divider and an external ADC or sigma delta ADC.

    The output will be exponential, not unlike the output from an RC, and probably more stable to work with.

    Probably the best way to go, and the way it is usually done in the commercial building automation systems i have seen.
  • Hello everyone!

    Thank you for all your help.

    I went the ADC way. Seems to work great.


Sign In or Register to comment.