Searching \ for 'Solving an equation' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=solving+equation
Search entire site for: 'Solving an equation'.

Truncated match.
'Solving an equation'
1995\03\14@025846 by

On Mon, 13 Mar 1995, James L. Johnson wrote:

> Hello,

>   I am going to try to implement the solution to the Steinhart-Hart
> equation using a PIC.  This equation gives the relationship between
> the resistance of a negative-temperature-coefficient thermistor and
> its temperature.  It is an empirically determined equation, so is
> only an approximation to the relationship between resistance and
> temperature.  But, it is quite accurate over a large range as long
> as the coefficients are accurate.  The thermistor manufacturer gives
> you the coefficients so all you have to do is plug in the numbers.

>   This is a no-brainer in any high level language and we have it running
> in BASIC here in our lab.  However, it's probably rocket science to get
> it to work in a PIC.  At least it seems like it to someone who has no
> experience in programming microcontrollers (me).

For my hottub (http://hamjudo.com/cgi-bin/hottub) I use a 6811 (sorry, wrong
list) to read the thermistors.  I actually do the conversion to temperature
on a workstation, but I could do it on the 6811 if I wanted to.

I use linear interpolation into a lookup table.  I plotted the "correct"
values, the "approximate" values and the difference.  When I got the
difference small enough in the temperature range that I cared about, I said
enough, and went on to other things.

I'm using an 8 bit A to D convertor fed by a simple voltage divider.
If you're using a 16 bit A to D, you'll probably still want to use
interpolation, perhaps not linear interpolation.

---
Paul Haas   paulhhamjudo.com     Web site: http://hamjudo.com/index.html
Home: (313) 487-8739      Office: (313) 487-4357      Fax: (313) 487-4371
Finger or email my hottub at hottubhamjudo.com, seen on TV

>
>  The equation is:  1/T = a + b(ln R) + c(ln R)^3  where T is in Kelvin,
>  a,b, and c are the coefficients provided by the manufacturer, R is the
>  resistance in ohms, and the notation "ln" is the natural logarithm
>  (base e).  I assume the "cubed" term can be done by doing three
>  "multiplies" but I don't know about the log and the reciprocal.

And if you don't want to use linear interpolation, go to a good library and
look for a mathematical reference book. There are several ways of
'developing' logarithms and the inverse into sums of products. I don't want
to type them all, since they contain exponents and (constant) divisions,
and depending on the range (and acceptable pre- and post-conversion) you
can get different formulas.
Just an e.g. (from Bronstein-Semendjajew: Taschenbuch der Mathematik):

(1+x)^-m = 1 - mx + (m*(m+1))/2!*x^2 - .....  substitutes easily for 1/T (=T^-1)
and one development for ln x (for 0 < x <= 2, which can be achieved by a
ln x = (x-1) - (x-1)^2/2 + (x-1)^3/3 - (x-1)^4/4 ....

I admit, a lookup-table and some linear interpolation might be easier (and
probably is the more usual way of doing these things), but above can be as
accurate as you want it with less memory 9and more calculating time).

Bye
Markus

P.S. No, I haven't actually tried to implement this in a uP (yet !).

Your approach is probably possible on a PIC, although you don't say
which one you're thinking of using, but on small micros I would think
looking up the temperature in a table would be more practical.

Tim McDonough -- timmedcencom.net

On Mon, 13 Mar 1995, James L. Johnson wrote:

{Quote hidden}

I want to thank all the people who sent responses to my request for
solving the Steinhart-Hart equation.  There certainly is a consensus
out there for the lookup table idea.  After reading all the suggestions,
I would be foolish to do it any other way.  I've been thinking more
about my application, and for what I want to do, it seems that I can
implement this loop with only the knowledge of what the voltage is on
the bridge.  This voltage is read by the AD7714 (A/D converter, the
output of which is converted to a serial word) and if it is not zero
(a balanced bridge), then I can create a correction signal according
to the size of the error (proportional plus integral controller), and
apply or reduce the heat until the thermistor bridge is again balanced.
During all this, I don't really need to know the number of degrees that
the thermistor is off from the setpoint, I just need to know the bridge
voltage and take the necessary action to bring it back into balance.

We want the number of degrees of error for design/development/diagnostic
purposes as we characterize the oven, the controller hardware, and the
software algorithm.  We are still able to do this in the lab using table
top computers running BASIC.  But for the PIC implementation, all we want
is for that bridge to balance and for the loop dynamic characteristics to
be what we specify.  So using a lookup table and simpler integer arithmetic
is certainly the way to go.

Thanks again for the help and the good ideas and pointers to the
various utilities and methods that all you bright designers have already

Jim Johnson
jjohnsonhpl.hp.com

>> getlog  jmp     pc+w
>          ^^^^^^^^^^^^
>what is the Microchip/OPCODE equivalent of this instruction ?

and retw codes to retlw

--  Tom Mornini -------------------------------------------------------------
--  Parallax, Inc.  ---------------------------------------------------------
--  Makers of really cool PIC development tools & the BASIC Stamps  ---------
--  http://www.parallaxinc.com              ftp://ftp.parallaxinc.com/pub
--

> what is the Microchip/OPCODE equivalent of this instruction ?

(computed GOTO)
--Chuck

> the bridge.  This voltage is read by the AD7714 (A/D converter, the
> output of which is converted to a serial word) and if it is not zero
> (a balanced bridge), then I can create a correction signal according
> to the size of the error (proportional plus integral controller), and
> apply or reduce the heat until the thermistor bridge is again balanced.
> During all this, I don't really need to know the number of degrees that
> the thermistor is off from the setpoint, I just need to know the bridge
> voltage and take the necessary action to bring it back into balance.
>

This is fine if the thermistor / measuring circuit is reasonably linear
over the range you intend to use, but if it isn't, the gain of your
control loop will vary with the setpoint. You may need to take this into
account when optimising the PID parameters.