Shop OBEX P1 Docs P2 Docs Learn Events
NTC linearization — Parallax Forums

NTC linearization

ManAtWorkManAtWork Posts: 2,077
edited 2021-10-29 12:53 in Propeller 2

The cheapest method to measure the temperature of the PCB itself or a nearby heatsink, motor or whatsoever is probably to put an NTC or PTC resistor on it. Together with a normal resistor it makes a voltage divider which can be sampled with an ADC input.

The disadvantage is that the voltage to temperature relation is highly non-linear.

The picture shows the ADC value (12 bit) on the X axis and the corresponding temperature (°C) on the Y axis. The blue curve is the actual value calculated from the nominal resistance/temperature values from the data sheet. The purple curve is a polynomial approximation.

PUB AdcToTemp (a) : t | x
// polynomial approximation, a=12 bit ADC value, t=temperature in 0.1°C units
{
    x:= 1827 - a
    t:= (x * 112) + (294*512)
    x:= x*x / 4096
    t+= (x * 115)
    x:= x*x / 4096
    t+= (x * 382)
    return t / 512
}

The above code is optimized for integer math and should work for 10k NTCs from Guangdong (B=3950) together with a 10k pullup resistor in the range from -25 to +90°C. However, if the NTC type is changed or a different temperature range is required the coefficients have to be re-calculated which is not that easy.

Now that we have floating point math in Spin2 maybe somebody has better formulas where the resistor and B values can be inserted directly?

Comments

Sign In or Register to comment.