aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--klippy/heater.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/klippy/heater.py b/klippy/heater.py
index d8021332..cac8f984 100644
--- a/klippy/heater.py
+++ b/klippy/heater.py
@@ -17,7 +17,8 @@ KELVIN_TO_CELCIUS = -273.15
class Thermistor:
def __init__(self, config, params):
self.pullup = config.getfloat('pullup_resistor', 4700., above=0.)
- # Calculate Steinhart-Hart coefficents from temp measurements
+ # Calculate Steinhart-Hart coefficents from temp measurements.
+ # Arrange samples as 3 linear equations and solve for c1, c2, and c3.
inv_t1 = 1. / (params['t1'] - KELVIN_TO_CELCIUS)
inv_t2 = 1. / (params['t2'] - KELVIN_TO_CELCIUS)
inv_t3 = 1. / (params['t3'] - KELVIN_TO_CELCIUS)
@@ -43,6 +44,7 @@ class Thermistor:
def calc_adc(self, temp):
inv_t = 1. / (temp - KELVIN_TO_CELCIUS)
if self.c3:
+ # Solve for ln_r using Cardano's formula
y = (self.c1 - inv_t) / (2. * self.c3)
x = math.sqrt((self.c2 / (3. * self.c3))**3 + y**2)
ln_r = math.pow(x - y, 1./3.) - math.pow(x + y, 1./3.)