|
@@ -12,9 +12,9 @@ Usage: python createTemperatureLookup.py [options]
|
12
|
12
|
Options:
|
13
|
13
|
-h, --help show this help
|
14
|
14
|
--rp=... pull-up resistor
|
15
|
|
- --t1=ttt:rrr low temperature temperature:resistance point (around 25C)
|
16
|
|
- --t2=ttt:rrr middle temperature temperature:resistance point (around 150C)
|
17
|
|
- --t3=ttt:rrr high temperature temperature:resistance point (around 250C)
|
|
15
|
+ --t1=ttt:rrr low temperature temperature:resistance point (around 25 degC)
|
|
16
|
+ --t2=ttt:rrr middle temperature temperature:resistance point (around 150 degC)
|
|
17
|
+ --t3=ttt:rrr high temperature temperature:resistance point (around 250 degC)
|
18
|
18
|
--num-temps=... the number of temperature points to calculate (default: 36)
|
19
|
19
|
"""
|
20
|
20
|
|
|
@@ -50,25 +50,24 @@ class Thermistor:
|
50
|
50
|
self.c3 = c
|
51
|
51
|
self.rp = rp # pull-up resistance
|
52
|
52
|
|
53
|
|
- def res(self, adc):
|
|
53
|
+ def resol(self, adc):
|
54
|
54
|
"Convert ADC reading into a resolution"
|
55
|
55
|
res = self.temp(adc)-self.temp(adc+1)
|
56
|
56
|
return res
|
57
|
57
|
|
58
|
|
- def v(self, adc):
|
|
58
|
+ def voltage(self, adc):
|
59
|
59
|
"Convert ADC reading into a Voltage"
|
60
|
60
|
return adc * VSTEP # convert the 10 bit ADC value to a voltage
|
61
|
61
|
|
62
|
|
- def r(self, adc):
|
|
62
|
+ def resist(self, adc):
|
63
|
63
|
"Convert ADC reading into a resistance in Ohms"
|
64
|
|
- r = self.rp * self.v(adc) / (VCC - self.v(adc)) # resistance of thermistor
|
|
64
|
+ r = self.rp * self.voltage(adc) / (VCC - self.voltage(adc)) # resistance of thermistor
|
65
|
65
|
return r
|
66
|
66
|
|
67
|
67
|
def temp(self, adc):
|
68
|
68
|
"Convert ADC reading into a temperature in Celcius"
|
69
|
|
- r = self.rp * self.v(adc) / (VCC - self.v(adc)) # resistance of thermistor
|
70
|
|
- lnr = log(r)
|
71
|
|
- Tinv = self.c1 + (self.c2*lnr) + (self.c3*pow(lnr,3))
|
|
69
|
+ l = log(self.resist(adc))
|
|
70
|
+ Tinv = self.c1 + self.c2*l + self.c3*pow(l,3) # inverse temperature
|
72
|
71
|
return (1/Tinv) - ZERO # temperature
|
73
|
72
|
|
74
|
73
|
def adc(self, temp):
|
|
@@ -87,7 +86,7 @@ def main(argv):
|
87
|
86
|
t3 = 250 # high temperature in Kelvin (250 degC)
|
88
|
87
|
r3 = 226.15 # resistance at high temperature (226.15 Ohm)
|
89
|
88
|
rp = 4700; # pull-up resistor (4.7 kOhm)
|
90
|
|
- num_temps = int(36); # number of entries for look-up table
|
|
89
|
+ num_temps = 36; # number of entries for look-up table
|
91
|
90
|
|
92
|
91
|
try:
|
93
|
92
|
opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
|
|
@@ -130,11 +129,12 @@ def main(argv):
|
130
|
129
|
print "const short temptable[NUMTEMPS][2] PROGMEM = {"
|
131
|
130
|
|
132
|
131
|
for temp in temps:
|
133
|
|
- print " { (short) (%7.2f * OVERSAMPLENR ), %s\t}%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % ( t.adc(temp), temp, \
|
|
132
|
+ adc = t.adc(temp)
|
|
133
|
+ print " { (short) (%7.2f * OVERSAMPLENR ), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \
|
134
|
134
|
',' if temp != temps[-1] else ' ', \
|
135
|
|
- t.v( t.adc(temp)), \
|
136
|
|
- t.r( t.adc(temp)), \
|
137
|
|
- t.res(t.adc(temp)) \
|
|
135
|
+ t.voltage(adc), \
|
|
136
|
+ t.resist( adc), \
|
|
137
|
+ t.resol( adc) \
|
138
|
138
|
)
|
139
|
139
|
print "};"
|
140
|
140
|
|