summaryrefslogtreecommitdiff
path: root/Tonokip_Firmware
diff options
context:
space:
mode:
authorkliment <kliment.yanev@gmail.com>2011-05-01 16:31:46 +0200
committerkliment <kliment.yanev@gmail.com>2011-05-01 16:31:46 +0200
commiteb3940fab4e6469c8ede41f03037427dda4d41c5 (patch)
treef07c4dc58d02ee8bcb86c701e518c827119f3f7d /Tonokip_Firmware
parentd22c0fbf361885a38f83814bc5ee34488edeb00c (diff)
Added watchdog aand minimal temp for greater safety in the case of a disconnected thermistor
Diffstat (limited to 'Tonokip_Firmware')
-rw-r--r--Tonokip_Firmware/Tonokip_Firmware.pde40
-rw-r--r--Tonokip_Firmware/configuration.h7
2 files changed, 45 insertions, 2 deletions
diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde
index 607dc76..a352777 100644
--- a/Tonokip_Firmware/Tonokip_Firmware.pde
+++ b/Tonokip_Firmware/Tonokip_Firmware.pde
@@ -111,8 +111,13 @@ int temp_iState_max = 100*PID_INTEGRAL_DRIVE_MAX/PID_IGAIN;
#ifdef SMOOTHING
uint32_t nma=SMOOTHFACTOR*analogRead(TEMP_0_PIN);
#endif
-
-
+#ifdef WATCHPERIOD
+int watch_raw=-1000;
+unsigned long watchmillis=0;
+#endif
+#ifdef MINTEMP
+int minttemp=temp2analog(MINTEMP);
+#endif
//Inactivity shutdown variables
unsigned long previous_millis_cmd=0;
@@ -623,6 +628,14 @@ inline void process_commands()
#endif
case 104: // M104
if (code_seen('S')) target_raw = temp2analog(code_value());
+ #ifdef WATCHPERIOD
+ if(target_raw>current_raw){
+ watchmillis=max(1,millis());
+ watch_raw=current_raw;
+ }else{
+ watchmillis=0;
+ }
+ #endif
break;
case 140: // M140 set bed temp
if (code_seen('S')) target_bed_raw = temp2analogBed(code_value());
@@ -651,6 +664,14 @@ inline void process_commands()
//break;
case 109: // M109 - Wait for heater to reach target.
if (code_seen('S')) target_raw = temp2analog(code_value());
+ #ifdef WATCHPERIOD
+ if(target_raw>current_raw){
+ watchmillis=max(1,millis());
+ watch_raw=current_raw;
+ }else{
+ watchmillis=0;
+ }
+ #endif
previous_millis_heater = millis();
while(current_raw < target_raw) {
if( (millis()-previous_millis_heater) > 1000 ) //Print Temp Reading every 1 second while heating up.
@@ -1109,6 +1130,21 @@ inline void manage_heater()
nma=(nma+current_raw)-(nma/SMOOTHFACTOR);
current_raw=nma/SMOOTHFACTOR;
#endif
+ #ifdef WATCHPERIOD
+ if(watchmillis && millis()-watchmillis>WATCHPERIOD){
+ if(watch_raw+1>=current_raw){
+ target_raw=0;
+ digitalWrite(HEATER_0_PIN,LOW);
+ digitalWrite(LED_PIN,LOW);
+ }else{
+ watchmillis=0;
+ }
+ }
+ #endif
+ #ifdef MINTEMP
+ if(current_raw<=minttemp)
+ target_raw=0;
+ #endif
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX66675)
#ifdef PIDTEMP
error = target_raw - current_raw;
diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h
index 019a9fd..f97ad6b 100644
--- a/Tonokip_Firmware/configuration.h
+++ b/Tonokip_Firmware/configuration.h
@@ -37,6 +37,13 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move
//#define SMOOTHING 1
//#define SMOOTHFACTOR 16 //best to use a power of two here - determines how many values are averaged together by the smoothing algorithm
+//Experimental watchdog and minimal temp
+//The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
+//If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
+//#define WATCHPERIOD 5000 //5 seconds
+//The minimal temperature defines the temperature below which the heater will not be enabled
+//#define MINTEMP
+
// Select one of these only to define how the nozzle temp is read.
#define HEATER_USES_THERMISTOR
//#define HEATER_USES_AD595