Browse Source

cosmetic whitespace cleanup and comments added/updated

Steffen Vogel 10 years ago
parent
commit
538231edfd
1 changed files with 22 additions and 25 deletions
  1. 22
    25
      Marlin/scripts/createTemperatureLookupMarlin.py

+ 22
- 25
Marlin/scripts/createTemperatureLookupMarlin.py View File

1
 #!/usr/bin/python
1
 #!/usr/bin/python
2
-#
3
-# Creates a C code lookup table for doing ADC to temperature conversion
4
-# on a microcontroller
5
-# based on: http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
6
 """Thermistor Value Lookup Table Generator
2
 """Thermistor Value Lookup Table Generator
7
 
3
 
8
 Generates lookup to temperature values for use in a microcontroller in C format based on: 
4
 Generates lookup to temperature values for use in a microcontroller in C format based on: 
9
-http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
5
+http://en.wikipedia.org/wiki/Steinhart-Hart_equation
10
 
6
 
11
 The main use is for Arduino programs that read data from the circuit board described here:
7
 The main use is for Arduino programs that read data from the circuit board described here:
12
 http://make.rrrf.org/ts-1.0
8
 http://make.rrrf.org/ts-1.0
19
   --t1=ttt:rrr      low temperature temperature:resistance point (around 25C)
15
   --t1=ttt:rrr      low temperature temperature:resistance point (around 25C)
20
   --t2=ttt:rrr      middle temperature temperature:resistance point (around 150C)
16
   --t2=ttt:rrr      middle temperature temperature:resistance point (around 150C)
21
   --t3=ttt:rrr      high temperature temperature:resistance point (around 250C)
17
   --t3=ttt:rrr      high temperature temperature:resistance point (around 250C)
22
-  --num-temps=...   the number of temperature points to calculate (default: 20)
18
+  --num-temps=...   the number of temperature points to calculate (default: 36)
23
 """
19
 """
24
 
20
 
25
 from math import *
21
 from math import *
86
         return (r / (self.rp + r)) * (1024)
82
         return (r / (self.rp + r)) * (1024)
87
 
83
 
88
 def main(argv):
84
 def main(argv):
89
-
85
+    "Default values"
90
-    rp = 4700;
86
+    t1 = 25                                 # low temperature in Kelvin (25 degC)
91
-    t1 = 25;
87
+    r1 = 100000                             # resistance at low temperature (10 kOhm)
92
-    r1 = 100000;
88
+    t2 = 150                                # middle temperature in Kelvin (150 degC)
93
-    t2 = 150;
89
+    r2 = 1641.9                             # resistance at middle temperature (1.6 KOhm)
94
-    r2 = 1641.9;
90
+    t3 = 250                                # high temperature in Kelvin (250 degC)
95
-    t3 = 250;
91
+    r3 = 226.15                             # resistance at high temperature (226.15 Ohm)
96
-    r3 = 226.15;
92
+    rp = 4700;                              # pull-up resistor (4.7 kOhm)
97
-    num_temps = int(36);
93
+    num_temps = int(36);                    # number of entries for look-up table
98
     
94
     
99
     try:
95
     try:
100
         opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
96
         opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
102
         print  str(err)
98
         print  str(err)
103
         usage()
99
         usage()
104
         sys.exit(2)
100
         sys.exit(2)
105
-        
101
+
106
     for opt, arg in opts:
102
     for opt, arg in opts:
107
         if opt in ("-h", "--help"):
103
         if opt in ("-h", "--help"):
108
             usage()
104
             usage()
111
             rp = int(arg)
107
             rp = int(arg)
112
         elif opt == "--t1":
108
         elif opt == "--t1":
113
             arg =  arg.split(':')
109
             arg =  arg.split(':')
114
-            t1 = float( arg[0])
110
+            t1 = float(arg[0])
115
-            r1 = float( arg[1])
111
+            r1 = float(arg[1])
116
         elif opt == "--t2":
112
         elif opt == "--t2":
117
             arg =  arg.split(':')
113
             arg =  arg.split(':')
118
-            t2 = float( arg[0])
114
+            t2 = float(arg[0])
119
-            r2 = float( arg[1])
115
+            r2 = float(arg[1])
120
         elif opt == "--t3":
116
         elif opt == "--t3":
121
             arg =  arg.split(':')
117
             arg =  arg.split(':')
122
-            t3 = float( arg[0])
118
+            t3 = float(arg[0])
123
-            r3 = float( arg[1])
119
+            r3 = float(arg[1])
124
         elif opt == "--num-temps":
120
         elif opt == "--num-temps":
125
             num_temps =  int(arg)
121
             num_temps =  int(arg)
126
 
122
 
136
 
132
 
137
     print "// Thermistor lookup table for Marlin"
133
     print "// Thermistor lookup table for Marlin"
138
     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)
134
     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)
139
-    print "// Steinhart-Hart Coefficients: %.15g, %.15g,  %.15g " % (t.c1, t.c2, t.c3)
135
+    print "// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3)
140
-    print "//#define NUMTEMPS %s" % (len(temps))
136
+    print
137
+    print "#define NUMTEMPS %s" % (len(temps))
141
     print "const short temptable[NUMTEMPS][2] PROGMEM = {"
138
     print "const short temptable[NUMTEMPS][2] PROGMEM = {"
142
 
139
 
143
     counter = 0
140
     counter = 0
148
         else:
145
         else:
149
             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)))
146
             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)))
150
     print "};"
147
     print "};"
151
-    
148
+
152
 def usage():
149
 def usage():
153
     print __doc__
150
     print __doc__
154
 
151
 

Loading…
Cancel
Save