diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-05-29 11:11:07 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-06-02 10:59:23 -0400 |
commit | 3e1c42da801fb87c01369cb95f4cbd7766abb948 (patch) | |
tree | e0938fbef1b53a79cfba5b4d9b00608b2a75b4c9 /klippy/extras/thermistor.py | |
parent | e2e4a5d4e6baa4008a7b2caabd48edbfe4df4685 (diff) | |
download | kutter-3e1c42da801fb87c01369cb95f4cbd7766abb948.tar.gz kutter-3e1c42da801fb87c01369cb95f4cbd7766abb948.tar.xz kutter-3e1c42da801fb87c01369cb95f4cbd7766abb948.zip |
thermistor: Add support for printers with an "inline_resistor"
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/thermistor.py')
-rw-r--r-- | klippy/extras/thermistor.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/klippy/extras/thermistor.py b/klippy/extras/thermistor.py index 7a1ca534..e805a70b 100644 --- a/klippy/extras/thermistor.py +++ b/klippy/extras/thermistor.py @@ -10,8 +10,9 @@ KELVIN_TO_CELCIUS = -273.15 # Analog voltage to temperature converter for thermistors class Thermistor: - def __init__(self, pullup): + def __init__(self, pullup, inline_resistor): self.pullup = pullup + self.inline_resistor = inline_resistor self.c1 = self.c2 = self.c3 = 0. def setup_coefficients(self, t1, r1, t2, r2, t3, r3, name=""): # Calculate Steinhart-Hart coefficents from temp measurements. @@ -48,7 +49,7 @@ class Thermistor: # Calculate temperature from adc adc = max(.00001, min(.99999, adc)) r = self.pullup * adc / (1.0 - adc) - ln_r = math.log(r) + ln_r = math.log(r - self.inline_resistor) inv_t = self.c1 + self.c2 * ln_r + self.c3 * ln_r**3 return 1.0/inv_t + KELVIN_TO_CELCIUS def calc_adc(self, temp): @@ -63,13 +64,14 @@ class Thermistor: ln_r = math.pow(x - y, 1./3.) - math.pow(x + y, 1./3.) else: ln_r = (inv_t - self.c1) / self.c2 - r = math.exp(ln_r) + r = math.exp(ln_r) + self.inline_resistor return r / (self.pullup + r) # Create an ADC converter with a thermistor def PrinterThermistor(config, params): pullup = config.getfloat('pullup_resistor', 4700., above=0.) - thermistor = Thermistor(pullup) + inline_resistor = config.getfloat('inline_resistor', 0., minval=0.) + thermistor = Thermistor(pullup, inline_resistor) if 'beta' in params: thermistor.setup_coefficients_beta( params['t1'], params['r1'], params['beta']) |