From 5cb5939973ca04a90fe554b5aff7cd0c52e3fc3f Mon Sep 17 00:00:00 2001 From: Mikhail Basov Date: Wed, 12 May 2021 04:19:49 +0300 Subject: [PATCH] Overheat an thermistor break protection --- PETCTL.ino | 29 +++++++++++++++++++++++++++++ PETCTL_cfg.h | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/PETCTL.ino b/PETCTL.ino index 430dc4a..05bdde5 100644 --- a/PETCTL.ino +++ b/PETCTL.ino @@ -60,12 +60,17 @@ const float REDCONST = BOBIN_ROUND_LENGTH /(360 * GEAR_RATIO * 1000); boolean runMotor=false; long Speed = (float)CFG_SPEED_INIT/(REDCONST * 1000); // 539 degree/sec for 2.5 mm/s speed +/* Interactive statuses */ #define CHANGE_NO 0 #define CHANGE_TEMPERATURE 1 #define CHANGE_SPEED 2 int whatToChange = CHANGE_NO; unsigned long interactive = millis(); +/* Emergency stop reasons */ +#define OVERHEAT 1 +#define THERMISTOR_ERROR 2 + void encRotationToValue (long* value, int inc = 1, long minValue = 0, long maxValue = 0); void setup() { @@ -186,6 +191,8 @@ void loop() { } curTemp = getTemp(); + if (curTemp > CFG_TEMP_MAX - 10) emStop(OVERHEAT); + if (curTemp < -10) emStop(THERMISTOR_ERROR); regulator.input = curTemp; if (curTemp != prevTemp) { prevTemp = curTemp; @@ -242,6 +249,28 @@ void loop() { finalLength = 0; } } + +void emStop(int reason) { + runMotor = false; + motorCTL(0); + Heat = false; + analogWrite(HEATER_PIN, 0); + oled.clear(); + oled.setScale(3); + oled.setCursorXY(0,2); + oled.println("*HALT!*"); + oled.setScale(2); + oled.setCursorXY(3,40); + switch (reason) { + case OVERHEAT: + oled.println("Overheat"); + break; + case THERMISTOR_ERROR: + oled.println("Thermistor"); + break; + } + for(;;); +} float getMilage() { return stepper.getCurrentDeg() * REDCONST; diff --git a/PETCTL_cfg.h b/PETCTL_cfg.h index ef7d7bc..6196ba8 100644 --- a/PETCTL_cfg.h +++ b/PETCTL_cfg.h @@ -18,7 +18,7 @@ #define CFG_TEMP_INIT 180 /* Maximum allowed temperature [degree C], allowed to set to 10 degree less */ #define CFG_TEMP_MAX 290 -/* Maximum allowed temperature to set [degree C] */ +/* Minimum allowed temperature to set [degree C] */ #define CFG_TEMP_MIN 120 /* Which pin termistor connected to*/ #define CFG_TERM_PIN A0