Calculating NTC temperature

Discussion in 'Programmer's Corner' started by nerdegutta, Jul 14, 2012.

  1. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    To calculate the Celsius I've found this code snippet:

    Code ( (Unknown Language)):
    1.  
    2. temperature = log(((10240000/adc_raw)-10000));
    3. temperature=1 / (0.001129148 + (0.000234125 * temperature) + (0.0000000876741 * temperature * temperature * temperature));
    4. temperature = temperature - 273;
    5.  
    This assumes that I have a setup like this:

    GND|-----|10K|-----|uC|-----|NTC*|-----|+5vdc

    *10K @ 25°C
    The uC is to the ADC pin on PIC18F25K22

    Now it turns out that my DIY thermometer is approximately 1° lower than the commercial I've bought. (It's really cheap, so it could be wrong.)

    I've measured the 10K resistor, and it shows 9 960 Ohm, so I changed 10000 in the code snippet to:

    Code ( (Unknown Language)):
    1.  
    2. temperature = log(((10240000/adc_raw)-9960));
    3. temperature=1 / (0.001129148 + (0.000234125 * temperature) + (0.0000000876741 * temperature * temperature * temperature));
    4. temperature = temperature - 273;
    5.  
    But it's still off.

    So I was thinking of putting a 10K pot in series with the 10K, and change the 10K to a 5.6K. Like this:

    GND|-----|10K pot|-----|5.6K|-----|uC|-----|NTC*|-----|+5vdc

    This way the resistance is adjustable and I can calibrate it with my commercial one.

    Is it a good idea or not?

    Everything is breadboarded, so I was also wondering if stray capacitance could be an issue, but as long as I'm not doing any RF, I don't think so.
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    nerdegutta likes this.
  3. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
  4. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    That code snippet you found, was it for a thermistor with YOUR thermistor's temperature coefficients? My guess is that those numbers are for a different part and that most NTC thermistors have sufficiently similar coefficients that it gets you reasonably close. You might look to see if you can find the actual nominal coefficients for your device.
     
    nerdegutta likes this.
  5. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
  6. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    It looks like they are doing the same thing you are doing -- finding some example code and using it. The Wikipedia article they cite specifically states that the values are "typical".

    You want to find the actual part number for the thermistor you are using. This may or may not be indicated on the part itself (probably not). But look at the documentation for the board that it came with and see if the bill of materials gives a manufacturer and part number. Or, if they were being unusually complete, they would provide the coefficients in their own documentation.
     
  7. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    I have the datasheet, and my NTC is 10K @ 25° C. With R/T No. 4901.

    It say's in the ΔT[+-°C] - column 1.2. Does that mead it can 1.2° off the actual temperature?
     
  8. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    Are you sure you have the 5% part (p16) and not the 10% part (p17)?

    Yes, that is what that means, although that is talking about the error range compared to the assumed nominal device. You can almost certainly calibrate your device to be considerably better than that.

    You might find this document handy: EPCOS Standardized R/T Characteristics
     
  9. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    I have the +/-10%. Checked with the supplier.

    So that means I'm well within the +/-10%, and everything should be OK?

    Thanks for the doc.:)
     
  10. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    If you aren't sure which thermometer is off (and you've got one) use a body temperature thermometer, they are usually accurate to better than 0.5 C
    Of course that only gives one point so won't deal with nonlinearity.
     
    Last edited: Jul 14, 2012
  11. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    Nice tip. :)

    I'll keep that in mind.
     
  12. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    I found this calculator.

    http://www.thermistor.com/calculators.php

    But the thermometers are still not equal. Guess I have to buy some more precise NTC's, or use a LM35. Would that be easier?
     
  13. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    Do you have enough confidence in the thermometer you are comparing it to in order to consider it "correct"?

    Can you take resistance measurements at three or four fairly widely spaced temperatures?

    If so, you can compute your own coefficients very easily.
     
  14. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    I'm starting to doubt it now.

    With some effort I can move around.:)

    Please show me.
     
  15. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    Are you comfortable solving a system of four linear equations in four unknowns?
     
  16. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    Not too comfortable. But if I get the formula(s) and where to find the starting numbers, I'd like to try. :)
     
  17. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    If you interface a nonlinear thermistor to an MCU you can easily correct for non-linearity.
    I or WBahn can show you how. Also you do not need an ADC to measure the thermistor. A single I/O pin and a capacitor will do it. I will show you the way.

    (btw, we never finished our thermometer project.)
     
    Last edited: Jul 15, 2012
  18. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Wolfram alpha can solve them for you, just put the four equations in, separated by commas. It's not as fun as doing it by hand, but easier.
    http://www.wolframalpha.com/
     
  19. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,515
    785
    That would be awesome!
    I know... That's why I'm messing with this now. Trying to learn and understand, and I figured it would be easier to start with LCD instead of multiplexing seven segments. I'm sure that's easy too, but, well here I am. :)

    Can you show me the four equations?
     
  20. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    Before we jump in we have to look at the details and do some analysis.

    What is your temperature range of interest? I will assume -20 to +55C for now.
    What is your target resolution? I will assume 0.5C is good enough.

    Are you building one unit or planning on multiple?
    If you are planning to manufacture and market a number of units I would aim for no calibration requirement. Hence I would choose at minimum a 1% component.
    If you are just building one unit for the fun of it then you can plan on calibrating the single unit. Do you have an accurate thermometer handy? Analog or digital?

    We can use the manufacturer's data sheet to do some initial analysis.
    Do you have Matlab? Otherwise we will have to resort to Excel spreadsheet.
     
    nerdegutta likes this.
Loading...