STM32 12-Bit ADC NTC Thermistor C99 Lookup Table Generator

Generate a zero-division C99 int16_t lookup table and shift-interpolator for STM32 12-bit ADCs (0–4095) with 3.3 V VDDA.

Jump to results

Inputs

Thermistor parameters
Divider & firmware LUT
Match R25 near your primary target temperature.

Results

Estimates
Resistance at 45 °C4.35 kΩ
Divider output voltage
1 V
Expected 12-bit ADC code
1,241 / 4,095
Voltage sensitivity
-27.2 mV/°C
Resolution at spot temp
0.03 °C/LSB
Self-heating power
0.23 mW
Firmware LUT entries
65 × int16_t (130 bytes)
NTC resistance & ADC divider voltage curve (−40 °C to 125 °C)
-40°C 0°C 25°C 60°C 100°C 125°C10^6Ω10^2ΩIndigo: log R(T) · Amber: V_adc(T)
Temperature vs. resistance & ADC curve
Temp (°C)NTC ResistanceV_adc (V)12-bit ADC
-40 °C401.86 kΩ3.223,996
-25 °C144.32 kΩ3.0863,830
-10 °C58.25 kΩ2.8163,495
0 °C33.62 kΩ2.5433,156
15 °C15.84 kΩ2.0232,510
25 °C10 kΩ1.652,048
40 °C5.3 kΩ1.1431,419
55 °C2.98 kΩ0.757940
70 °C1.76 kΩ0.494613
85 °C1.09 kΩ0.323401
100 °C697.52 Ω0.215267
125 °C358.83 Ω0.114142
Generated C99 firmware LUT & Python converter
#include <stdint.h>

/* OhmBitLab NTC LUT: R25=10000 ohm, B=3950 K, R_pullup=10000 ohm, ntc-low, 12-bit ADC */
#define NTC_LUT_SIZE 65U
#define NTC_ADC_SHIFT 6U
#define NTC_ADC_STEP (1U << NTC_ADC_SHIFT)

/* Temperature in tenths of deg C (e.g. 250 = 25.0 C) indexed by (adc >> NTC_ADC_SHIFT) */
static const int16_t ntc_temp_c_x10[NTC_LUT_SIZE] = {
   1500,  1607,  1293,  1127,  1016,   933,   866,   811,
    763,   722,   685,   651,   621,   593,   567,   542,
    520,   498,   477,   457,   439,   420,   403,   386,
    369,   353,   338,   323,   308,   293,   278,   264,
    250,   236,   222,   208,   194,   181,   167,   153,
    139,   125,   111,    97,    82,    68,    53,    37,
     22,     5,   -12,   -29,   -47,   -67,   -87,  -109,
   -132,  -158,  -186,  -219,  -257,  -303,  -365,  -462,
   -500
};

int16_t ntc_adc_to_c_x10(uint16_t adc) {
  uint16_t idx = adc >> NTC_ADC_SHIFT;
  if (idx >= NTC_LUT_SIZE - 1U) return ntc_temp_c_x10[NTC_LUT_SIZE - 1U];
  int32_t t0 = ntc_temp_c_x10[idx];
  int32_t t1 = ntc_temp_c_x10[idx + 1U];
  uint16_t frac = adc & (NTC_ADC_STEP - 1U);
  return (int16_t)(t0 + (((t1 - t0) * (int32_t)frac) >> NTC_ADC_SHIFT));
}
import math

R_PULLUP = 10000
ADC_MAX = 4095
TOPOLOGY = "ntc-low"
R25 = 10000
BETA = 3950

def adc_to_temp_c(adc: int) -> float:
    if adc <= 0 or adc >= ADC_MAX:
        raise ValueError("ADC reading saturated at rail")
    ratio = adc / ADC_MAX
    r_ntc = R_PULLUP * ratio / (1.0 - ratio) if TOPOLOGY == "ntc-low" else R_PULLUP * (1.0 - ratio) / ratio
    inv_t = (1.0 / 298.15) + math.log(r_ntc / R25) / BETA
    return (1.0 / inv_t) - 273.15

# Example spot check at 45 C -> ADC ~ 1241
print(f"{adc_to_temp_c(1241):.2f} C")

Choose a bias resistor near the NTC resistance at your most critical temperature to maximize mV/°C sensitivity and minimize quantization error.

Fast integer-only NTC decoding on STM32 Cortex-M microcontrollers

STM32F0, F1, G0 and F4 microcontrollers feature 12-bit SAR ADCs (0–4095) whose DMA channels can stream thermistor channels continuously into RAM. Evaluating logf() inside a timer ISR bloats flash on Cortex-M0 parts.

The generated 65-entry C99 table consumes only 130 bytes of flash and uses a single 6-bit right shift (`adc >> 6`) plus integer linear interpolation to return temperature in 0.1 °C increments.

Formulas

  • idx = adc >> 6 (step = 64 counts per LUT bin)
  • frac = adc & 63
  • T_x10 = T[idx] + (((T[idx+1] − T[idx]) × frac) >> 6)

Worked example

At 45 °C with a 10 kΩ B3950 NTC and 10 kΩ pull-up on STM32 3.3 V, R_ntc = 4.37 kΩ, V_adc = 1.003 V (ADC code 1,245), resolving 0.025 °C per LSB.

Frequently asked questions

What STM32 ADC sampling time should I configure for a 10 kΩ NTC divider?

The worst-case source impedance of a 10 kΩ pull-up divider is 5 kΩ at mid-scale and up to 10 kΩ when hot/cold; select at least 28.5–55.5 ADC clock cycles plus a 100 nF filter cap.

Can I connect the NTC pull-up to 3.3 V VDD if VDDA has a ferrite bead?

Always pull the NTC up to the filtered VDDA / VREF+ rail rather than noisy digital VDD so the measurement remains strictly ratiometric.

How much RAM does the generated C99 LUT use?

Zero RAM! Declared `static const int16_t`, the array lives entirely in flash (.rodata) and executes in deterministic O(1) time.