Skip to content

Added support for C type TCs. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mcc134.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion lib/mcc134.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
78 changes: 71 additions & 7 deletions lib/nist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math.h>
#include "nist.h"
Expand All @@ -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,
Expand All @@ -22,7 +24,8 @@ enum tcTypes
TC_TYPE_R,
TC_TYPE_S,
TC_TYPE_B,
TC_TYPE_N
TC_TYPE_N,
TC_TYPE_C
};


Expand Down Expand Up @@ -641,10 +644,66 @@ 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[] =
{
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 =
{
7, // nCoefficients
TypeCReverse
};


// ****************************************************************************

const Thermocouple_Data_type ThermocoupleData[8] =
const Thermocouple_Data_type ThermocoupleData[9] =
{
{
3, // nTables
Expand Down Expand Up @@ -685,6 +744,11 @@ const Thermocouple_Data_type ThermocoupleData[8] =
3, // nTables
&TypeNReverseTable, // Reverse Table
TypeNTables // Tables
},
{
2, // nTables
&TypeCReverseTable, // Reverse Table
TypeCTables // Tables
}
};

Expand All @@ -696,9 +760,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
Expand Down Expand Up @@ -740,9 +804,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
Expand Down