Thermocouple Calculator
NIST ITS-90 conversion for every standard type — both directions, with cold-junction compensation.
How the NIST polynomials work
Every standard thermocouple type is defined by ITS-90 reference functions: the EMF (referenced to a 0 °C cold junction) is a polynomial in millivolts:
with coefficients published by NIST per type and temperature segment. Type K adds an exponential correction term above 0 °C. The reverse direction uses separate inverse polynomials
valid only inside fixed EMF
windows and accurate to roughly ±0.05 K. Evaluate them with Horner's method — never
with naive pow() calls:
double poly(const double *c, int n, double x)
{
double y = c[n - 1];
for (int i = n - 2; i >= 0; i--)
y = y * x + c[i]; /* Horner: one mul + one add per term */
return y;
} Cold-junction compensation works in EMF space, not temperature space:
then convert to temperature. Adding temperatures directly is wrong because the curve is non-linear.
Fixed-point implementation on an MCU
On a Cortex-M0 or similar FPU-less core, double-precision polynomials are slow and pull in soft-float code. The pragmatic embedded approach is a lookup table in integer µV with linear interpolation — deterministic, fast, and accurate to the table pitch (10 °C steps keep the interpolation error well under 0.1 °C for type K):
/* Type K, 0…1370 °C in 10 °C steps, EMF in µV (NIST table values) */
static const int32_t k_uV[138] = { 0, 397, 798, 1203, 1612, /* … */ };
int32_t k_uV_to_dC(int32_t uV) /* returns 0.1 °C units */
{
int lo = 0, hi = 137;
while (hi - lo > 1) { /* binary search the segment */
int mid = (lo + hi) / 2;
if (k_uV[mid] <= uV) lo = mid; else hi = mid;
}
/* linear interpolation inside the 10 °C segment */
return lo * 100 + (int32_t)((int64_t)(uV - k_uV[lo]) * 100
/ (k_uV[lo + 1] - k_uV[lo]));
} Three details matter: keep the intermediate product in int64_t so it
cannot overflow, return scaled integers (0.1 °C) instead of floats, and apply CJC by
adding the cold-junction EMF (from a small second table around room temperature)
before the lookup. If you prefer pure fixed-point polynomials, scale the
coefficients to Q16.16 and evaluate with Horner using 64-bit accumulators.