It is quite possible there are errors.
The generating function was created by fitting published data to a
polynomial by least-square fit using "octave".
http://owfs.sourceforge.net/thermocouple/type_t.html

I'll have to check again.

Paul Alfille

On 11/7/07, Tom Collins <[EMAIL PROTECTED]> wrote:
>
> It looks like the coefficient table, or perhaps the polycomp() function
> doesn't work correctly for some of the temperatures for a Type T
> thermocouple.  I'm working with negative temperatures, and it totally freaks
> out.
> I've taken the code out and put it in a standalone program that I could
> test with.  I've made some minor changes to the functions so it will run
> independently, but nothing that would have caused these problems (best I can
> tell).
>
> The test program displays two tables -- one of ambient temperatures to mV
> readings.  All match up to the Type T table.
>
> The other does a table with a bunch of mV readings from -270C (-6.258mV)
> up to 0C (0.0mV).  As you can see from the output, something is very
> wrong.  How was the type_t table generated?  Could it have been generated
> with the wrong source tables?
> -Tom
>
> Code:
>
> #include <stdio.h>
>
> struct thermocouple {
> float v1, v2;
> float rangeLow, rangeHigh;
> float low[11];
> float mid[11];
> float high[11];
> float mV[11];
> };
>
> const struct thermocouple type_t = {
> -1.785, 2.556, -270.0, 400.0,
> {-0.0856873, -3.35591, -58.1948, -587.947, -3829.53, -16790.4,
>  -50151.1, -100705, -130042, -97452.3, -32202.6,},
> {0.000151427, 3.35406e-05, -0.00372056, 0.00326535, 0.022672,
>  -0.0222902, -0.0694538, 0.116881, -0.67161, 25.8257, -0.0024547,},
> {-5.44871e-11, 6.49228e-09, -3.38465e-07, 1.02385e-05, -0.000201171,
>  0.00272364, -0.0263712, 0.192645, -1.30813, 27.0402, -0.900659,},
> {-1.1498e-22, 7.18468e-21, 5.31691e-18, -2.88407e-16, -9.51445e-14,
>  4.02711e-12, 8.60657e-10, -5.74685e-08, 4.17544e-05, 0.0386747,
>  -0.000253129,},
> };
>
> /* Compute a 10th order polynomial with cooef being a10, a9, ... a0 */
> float polycomp(float x, float * coef)
> {
> float r;
> int i;
>
> r = coef[0];
> for (i = 1; i <= 10; ++i)
> r = x * r + coef[i];
> return r;
> }
>
> // T is temp in degrees C, mV is voltage in millivolts
> float thermocouple(struct thermocouple *thermo, float T, float mV)
> {
> /* Correct voltage by adding reference temperature voltage */
> mV = mV + polycomp(T, thermo->mV);
>
> /* Find right range, them compute temparature from voltage */
> if (mV < thermo->v1) {
> return polycomp(mV, thermo->low);
> } else if (mV < thermo->v2) {
> return polycomp(mV, thermo->mid);
> } else {
> return polycomp(mV, thermo->high);
> }
> }
>
> int main ()
> {
> int i;
> float t;
> float mV;
>
> printf ("thermocouple table:\n");
> for (i = 0; i < 30; i++) {
> printf ("%3dC = %.5fmV\n", i, polycomp (i * 1.0, type_t.mV));
> }
>
> for (i = -6258; i < 0; i += 164) {
> mV = i * 0.001;
> t = thermocouple (&type_t, 0.0, mV);
> printf ("%.3fmV = %.2fC\n", mV, t);
> }
>
> }
>
> Output:
>
> thermocouple table:
>   0C = -0.00025mV
>   1C = 0.03846mV
>   2C = 0.07726mV
>   3C = 0.11615mV
>   4C = 0.15511mV
>   5C = 0.19416mV
>   6C = 0.23329mV
>   7C = 0.27250mV
>   8C = 0.31179mV
>   9C = 0.35117mV
> 10C = 0.39062mV
> 11C = 0.43016mV
> 12C = 0.46978mV
> 13C = 0.50947mV
> 14C = 0.54925mV
> 15C = 0.58911mV
> 16C = 0.62905mV
> 17C = 0.66908mV
> 18C = 0.70918mV
> 19C = 0.74936mV
> 20C = 0.78963mV
> 21C = 0.82997mV
> 22C = 0.87040mV
> 23C = 0.91091mV
> 24C = 0.95149mV
> 25C = 0.99216mV
> 26C = 1.03292mV
> 27C = 1.07375mV
> 28C = 1.11466mV
> 29C = 1.15566mV
> -6.258mV = 456.44C
> -6.094mV = 379.28C
> -5.930mV = 300.70C
> -5.766mV = 237.98C
> -5.602mV = 169.85C
> -5.438mV = 123.53C
> -5.274mV = 79.66C
> -5.110mV = 48.65C
> -4.946mV = 20.35C
> -4.782mV = -2.68C
> -4.618mV = -24.20C
> -4.454mV = -37.53C
> -4.290mV = -47.42C
> -4.126mV = -55.99C
> -3.962mV = -63.00C
> -3.798mV = -66.14C
> -3.634mV = -69.81C
> -3.470mV = -71.88C
> -3.306mV = -71.32C
> -3.142mV = -70.61C
> -2.978mV = -69.13C
> -2.814mV = -66.84C
> -2.650mV = -64.34C
> -2.486mV = -61.48C
> -2.322mV = -58.52C
> -2.158mV = -54.95C
> -1.994mV = -50.79C
> -1.830mV = -47.00C
> -1.666mV = -45.52C
> -1.502mV = -40.78C
> -1.338mV = -36.10C
> -1.174mV = -31.49C
> -1.010mV = -26.93C
> -0.846mV = -22.43C
> -0.682mV = -17.98C
> -0.518mV = -13.59C
> -0.354mV = -9.24C
> -0.190mV = -4.94C
> -0.026mV = -0.68C
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Owfs-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to