createTemperatureLookup.py: deal with precision limitation on R0.

Inserting a dummy value is better than risking an exception with
failure to write a thermistor table at all. Happens when for one
of the usual thermistors accidently a nominal resistance of
1000k instead of 100k is used.
This commit is contained in:
Markus Hitter 2015-04-20 16:32:19 +02:00
parent 48433a6254
commit 2d191768ca
1 changed files with 4 additions and 1 deletions

View File

@ -62,7 +62,10 @@ class Thermistor:
def temp(self,adc):
"Convert ADC reading into a temperature in Celcius"
v = adc * self.vadc / 1024 # convert the 10 bit ADC value to a voltage
r = self.rs * v / (self.vs - v) # resistance of thermistor
if (self.vs - v): # can be zero due to accuracy limitations
r = self.rs * v / (self.vs - v) # resistance of thermistor
else:
r = self.r0 * 10 # dummy value
try:
return (self.beta / log(r / self.k)) - 273.15 # temperature
except: