Browse Source

createTemperatureLookupMarlin.py: Add resolution comments and format for Marlin.

David Forrest 11 years ago
parent
commit
7216583b8b
1 changed files with 23 additions and 7 deletions
  1. 23
    7
      Marlin/createTemperatureLookupMarlin.py

+ 23
- 7
Marlin/createTemperatureLookupMarlin.py View File

@@ -54,9 +54,25 @@ class Thermistor:
54 54
         self.c2 = c2
55 55
         self.c3 = c3
56 56
 
57
+    def res(self,adc):
58
+        "Convert ADC reading into a resolution"
59
+        res = self.temp(adc)-self.temp(adc+1)
60
+        return res
61
+
62
+    def v(self,adc):
63
+        "Convert ADC reading into a Voltage"
64
+        v = adc * self.vadc / (1024 )   # convert the 10 bit ADC value to a voltage
65
+        return v
66
+
67
+    def r(self,adc):
68
+        "Convert ADC reading into a resistance in Ohms"
69
+        v = adc * self.vadc / (1024 )   # convert the 10 bit ADC value to a voltage
70
+        r = self.rp * v / (self.vcc - v)    # resistance of thermistor
71
+        return r
72
+
57 73
     def temp(self,adc):
58 74
         "Convert ADC reading into a temperature in Celcius"
59
-        v = adc * self.vadc / (1024 * 16)   # convert the 10 bit ADC value to a voltage
75
+        v = adc * self.vadc / (1024 )   # convert the 10 bit ADC value to a voltage
60 76
         r = self.rp * v / (self.vcc - v)    # resistance of thermistor
61 77
         lnr = log(r)
62 78
         Tinv = self.c1 + (self.c2*lnr) + (self.c3*pow(lnr,3))
@@ -67,7 +83,7 @@ class Thermistor:
67 83
         y = (self.c1 - (1/(temp+273.15))) / (2*self.c3)
68 84
 	x = sqrt(pow(self.c2 / (3*self.c3),3) + pow(y,2))
69 85
         r = exp(pow(x-y,1.0/3) - pow(x+y,1.0/3)) # resistance of thermistor
70
-        return (r / (self.rp + r)) * (1024*16)
86
+        return (r / (self.rp + r)) * (1024)
71 87
 
72 88
 def main(argv):
73 89
 
@@ -107,7 +123,7 @@ def main(argv):
107 123
         elif opt == "--num-temps":
108 124
             num_temps =  int(arg)
109 125
 
110
-    max_adc = (1024 * 16) - 1
126
+    max_adc = (1024 ) - 1
111 127
     min_temp = 0
112 128
     max_temp = 350
113 129
     increment = int(max_adc/(num_temps-1));
@@ -119,16 +135,16 @@ def main(argv):
119 135
 
120 136
     print "// Thermistor lookup table for Marlin"
121 137
     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)
122
-    print "#define NUMTEMPS %s" % (len(temps))
123
-    print "short temptable[NUMTEMPS][2] = {"
138
+    print "//#define NUMTEMPS %s" % (len(temps))
139
+    print "const short temptable[NUMTEMPS][2] PROGMEM = {"
124 140
 
125 141
     counter = 0
126 142
     for temp in temps:
127 143
         counter = counter +1
128 144
         if counter == len(temps):
129
-            print "   {%s, %s}" % (int(t.adc(temp)), temp)
145
+            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)))
130 146
         else:
131
-            print "   {%s, %s}," % (int(t.adc(temp)), temp)
147
+            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)))
132 148
     print "};"
133 149
     
134 150
 def usage():

Loading…
Cancel
Save