Browse Source

M109 now equal to sprinter

Erik van der Zalm 12 years ago
parent
commit
95d3d9847c
2 changed files with 52 additions and 23 deletions
  1. 7
    0
      Marlin/Configuration.h
  2. 45
    23
      Marlin/Marlin.pde

+ 7
- 0
Marlin/Configuration.h View File

@@ -146,9 +146,16 @@ const int dropsegments=5; //everything with this number of steps  will be ignore
146 146
 #define WATCHDOG_TIMEOUT 4
147 147
 
148 148
 
149
+
150
+//// Experimental watchdog and minimal temp
151
+// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
149 152
 // 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
150 153
 //#define WATCHPERIOD 5000 //5 seconds
151 154
 
155
+// Actual temperature must be close to target for this long before M109 returns success
156
+//#define TEMP_RESIDENCY_TIME 20  // (seconds)
157
+//#define TEMP_HYSTERESIS 5       // (C°) range of +/- temperatures considered "close" to the target one
158
+
152 159
 //// The minimal temperature defines the temperature below which the heater will not be enabled
153 160
 #define MINTEMP 5
154 161
 #define BED_MINTEMP 5

+ 45
- 23
Marlin/Marlin.pde View File

@@ -780,7 +780,7 @@ inline void process_commands()
780 780
         #ifdef WATCHPERIOD
781 781
             if(target_raw[0] > current_raw[0]){
782 782
                 watchmillis = max(1,millis());
783
-                watch_raw[0] = current_raw[0];
783
+                watch_raw = current_raw[0];
784 784
             }else{
785 785
                 watchmillis = 0;
786 786
             }
@@ -820,32 +820,54 @@ inline void process_commands()
820 820
         #endif
821 821
         return;
822 822
         //break;
823
-      case 109: // M109 - Wait for extruder heater to reach target.
824
-        LCD_MESSAGE("Heating...");
825
-               if (code_seen('S')) target_raw[0] = temp2analog(code_value());
826
-#ifdef PIDTEMP
827
-               pid_setpoint = code_value();
828
-#endif //PIDTEM
829
-        #ifdef WATCHPERIOD
830
-          if(target_raw[0]>current_raw[0]){
823
+      case 109: {// M109 - Wait for extruder heater to reach target.
824
+            LCD_MESSAGE("Heating...");
825
+            if (code_seen('S')) target_raw[0] = temp2analog(code_value());
826
+            #ifdef PIDTEMP
827
+            pid_setpoint = code_value();
828
+            #endif //PIDTEM
829
+            #ifdef WATCHPERIOD
830
+            if(target_raw[0]>current_raw[0]) {
831 831
               watchmillis = max(1,millis());
832
-              watch_raw[0] = current_raw[0];
833
-          }else{
832
+              watch_raw = current_raw[0];
833
+            } else {
834 834
               watchmillis = 0;
835
-          }
836
-        #endif
837
-          codenum = millis(); 
838
-          starttime=millis();
839
-          while(current_raw[0] < target_raw[0]) {
840
-            if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up.
841
-              Serial.print("T:");
842
-              Serial.println( analog2temp(current_raw[0]) ); 
843
-              codenum = millis();
844 835
             }
845
-            LCD_STATUS;
846
-            manage_heater();
836
+            #endif //WATCHPERIOD
837
+            codenum = millis(); 
838
+     
839
+               /* See if we are heating up or cooling down */
840
+              bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling
841
+
842
+            #ifdef TEMP_RESIDENCY_TIME
843
+            long residencyStart;
844
+            residencyStart = -1;
845
+            /* continue to loop until we have reached the target temp   
846
+              _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
847
+            while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) ||
848
+                    (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
849
+            #else
850
+            while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) {
851
+            #endif //TEMP_RESIDENCY_TIME
852
+              if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
853
+                Serial.print("T:");
854
+                Serial.println( analog2temp(current_raw[0]) );
855
+                codenum = millis();
856
+              }
857
+              manage_heater();
858
+              LCD_STATUS;
859
+              #ifdef TEMP_RESIDENCY_TIME
860
+               /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
861
+                  or when current temp falls outside the hysteresis after target temp was reached */
862
+              if ((residencyStart == -1 &&  target_direction && current_raw[0] >= target_raw[0]) ||
863
+                  (residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) ||
864
+                  (residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) {
865
+                residencyStart = millis();
866
+              }
867
+              #endif //TEMP_RESIDENCY_TIME
868
+	    }
869
+            LCD_MESSAGE("Marlin ready.");
847 870
           }
848
-          LCD_MESSAGE("UltiMarlin ready.");
849 871
           break;
850 872
       case 190: // M190 - Wait bed for heater to reach target.
851 873
       #if TEMP_1_PIN > -1

Loading…
Cancel
Save