Well, for limited temp ranges, you can fit a polynomial to it and get pretty decent results -- I've done that for 0-50C. The problem is that the curve really is logarithmic, so no polynomial will fit very well, at least not over any extended temp range. Hint -- buried in Excel somewhere there is a polynomial curve-fitting wizard, I just don't remember where. > -----Original Message----- > From: Eisermann, Phil [Ridg/CO] [mailto:peiserma@RIDGID.COM] > Sent: Monday, May 22, 2000 12:47 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC] Converting A/D into Temperature > > > Damon wrote: > > I've got an A/D circuit on my 16F874. > > I have a couple of OP Amps hooked to some resistors a few Pots and a > > thermistor so that I get a 5X gain on the voltage. > (schematic available > > if needed) > > I have it giving me 2.5V at room temp. But for the LIFE of > me I can't > > figure out how to convert the 0-1023 value into a usable > temperature. > > I have an Excel spreadsheet that will tell me the readout > if I type in > > the voltage example: 0v=0, 5V=1023, 2.5V=512, 2.813782991V=576 > > > > From my chart that last Voltage should correspond to a > reading of 68F > > (20C) > > Maybe it's late and it's really simple but I can't figure > it out.. any > > help out there? > > > > > Well, using a thermistor, it's not exactly > straightforward. The > reason > is the highly non-linear resistance to temperature > characteristic of the > thermistor. I have been working on something similar (in my copious > spare time). This equation is from memory, i'll look it up > tonight when > I get home: > > T(Kelvin) = 1/(A + B*ln(R) + C*(ln(R)^3)) > > This equation is the Steinhart-Hart equation. R is the resistance > of the thermistor. A, B, and C are material constants that > you can figure > out by measuring the resistance at three different temperatures. The > constants are all less than 1 for my particular thermistor. > > Now you can see the difficulty with this equation in a PIC. While the > fractional values can be taken care of by scaling everything, > calculating the natural log function is a bit more difficult. On top > of that, the temperature (in Kelvin) is actually the inverse. > > Of course, I admit I am not the world's greatest PIC > programmer. Perhaps > there is an easy way to realize the required mathematical operations > on a PIC. > > In my circuit, I placed the thermistor in parallel with a > fixed resistor > in an attempt to linearize the resistance a little. Over a certain > range of values, this works fairly well. > > A lookup table is one possible solution. You could put a lookup > table for all possible values in external EEPROM. Or you could > place a smaller lookup table in memory, and interpolate between > points. > > If anyone has any other ideas, please jump in. > > Phil Eisermann > H:(440) 284-3787 (mazer@ix.netcom.com) > O:(440) 329-4680 (peiserma@ridgid.com) >