add config parameters for controlling temperature

This commit is contained in:
Andrew de Quincey 2021-05-01 15:02:51 +01:00
parent 7bbc241578
commit 9c77d1ab30
3 changed files with 44 additions and 18 deletions

View File

@ -119,3 +119,13 @@ kiln_must_catch_up_max_error = 10 #degrees
# set set this offset to -4 to compensate. This probably means you have a
# cheap thermocouple. Invest in a better thermocouple.
thermocouple_offset=0
# some kilns/thermocouples start erroneously reporting "short" errors at higher temperatures
# due to plasma forming in the kiln.
# Set this to False to ignore these errors and assume the temperature reading was correct anyway
honour_theromocouple_short_errors = True
# number of samples of temperature to average.
# If you suffer from ghe high temperature kiln issue and have set honour_theromocouple_short_errors to False,
# you will likely need to increase this (eg I use 40)
temperature_average_samples = 5

View File

@ -26,7 +26,7 @@ class MAX31855(object):
self.units = units
self.data = None
self.board = board
self.noConnection = self.shortToGround = self.shortToVCC = False
self.noConnection = self.shortToGround = self.shortToVCC = self.unknownError = False
# Initialize needed GPIO
GPIO.setmode(self.board)
@ -74,9 +74,10 @@ class MAX31855(object):
if anyErrors:
self.noConnection = (data_32 & 0x00000001) != 0 # OC bit, D0
self.shortToGround = (data_32 & 0x00000002) != 0 # SCG bit, D1
self.shortToVCC = (data_32 & 0x00000004) != 0
self.shortToVCC = (data_32 & 0x00000004) != 0 # SCV bit, D2
self.unknownError = not (self.noConnection | self.shortToGround | self.shortToVCC) # Errk!
else:
self.noConnection = self.shortToGround = self.shortToVCC = False
self.noConnection = self.shortToGround = self.shortToVCC = self.unknownError = False
def data_to_tc_temperature(self, data_32 = None):
'''Takes an integer and returns a thermocouple temperature in celsius.'''

View File

@ -8,7 +8,6 @@ import config
log = logging.getLogger(__name__)
TEMPERATURE_MOVING_AVERAGE_SAMPLES = 40
class Output(object):
def __init__(self):
@ -124,15 +123,24 @@ class TempSensorReal(TempSensor):
temps = []
while True:
temp = self.thermocouple.get()
temps.append(temp)
if len(temps) > TEMPERATURE_MOVING_AVERAGE_SAMPLES:
del temps[0]
if len(temps):
self.temperature = sum(temps) / len(temps)
self.noConnection = self.thermocouple.noConnection
self.shortToGround = self.thermocouple.shortToGround
self.shortToVCC = self.thermocouple.shortToVCC
self.unknownError = self.thermocouple.unknownError
is_bad_value = self.noConnection | self.unknownError
if config.honour_theromocouple_short_errors:
is_bad_value |= self.shortToGround | self.shortToVCC
if not is_bad_value:
temps.append(temp)
if len(temps) > config.temperature_average_samples:
del temps[0]
else:
log.error(f"Problem reading temp N/C:{self.noConnection} GND:{self.shortToGround} VCC:{self.shortToVCC} ???:{self.unknownError}")
if len(temps):
self.temperature = sum(temps) / len(temps)
time.sleep(self.sleeptime)
class Oven(threading.Thread):
@ -167,6 +175,9 @@ class Oven(threading.Thread):
if self.board.temp_sensor.shortToVCC:
log.info("Refusing to start profile - thermocouple short to VCC")
return
if self.board.temp_sensor.unknownError:
log.info("Refusing to start profile - thermocouple unknown error")
return
log.info("Running schedule %s" % profile.name)
self.profile = profile
@ -217,6 +228,10 @@ class Oven(threading.Thread):
log.info("emergency!!! lost connection to thermocouple, shutting down")
self.reset()
if self.board.temp_sensor.unknownError:
log.info("emergency!!! unknown thermocouple error, shutting down")
self.reset()
def reset_if_schedule_ended(self):
if self.runtime > self.totaltime:
log.info("schedule ended, shutting down")