From 7216583b8be5617ecde6aaee4d209f6510baebed Mon Sep 17 00:00:00 2001 From: David Forrest Date: Thu, 16 Jan 2014 12:40:15 -0500 Subject: [PATCH 1/4] createTemperatureLookupMarlin.py: Add resolution comments and format for Marlin. --- Marlin/createTemperatureLookupMarlin.py | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Marlin/createTemperatureLookupMarlin.py b/Marlin/createTemperatureLookupMarlin.py index e09294e4b..592dae53d 100644 --- a/Marlin/createTemperatureLookupMarlin.py +++ b/Marlin/createTemperatureLookupMarlin.py @@ -54,9 +54,25 @@ class Thermistor: self.c2 = c2 self.c3 = c3 + def res(self,adc): + "Convert ADC reading into a resolution" + res = self.temp(adc)-self.temp(adc+1) + return res + + def v(self,adc): + "Convert ADC reading into a Voltage" + v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage + return v + + def r(self,adc): + "Convert ADC reading into a resistance in Ohms" + v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage + r = self.rp * v / (self.vcc - v) # resistance of thermistor + return r + def temp(self,adc): "Convert ADC reading into a temperature in Celcius" - v = adc * self.vadc / (1024 * 16) # convert the 10 bit ADC value to a voltage + v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage r = self.rp * v / (self.vcc - v) # resistance of thermistor lnr = log(r) Tinv = self.c1 + (self.c2*lnr) + (self.c3*pow(lnr,3)) @@ -67,7 +83,7 @@ class Thermistor: y = (self.c1 - (1/(temp+273.15))) / (2*self.c3) x = sqrt(pow(self.c2 / (3*self.c3),3) + pow(y,2)) r = exp(pow(x-y,1.0/3) - pow(x+y,1.0/3)) # resistance of thermistor - return (r / (self.rp + r)) * (1024*16) + return (r / (self.rp + r)) * (1024) def main(argv): @@ -107,7 +123,7 @@ def main(argv): elif opt == "--num-temps": num_temps = int(arg) - max_adc = (1024 * 16) - 1 + max_adc = (1024 ) - 1 min_temp = 0 max_temp = 350 increment = int(max_adc/(num_temps-1)); @@ -119,16 +135,16 @@ def main(argv): print "// Thermistor lookup table for Marlin" print "// ./createTemperatureLookup.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) - print "#define NUMTEMPS %s" % (len(temps)) - print "short temptable[NUMTEMPS][2] = {" + print "//#define NUMTEMPS %s" % (len(temps)) + print "const short temptable[NUMTEMPS][2] PROGMEM = {" counter = 0 for temp in temps: counter = counter +1 if counter == len(temps): - print " {%s, %s}" % (int(t.adc(temp)), temp) + print " {%s*OVERSAMPLENR, %s} // v=%s r=%s res=%s C/count" % (int(t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) else: - print " {%s, %s}," % (int(t.adc(temp)), temp) + print " {%s*OVERSAMPLENR, %s}, // v=%s r=%s res=%s C/count" % (int(t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) print "};" def usage(): From f5b5dd8038c806efadc24de6ed85bbcd189f2e0b Mon Sep 17 00:00:00 2001 From: David Forrest Date: Wed, 29 Jan 2014 22:45:10 -0500 Subject: [PATCH 2/4] createTemperatureLookupMarlin.py: Add output of Steinhart-Hart coefficients. --- Marlin/createTemperatureLookupMarlin.py | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 Marlin/createTemperatureLookupMarlin.py diff --git a/Marlin/createTemperatureLookupMarlin.py b/Marlin/createTemperatureLookupMarlin.py old mode 100644 new mode 100755 index 592dae53d..bf24dc652 --- a/Marlin/createTemperatureLookupMarlin.py +++ b/Marlin/createTemperatureLookupMarlin.py @@ -135,6 +135,7 @@ def main(argv): print "// Thermistor lookup table for Marlin" print "// ./createTemperatureLookup.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) + print "// Steinhart-Hart Coefficients: %.15g, %.15g, %.15g " % (t.c1, t.c2, t.c3) print "//#define NUMTEMPS %s" % (len(temps)) print "const short temptable[NUMTEMPS][2] PROGMEM = {" From 50f44d92490b1a39d471a01333a2a12e90023eda Mon Sep 17 00:00:00 2001 From: David Forrest Date: Wed, 29 Jan 2014 23:23:18 -0500 Subject: [PATCH 3/4] createTemperatureLookupMarlin.py: Truncate to short after application of OVERSAMPLENR for improved resolution. --- Marlin/createTemperatureLookupMarlin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/createTemperatureLookupMarlin.py b/Marlin/createTemperatureLookupMarlin.py index bf24dc652..d19430b82 100755 --- a/Marlin/createTemperatureLookupMarlin.py +++ b/Marlin/createTemperatureLookupMarlin.py @@ -143,9 +143,9 @@ def main(argv): for temp in temps: counter = counter +1 if counter == len(temps): - print " {%s*OVERSAMPLENR, %s} // v=%s r=%s res=%s C/count" % (int(t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) + print " {(short)(%.2f*OVERSAMPLENR), %s} // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) else: - print " {%s*OVERSAMPLENR, %s}, // v=%s r=%s res=%s C/count" % (int(t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) + print " {(short)(%.2f*OVERSAMPLENR), %s}, // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) print "};" def usage(): From f0b8d5ba3d25328f79eb5b3830f64771eb90e23a Mon Sep 17 00:00:00 2001 From: David Forrest Date: Wed, 29 Jan 2014 23:34:22 -0500 Subject: [PATCH 4/4] createTemperatureLookupMarlin.py: Change comment to refer to actual program name. --- Marlin/createTemperatureLookupMarlin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/createTemperatureLookupMarlin.py b/Marlin/createTemperatureLookupMarlin.py index d19430b82..77187b809 100755 --- a/Marlin/createTemperatureLookupMarlin.py +++ b/Marlin/createTemperatureLookupMarlin.py @@ -134,7 +134,7 @@ def main(argv): temps = range(max_temp, min_temp + tmp, tmp); print "// Thermistor lookup table for Marlin" - print "// ./createTemperatureLookup.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) + print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) print "// Steinhart-Hart Coefficients: %.15g, %.15g, %.15g " % (t.c1, t.c2, t.c3) print "//#define NUMTEMPS %s" % (len(temps)) print "const short temptable[NUMTEMPS][2] PROGMEM = {"