Custom Functions In Channel Conversions


Recommended Posts

I'm trying to convert the analog signal from a thermistor-resistor network to a temperature. (I know a thermalcouple would probably be better suited for this, but for now I have to work with a thermistor.) The data sheet on the thermistor does not give a single expression for converting resistance to temerature, but instead gives a table of values at certain temeratures.

So I thought I might be able to simply put this table into a function, pass the input of the channel into this function so it can find a resistance, interpolate between known points and then return a temperature. However, I'm having a lot of trouble getting a custom function to work correctly in the conversions.

In the expression for the conversion, I am calling the function like this:

Test_Sequence(Value)

Where Test_Sequence is defined as follows:

function Test_Sequence (input)

private output

output = 2*input

return output

The function Test_Sequence behaves as I expect it to (from the Command/Alert window anyway), but when I attempt to use it in the conversion expression, it doesn't seem to do anything.

Is there something I'm not handling correctly?

Link to comment
Share on other sites

I think you may have found a bug. The issue is the Value part of the conversion, since you can put test[0] in there and it works correctly (albeit still not doing what you want).

That said, I would avoid calling a sequence style function from a conversion unless you are sampling really slowly because the function call is quite slow. Instead, try and do it in a single expression. For this sort of thing, I'd build up a look-up table at startup. You should be able to build a fair bit of interpolation into the lookup table, or you can actually do the interpolation in a single expression too. Of course remember, thermistor conversions are typically third order polynomials, and you are probably going to do a linear interpolation, so its not going to be perfect. Better would be to try and figure out what the polynomial is for the conversion. Try contacting the hardware manufacturer, or look it up on the web.

Link to comment
Share on other sites

If you have a table of a values, use a curve fitting program to derive an equation that will produced the tabulated values. (Since you want to feed in the resistance and get back the temperature, treat the resistance numbers as your "X" or independent variable when you do the data entry. That will give you a function where you can plug in the resistance and get back the temperature.)

There is a DOS one on the internet called FIT2 from some professor somewhere (using a DOS program should tell you how long I've been doing this stuff!) that I use and many others I'm sure. You have to choose linear, log, exponential, polynomial (and max degree), and so on, and it will graph the data points and the best-fit curve for the type and parameters you specified. (Not bad for a DOS program). You have to try the types one at a time, but you almost always get a good fit with at least one type.

I've used this for many many data sets over the years including thermistor value tables.

Link to comment
Share on other sites

  • 1 month later...

I am working with Thermistors from Vishay. I assume NTC (negative temperature coefficients) are pretty much the same and rated based on the resistance of the device at 25 degree C. Vishay has device types at this location: http://www.vishay.com/resistors-non-linear/ntc/ Mine are pretty common and I got my equation from this sheet: http://www.vishay.com/docs/29049/ntcle100.pdf It's a forth order equation that can be found on the fourth page under formulea. The table above has the R25 numbers, color codes, and the all important 4 coefficients. The first formula is for resistance as a function of temperature, the second set (A1,B1, C1, D1) for temperature in Kelvin as a function of resistance. Just subtract 273.14 for degrees C and then divide by 5*9+32 for F if you want that. They also have for calculations for you at this site. My formula is:

R25 2.700000E+03 a1 3.354016E-03 b1 2.569850E-04 c1 2.620131E-06 d1 6.383091E-08 Rt 3.500000E+03 Rt/R25 1.30E+00 TrC =1/(a1+b1*LN(Rt/R25)+c1*(LN(Rt/R25))^2+d1*(LN(Rt/R25))^3)-273.14

Where Rt is your resistance at measured temperature. Your coefficients will be different. I'm assuming you know how to get the resistance based on your reference voltage, the reference resistor, the sensed voltage over the thermistor.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.