From c3ad1606457e2a2048cc9619687d49ff032e6740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ovidio=20Y=2E=20Pe=C3=B1a=20Rodr=C3=ADguez?= Date: Fri, 14 Jun 2024 10:11:27 +0200 Subject: [PATCH 1/2] Added support for C type TCs. --- include/mcc134.h | 2 ++ lib/mcc134.c | 2 +- lib/nist.c | 77 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/include/mcc134.h b/include/mcc134.h index df0852f..abb7baf 100644 --- a/include/mcc134.h +++ b/include/mcc134.h @@ -49,6 +49,8 @@ enum TcTypes TC_TYPE_B = 6, /// N type TC_TYPE_N = 7, + /// C type + TC_TYPE_C = 8, /// Input disabled TC_DISABLED = 0xFF }; diff --git a/lib/mcc134.c b/lib/mcc134.c index 205bfda..8883ebe 100644 --- a/lib/mcc134.c +++ b/lib/mcc134.c @@ -972,7 +972,7 @@ int mcc134_tc_type_write(uint8_t address, uint8_t channel, uint8_t type) if (!_check_addr(address) || (channel >= NUM_TC_CHANNELS) || - ((type > TC_TYPE_N) && (type != TC_DISABLED))) + ((type > TC_TYPE_C) && (type != TC_DISABLED))) { return RESULT_BAD_PARAMETER; } diff --git a/lib/nist.c b/lib/nist.c index da89996..02c24c1 100644 --- a/lib/nist.c +++ b/lib/nist.c @@ -4,6 +4,8 @@ * brief This file contains NIST thermocouple linearization functions. * * date 1 Feb 2018 +* +* 14 Jun 2024 Added C Type TC (Ovidio Y. Pena Rodriguez) */ #include #include "nist.h" @@ -12,7 +14,7 @@ // // The following types are supported: // -// J, K, R, S, T, N, E, B +// J, K, R, S, T, N, E, B, C enum tcTypes { TC_TYPE_J = 0, @@ -22,7 +24,8 @@ enum tcTypes TC_TYPE_R, TC_TYPE_S, TC_TYPE_B, - TC_TYPE_N + TC_TYPE_N, + TC_TYPE_C }; @@ -641,10 +644,65 @@ const NIST_Reverse_type TypeBReverseTable = TypeBReverse }; +// **************************************************************************** +// Type C data + +const double TypeCTable0[] = +{ + 0.0000000E+00, + 7.4411468E+01, + -4.5680255E+00, + 6.0972079E-01, + -5.5888380E-02, + 2.9645590E-03, + -6.5745000E-05 +}; + +const double TypeCTable1[] = +{ + 4.1102500E+02, + -6.1463789E+01, + 1.4651879E+01, + -9.9683382E-01, + 3.7141869E-02, + -7.0836000E-04, + 5.5012700E-06 +}; + +const NIST_Table_type TypeCTables[] = +{ + { + 7, + 0.0, + TypeCTable0 + }, + { + 7, + 11.3, + TypeCTable1 + } +}; + +const double TypeCReverse[] = +{ + -2.344710E-01, + 7.190027E-03, + 3.956443E-06, + -1.842722E-09, + 3.471851E-13, + -2.616792E-17 +}; + +const NIST_Reverse_type TypeCReverseTable = +{ + 6, // nCoefficients + TypeCReverse +}; + // **************************************************************************** -const Thermocouple_Data_type ThermocoupleData[8] = +const Thermocouple_Data_type ThermocoupleData[9] = { { 3, // nTables @@ -685,6 +743,11 @@ const Thermocouple_Data_type ThermocoupleData[8] = 3, // nTables &TypeNReverseTable, // Reverse Table TypeNTables // Tables + }, + { + 2, // nTables + &TypeCReverseTable, // Reverse Table + TypeCTables // Tables } }; @@ -696,9 +759,9 @@ double NISTCalcVoltage(unsigned int type, double temp) double fTemp; double fExtra = 0.0; - if (type > TC_TYPE_N) + if (type > TC_TYPE_C) { - type = TC_TYPE_N; + type = TC_TYPE_C; } // select appropriate NIST table data @@ -740,9 +803,9 @@ double NISTCalcTemperature(unsigned int type, double voltage) double fVoltage; double fResult; - if (type > TC_TYPE_N) + if (type > TC_TYPE_C) { - type = TC_TYPE_N; + type = TC_TYPE_C; } // determine which temp range table to use with the threshold V From b86bcea9ed67c30f80cf0b79d76b9b21a0ae7ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ovidio=20Y=2E=20Pe=C3=B1a=20Rodr=C3=ADguez?= Date: Fri, 21 Jun 2024 16:37:56 +0200 Subject: [PATCH 2/2] Updated the inverse polynomial for type C thermocouples. --- lib/nist.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/nist.c b/lib/nist.c index 02c24c1..46cbe91 100644 --- a/lib/nist.c +++ b/lib/nist.c @@ -685,17 +685,18 @@ const NIST_Table_type TypeCTables[] = const double TypeCReverse[] = { - -2.344710E-01, - 7.190027E-03, - 3.956443E-06, - -1.842722E-09, - 3.471851E-13, - -2.616792E-17 + 0.00000E00, + 1.33300E-02, + 1.25261E-05, + -1.08382E-08, + 3.70800E-12, + -4.64562E-16, + -1.35135E-20 }; const NIST_Reverse_type TypeCReverseTable = { - 6, // nCoefficients + 7, // nCoefficients TypeCReverse };