Skip to content

Commit

Permalink
Overheat an thermistor break protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Basov committed May 12, 2021
1 parent 85200b7 commit 5cb5939
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions PETCTL.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PETCTL_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cb5939

Please sign in to comment.