main
John Lauer
Review off-board sensor and mechanical libraries with truthful conversion and supplier limits
4c1d6f7
#!/usr/bin/env python3
"""Nominal curve compatibility only; never a sensor/assembly qualification."""
import json,math,hashlib
from pathlib import Path
R=Path(__file__).resolve().parents[1]
def old_curve(r):
l=math.log(r/10000);return 1/(.003354016+.000256985*l+.000002620131*l*l+.00000006383091*l*l*l)-273.15
def interp_temp(rows,r,col=1):
for a,b in zip(rows,rows[1:]):
if a[col]>=r>=b[col]:
return a[0]+(b[0]-a[0])*(math.log(a[col])-math.log(r))/(math.log(a[col])-math.log(b[col]))
raise ValueError('Resistance outside supplied table segment')
def main():
source=R/'design/sensor-candidate.json';d=json.loads(source.read_text());rows=d['rows']
comparison=[dict(actualC=t,nominalOhms=r,legacyCurveC=old_curve(r),nominalErrorC=old_curve(r)-t,legacyReadingAtMinOhmsC=old_curve(lo),legacyReadingAtMaxOhmsC=old_curve(hi))for t,r,lo,hi in rows]
v=2.5*3300/(10000+3300);threshold=10000*v/(3.3-v)
out=dict(status='candidate-screen-not-adopted',candidate=d['candidate'],inputSha256=hashlib.sha256(source.read_bytes()).hexdigest(),comparison=comparison,maxAbsoluteNominalErrorC=max(abs(v['nominalErrorC']) for v in comparison),
nominalHardwareComparator=dict(referenceV=v,tripResistanceOhms=threshold,interpolatedNominalTripC=interp_temp(rows,threshold),interpolatedLowResistanceTripC=interp_temp(rows,threshold,2),interpolatedHighResistanceTripC=interp_temp(rows,threshold,3)),
nominalSelfHeatingAt55C=dict(dissipatedMilliwatts=1000*3.3**2*2982.3/(10000+2982.3)**2,assumedDissipationMilliwattsPerK=3),
limits=['Comparison at all 30 manufacturer table nodes does not bound interpolation error or validate legacy firmware with the new sensor.','Comparator values exclude resistor/reference/supply/comparator tolerances; trip range is sensor resistance tolerance only.','Bond-line resistance, thermal lag, case-to-sensor gradient and self-heating need assembly calibration.','Candidate has not changed the formal board, spec, BOM or firmware. No physical measurement.'])
out['nominalSelfHeatingAt55C']['estimatedRiseC']=out['nominalSelfHeatingAt55C']['dissipatedMilliwatts']/3
p=R/'mechanical/sensor-candidate-screen.json';p.write_text(json.dumps(out,indent=2)+'\n');print(json.dumps(out,indent=2))
if __name__=='__main__':main()