3
$\begingroup$

I'm trying to implement an electronic temperature sensor that gives a resistance value. The sensor is a Honeywell TD4.

In the datasheet, they give a table of values :

  • -40ºC => 1584Ω ±12Ω
  • -30ºC => 1649Ω ±11Ω
  • -20ºC => 1715Ω ±10Ω
  • -10ºC => 1784Ω ±9Ω
  • 0ºC => 1854Ω ±8Ω
  • +10ºC => 1926Ω ±6Ω
  • +20ºC => 2000Ω ±5Ω
  • +30ºC => 2076Ω ±6Ω
  • +40ºC => 2153Ω ±6Ω
  • +50ºC => 2233Ω ±7Ω
  • ... (up to 150ºC)

They give a quadratic equation for computing resistance given the temperature:

$$R_T = R_0 + (3.84×10^{-3}×R_0×T) + (4.94×10^{-6}×R_0×T^2)$$

  • where $R_T$ is the resistance at temperature R,
  • $R_0$, resistance at 0ºC and
  • T the temperature in ºC.

we now want to get this equation the other way around, i.e. having the temperature given the resistance: $$T = f(R_T)$$

As we wanted to reduce the equation to get only one $T$, we calculated the discriminant, so we get :

$$∆ = b^2-4ac = (3.84×10^{-3}×R_0)^2 -4×4.94×10^{-6}×R_0×R_0$$ $$∆ = (3.84×0.001×1854)×(3.84×0.001×1854)-(4×4.94×0.000001×1854×1854)$$ $$∆ = -17.236077350399988$$

It is negative, thus there is no real roots, only the complex ones...

But our problem is that we want to come with a formula up we can implement in a microcontroller to get the value with the best precision... But my mathematics skills from highschool are far behind (if I knew at that time that I would actually have to solve such an equation in the real world ;-)). I may be wrong in the way to extract $T$ from $R_T$'s formula. But then what could be the good way ?

While I don't have a solution, I'm implementing in the microcontroller a linear formula for each segment of the given table...

  • 2
    The discriminant is $\Delta = b^2-4ac$ when the quadratic is in the form $ax^2+bx+c=0$, with *zero* on the other side. When you put your equation into this form, you'll find that $c$ is $R_0 - R_T$, not simply $R_0$. Then you can apply the quadratic formula as usual (though you'll probably get the same answer as @Tpofofn below).2012-09-05

2 Answers 2

2

It is not necessary to solve for the discriminant because the LHS is not zero. I recommend that you take the following approach.

EDIT to illustrate completion of the square

  1. Factor $R_0$ out of the RHS and move to the LHS as $R_T/R_0$. $$R_T/R_0 = 1 + (3.84×10^{-3}×T) + (4.94×10^{-6}×T^2)$$
  2. Complete the square on the RHS. $$R_T/R_0 = 1 - \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}+ \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}+ (3.84×10^{-3}×T) + (4.94×10^{-6}×T^2)$$
  3. Move the extra constant to the LHS. $$R_T/R_0 - 1 + \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}= \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}+ (3.84×10^{-3}×T) + (4.94×10^{-6}×T^2)$$ $$R_T/R_0 - 1 + \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}= \left(\frac{3.84×10^{-3}}{2(4.94×10^{-6})^\frac{1}{2}} + (4.94×10^{-6})^\frac{1}{2}×T\right)^2$$
  4. Take the square root of each side (be careful about which branch you choose (i.e. +/-)). (This should get rid of the $T^2$ term.) $$\frac{3.84×10^{-3}}{2(4.94×10^{-6})^\frac{1}{2}} + (4.94×10^{-6})^\frac{1}{2}×T = \sqrt{R_T/R_0 - 1 + \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}} $$
  5. Solve for $T$. $$ (4.94×10^{-6})^\frac{1}{2}×T = \sqrt{R_T/R_0 - 1 + \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}} - \frac{3.84×10^{-3}}{2(4.94×10^{-6})^\frac{1}{2}} $$ $$T = \frac{1}{(4.94×10^{-6})^\frac{1}{2}}\left(\sqrt{R_T/R_0 - 1 + \frac{(3.84×10^{-3})^2}{4(4.94×10^{-6})}} - \frac{3.84×10^{-3}}{2(4.94×10^{-6})^\frac{1}{2}}\right) $$

Also note that $R_T/R_0 must be > 0.25376518218$ which appears to hold from your posted data.

  • 0
    so following your advices I got: $R_0/R_T-1 = aT^2+bT$ where $a=4.94×10^{-6}$ and $b=3.84×10^{-3}$ but I don't get where you're going on step 4. I mean, if I do $\sqrt{aT^2+bT}$ I'll get a $\sqrt{T}$ which doesn't help, don't I?2012-09-04
  • 1
    In step 2 you are supposed to add a constant to make the right side a perfect square. It is $\frac {b^2}{4a}$. Then the square root becomes $\sqrt{aT^2+bT+\frac {b^2}{4a}}=\sqrt a(T + \frac b{2a})$. But this still has you taking a square root of an expression every time you want a temperature-maybe not what you want to do.2012-09-04
  • 0
    thank you a lot for your help, I'm definitely bad at that kind of maths. I had a hard time implementing it in python to validate the formula, but with the sane help of a colleague, we end up with something working.2012-09-06
2

One approach is to fit the data in the other sense. For the data you give, Excel gives $T=2\cdot 10^{-5}R^2+.232R-345.9$. The data looks quite linear over this span-would a straight line over the whole range be accurate enough for you?

Added: that fit seems to be polluted with roundoff error due to the high resistance values. If you use kohm instead it works very well. The fit (over the range -40 to +150) is $T=-16.941*R^2+201.93*R-316.55$, which is within 1 degree over the whole range.

  • 0
    for the time being, I implemented a linear calculation for each domain given by the datasheet (the data I posted), which has been the easy solution. What I'm trying to find out now, is the general formula to compute temperature from the measured resistance.2012-09-06
  • 0
    @zmo: I only typed in as many points as you posted. The fit I give will be accurate over that range. You could put all the data into Excel and ask for a quadratic trendline to get one over the whole range.2012-09-06
  • 0
    I don't understand, I implemented it in python which is: `def calculate_temp(R): return ((2e-5)*pow(R,2))+(.232*R)-345.9` and when I execute `calculate_temp(2000)` I expect 20ºC, whereas it returns `198.10000000000002` ... what would be wrong ?2012-09-06
  • 1
    @zmo: I lost a minus sign (overlapped with the grid) on the quadratic term, so it should be $T=-2\cdot 10^{-5}R^2+.232R-345.9$ but that still gives $38.$ The fit is terrible and all the values are too high. The linear fit is not so bad: $T=0.1227R-227.55$ is within $4$ degrees except at the very ends.2012-09-06
  • 0
    @zmo: I don't know if my edit will ping you, so here is a comment that will.2012-09-06
  • 0
    thank you a lot for your time and help, but my question was to find the most accurate way to get T=f(R), which by solving that !@#$!@#$ing equation, which is being done by @TPofofn. Your solution was better than the one I originally had, but still not as good. And really, thank you a lot for your help and time Ross, I do appreciate that a lot! If I could I would reward both of your answers, actually :-)2012-09-06
  • 0
    @zmo: whatever works for you. I wouldn't demand tremendous accuracy-the specified resistance errors are 5C at the bottom end, but only 0.1 C at the top. You may not have square root available on a microcontroller, so a quadratic fit may be easier.2012-09-06