main
John Lauer
Bind output-locked temperature diagnostics to selected NTCLE428 sensor
d2b6d40
/* NTCLE428E3103H301A nominal diagnostic curve, Vishay29186 table5,
* revision28-Apr-2026. Log-resistance interpolation, no extrapolation.
* Not calibrated; attachment, tolerance and thermal lag remain unqualified.
* Original implementation: MIT. */
#include "ntcle428.h"
#include <stdbool.h>
#include <math.h>
#include <stddef.h>
static const float temp_c[] = {-40.0f,-35.0f,-30.0f,-25.0f,-20.0f,-15.0f,-10.0f,-5.0f,0.0f,5.0f,10.0f,15.0f,20.0f,25.0f,30.0f,35.0f,40.0f,45.0f,50.0f,55.0f,60.0f,65.0f,70.0f,75.0f,80.0f,85.0f,90.0f,95.0f,100.0f,105.0f};
static const float ohms[] = {334274.00f,241323.00f,176133.00f,129900.00f,96761.00f,72765.00f,55218.00f,42268.00f,32624.00f,25381.00f,19897.00f,15711.00f,12493.00f,10000.00f,8056.00f,6529.70f,5323.90f,4365.30f,3598.70f,2982.30f,2483.80f,2078.70f,1747.70f,1475.90f,1251.80f,1066.10f,911.59f,782.46f,674.11f,582.84f};
bool load_ntcle428_nominal_c(float resistance, float *temperature) {
if (!temperature || !isfinite(resistance) || resistance > ohms[0] || resistance < ohms[29]) return false;
for (size_t i=0;i<29;i++) {
if (resistance <= ohms[i] && resistance >= ohms[i+1]) {
float fraction=logf(ohms[i]/resistance)/logf(ohms[i]/ohms[i+1]);
float result=temp_c[i]+fraction*(temp_c[i+1]-temp_c[i]);
if (!isfinite(result)) return false;
*temperature=result; return true;
}
}
return false;
}