21static void check(
bool ok,
const std::string& what) {
22 std::cout << (
ok ?
" ok " :
" FAIL ") << what << std::endl;
34 return static_cast<int32_t
>(std::llround(
volts /
kRef * 2147483648.0));
37static double read(int32_t code) {
42 std::cout <<
"=== ESP32 RTD board ===" << std::endl;
45 for (
double t : {-196.0, -183.0, -150.0, -100.0, -40.0, 0.0, 25.0, 100.0, 300.0})
46 all_ok = all_ok && std::fabs(
read(
code_at(t)) - t) < 0.01;
47 check(all_ok,
"reads the element's temperature from -196 C to 300 C within 0.01 C");
54 "the old quadratic-only inverse read LOX about 1.8 C cold");
55 check(std::fabs(
read(
code_at(-183.0)) - -183.0) < 0.01,
"the board now reads it at -183 C");
57 for (
double t : {0.5, 25.0, 300.0}) {
58 const int32_t code =
code_at(t);
59 const double ohms = code / 2147483648.0 *
kRef * 1e6 /
kUa;
62 check(same,
"above 0 C the reading is unchanged (the quadratic is exact there)");
65 check(std::isnan(
read(2147483647)) && std::isnan(
read(2147000000)),
66 "a saturated ADC (open element, ~395 C on the curve) is no reading");
68 "a shorted element (~0 ohm, below -200 C) is no reading");
70 "no excitation configured is no reading");
72 "above the standard's 850 C is no reading");
double resistance_to_temp_cvd(double resistance_ohms, const CVDCoeffs &cvd=CVDCoeffs{})
Convert resistance (Ω) to temperature (°C) using iterative CVD inverse.
double temp_to_resistance_cvd(double t_c, const CVDCoeffs &cvd=CVDCoeffs{})
Resistance (Ω) at temperature (°C), IEC 60751 Callendar-Van Dusen, the C term below 0 °C.
double rtd_board_adc_to_temp_c(int32_t adc_raw, double adc_ref_voltage, double excitation_ua, double r0_ohms)
An ESP32 RTD board's reading -> °C: the ADC code (2^31 = adc_ref_voltage) is the voltage across the e...
double resistance_to_temp_cvd_full(double resistance_ohms, const CVDCoeffs &cvd=CVDCoeffs{})
The full CVD inverse: exact above 0 °C (the quadratic), Newton on the C term below it.
static double volts(uint32_t code)
Shunt volts for a code, as calibration_main's convert_hp_pt_to_pressure computes it.
static int32_t code_at(double t_c)
The ADC code the board reports for an element at t_c.
static void check(bool ok, const std::string &what)
static double read(int32_t code)