はっくはっくキッチン
Hack Hack Kitchen

Library for Thermocouple based on NIST ITS-90 Database

 2022/01/29

Introduction

The National Institute of Standards and Technology (NIST) has published the data of several thermocouples as NIST ITS-90 Thermocouple Database.

The data consists of three parts for each thermocouple:

  1. table of the thermoelectromotive forces with respect to 0 degree Celsius for each 1 degree Celsius of temperature difference

  2. (coefficients for) approximate formula for conversion from temperature to thermoelectromotive force

  3. (coefficients for) approximate formula for conversion from thermoelectromotive force to temperature

This library provides functions based on 2. and 3. above. This allows mutual conversion between the emf (electromotive force) of the thermocouple and temperature with respect to $0\,\degree\mathrm{C}$.

Functions

The following functions are provided in this library. Replace X in the function name with the thermocouple types (B, E, …).

FLOAT temp2emf_X(FLOAT temperature)

Calculates the emf from the given temperature. It returns NAN (not a number) if the specified temperature is out of range,

FLOAT emf2temp_X(FLOAT emf)

Calculates the temperature from the given emf (with respect to $0\,\degree\mathrm{C}$). It returns NAN (not a number) if emf is out of range,

Type

The FLOAT type is defined as double if NIST_ITS90_USE_DOUBLE is defined at compile time, otherwise it is defined as float.

Units

The unit for temperature is $\degree\mathrm{C}$, and the unit for emf is mV.

How to use

First, retrieve the files from the repository.

git clone https://github.com/TPKato/nist-its90

The minimum file requirements are as follows:

  • nist-its90.c

  • nist-its90-X.c (X should be replaced by the thermocouple type (B, E, …))

  • nist-its90.h

  • nist-its90-config.h

If you use this library with your C source code(s):

  1. Edit nist-its90-config.h as necessary.

  2. Add following lines in your code:

    #include <math.h>	/* Only for type K (which requires exp()) */
    #include "nist-its90.h"
  3. The compilation procedure is as follows:

    gcc -c nist-its90.c
    gcc -c nist-its90-K.c
    gcc -o [execfile] [your source].c nist-its90.o nist-its90-K.o -lm

For Arduino, the procedure is almost the same.

  1. Copy the necessary files to the project directory.

  2. Edit nist-its90-config.h if necessary.

  3. Add the following line to the .ino file.

    #include "nist-its90.h"

Example

To calculate the measuring junction temperature t from the obtained the electromotive force emf and the cold junction temperature t_amb in the measurement using the K-type thermocouple:

t = emf2temp_K(emf + temp2emf_K(t_amb));

Files

This library consists of the following files.

Makefile

This file is used to generate nist-its90-*.c and nist-its90.h from the NIST database.

nistcoeff.pl

A Script to generate nist-its90-*.c and nist-its90.h from the NIST database

nist-test.pl

Test of generated programs

nist-its90.c

Compute polynomials (using the Horner method)

The following are the files generated by nistcoeff.pl. These files can be generated using the above files, but you usually do not need to generate them by yourself, since they are included in the repository.

  • nist-its90-B.c

  • nist-its90-E.c

  • nist-its90-J.c

  • nist-its90-K.c

  • nist-its90-N.c

  • nist-its90-R.c

  • nist-its90-S.c

  • nist-its90-T.c

  • nist-its90.h

How to make

Follow the steps below if you want to make these files by yourself.

Since the database file of NIST is not included in this repository, you need to download All Thermocouple Types from the Download Tables page of NIST ITS-90 Thermocouple Database.

Then, run:

make
make test

(make test is optional).

See also

See Correcting Temperature Data of MAX31855 for information on how to use this library with MAX31855 (Cold-Junction Compensated Thermocouple-to-Digital Converter by Maxim Integrated).

License

  • MIT License