From b7a2d58b3172dc699dbbaa71c359f83858240ccc Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Wed, 13 Apr 2016 16:45:54 -0400 Subject: [PATCH] Restrict thermistor table range to 0C-500C We don't care about the accuracy of very cold temperatures or unreasonably hot ones. --- configtool/thermistortablefile.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/configtool/thermistortablefile.py b/configtool/thermistortablefile.py index 20d66e0..637c49f 100644 --- a/configtool/thermistortablefile.py +++ b/configtool/thermistortablefile.py @@ -106,6 +106,7 @@ def BetaTable(ofp, params, names, settings, finalTable): # It works like this: # # - Calculate all (1024) ideal values. + # - Keep only the ones in the interesting range (0..500C). # - Insert the two extremes into our sample list. # - Calculate the linear approximation of the remaining values. # - Insert the correct value for the "most-wrong" estimation into our @@ -115,11 +116,16 @@ def BetaTable(ofp, params, names, settings, finalTable): # Calculate actual temps for all ADC values. actual = dict([(x, thrm.temp(1.0 * x)) for x in range(1, int(hiadc + 1))]) - # Build a lookup table starting with the extremes. - lookup = dict([(x, actual[x]) for x in [1, int(hiadc)]]) + # Limit ADC range to 0C to 500C. + MIN_TEMP = 0 + MAX_TEMP = 500 + actual = dict([(adc, actual[adc]) for adc in actual + if actual[adc] <= MAX_TEMP and actual[adc] >= MIN_TEMP]) - A = 1 - B = int(hiadc) + # Build a lookup table starting with the extremes. + A = min(actual) + B = max(actual) + lookup = dict([(x, actual[x]) for x in [A,B]]) error = dict({}) while len(lookup) < N: error.update(dict([(x, abs(actual[x] - LinearTableEstimate(lookup, x)))