Browse Source

Fixed AUTOTEMP (M109 S215 B260 F1 starts autotemp)

Changed SLOWDOWN. IF this does not work ok OLD_SLOWDOWN is the old algo.
Erik van der Zalm 13 years ago
parent
commit
67cf105bc6
7 changed files with 93 additions and 111 deletions
  1. 3
    3
      Marlin/Configuration.h
  2. 4
    7
      Marlin/Configuration_adv.h
  3. 1
    0
      Marlin/Marlin.h
  4. 26
    12
      Marlin/Marlin.pde
  5. 36
    58
      Marlin/planner.cpp
  6. 2
    8
      Marlin/stepper.cpp
  7. 21
    23
      Marlin/temperature.cpp

+ 3
- 3
Marlin/Configuration.h View File

121
 const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
121
 const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
122
 const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
122
 const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
123
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
123
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
124
-#define DISABLE_MAX_ENDSTOPS
124
+//#define DISABLE_MAX_ENDSTOPS
125
 
125
 
126
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
126
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
127
 #define X_ENABLE_ON 0
127
 #define X_ENABLE_ON 0
165
 
165
 
166
 // default settings 
166
 // default settings 
167
 
167
 
168
-#define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}                    // default steps per unit for ultimaker 
168
+#define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}  // default steps per unit for ultimaker 
169
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
169
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
170
 #define DEFAULT_MAX_ACCELERATION      {9000,9000,100,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
170
 #define DEFAULT_MAX_ACCELERATION      {9000,9000,100,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
171
 
171
 
196
 //#define ULTRA_LCD  //general lcd support, also 16x2
196
 //#define ULTRA_LCD  //general lcd support, also 16x2
197
 //#define SDSUPPORT // Enable SD Card Support in Hardware Console
197
 //#define SDSUPPORT // Enable SD Card Support in Hardware Console
198
 
198
 
199
-//#define ULTIPANEL
199
+#define ULTIPANEL
200
 #ifdef ULTIPANEL
200
 #ifdef ULTIPANEL
201
 //  #define NEWPANEL  //enable this if you have a click-encoder panel
201
 //  #define NEWPANEL  //enable this if you have a click-encoder panel
202
   #define SDSUPPORT
202
   #define SDSUPPORT

+ 4
- 7
Marlin/Configuration_adv.h View File

41
 // the target temperature is set to mintemp+factor*se[steps/sec] and limited by mintemp and maxtemp
41
 // the target temperature is set to mintemp+factor*se[steps/sec] and limited by mintemp and maxtemp
42
 // you exit the value by any M109 without F*
42
 // you exit the value by any M109 without F*
43
 // Also, if the temperature is set to a value <mintemp, it is not changed by autotemp.
43
 // Also, if the temperature is set to a value <mintemp, it is not changed by autotemp.
44
-// on an ultimaker, some initial testing worked with M109 S215 T260 F0.1 in the start.gcode
45
-//#define AUTOTEMP
44
+// on an ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode
45
+#define AUTOTEMP
46
 #ifdef AUTOTEMP
46
 #ifdef AUTOTEMP
47
   #define AUTOTEMP_OLDWEIGHT 0.98
47
   #define AUTOTEMP_OLDWEIGHT 0.98
48
 #endif
48
 #endif
94
 #define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
94
 #define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
95
 #define DEFAULT_MINTRAVELFEEDRATE     0.0
95
 #define DEFAULT_MINTRAVELFEEDRATE     0.0
96
 
96
 
97
-// minimum time in microseconds that a movement needs to take if the buffer is emptied.   Increase this number if you see blobs while printing high speed & high detail.  It will slowdown on the detailed stuff.
98
-#define DEFAULT_MINSEGMENTTIME        20000   // Obsolete delete this
97
+// minimum time in microseconds that a movement needs to take if the buffer is emptied.
98
+#define DEFAULT_MINSEGMENTTIME        20000
99
 
99
 
100
 // If defined the movements slow down when the look ahead buffer is only half full
100
 // If defined the movements slow down when the look ahead buffer is only half full
101
 #define SLOWDOWN
101
 #define SLOWDOWN
147
 
147
 
148
 #endif // ADVANCE
148
 #endif // ADVANCE
149
 
149
 
150
-// A debugging feature to compare calculated vs performed steps, to see if steps are lost by the software.
151
-//#define DEBUG_STEPS
152
-
153
 // Arc interpretation settings:
150
 // Arc interpretation settings:
154
 #define MM_PER_ARC_SEGMENT 1
151
 #define MM_PER_ARC_SEGMENT 1
155
 #define N_ARC_CORRECTION 25
152
 #define N_ARC_CORRECTION 25

+ 1
- 0
Marlin/Marlin.h View File

64
 
64
 
65
 
65
 
66
 #define SERIAL_PROTOCOL(x) MYSERIAL.print(x);
66
 #define SERIAL_PROTOCOL(x) MYSERIAL.print(x);
67
+#define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y);
67
 #define SERIAL_PROTOCOLPGM(x) serialprintPGM(MYPGM(x));
68
 #define SERIAL_PROTOCOLPGM(x) serialprintPGM(MYPGM(x));
68
 #define SERIAL_PROTOCOLLN(x) {MYSERIAL.print(x);MYSERIAL.write('\n');}
69
 #define SERIAL_PROTOCOLLN(x) {MYSERIAL.print(x);MYSERIAL.write('\n');}
69
 #define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(MYPGM(x));MYSERIAL.write('\n');}
70
 #define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(MYPGM(x));MYSERIAL.write('\n');}

+ 26
- 12
Marlin/Marlin.pde View File

849
       }
849
       }
850
       #if (TEMP_0_PIN > -1)
850
       #if (TEMP_0_PIN > -1)
851
         SERIAL_PROTOCOLPGM("ok T:");
851
         SERIAL_PROTOCOLPGM("ok T:");
852
-        SERIAL_PROTOCOL(degHotend(tmp_extruder)); 
853
-        //SERIAL_PROTOCOLPGM("/");
854
-        //SERIAL_PROTOCOL(degTargetHotend(tmp_extruder)); 
852
+        SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); 
853
+        SERIAL_PROTOCOLPGM(" /");
854
+        SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1); 
855
         #if TEMP_BED_PIN > -1
855
         #if TEMP_BED_PIN > -1
856
           SERIAL_PROTOCOLPGM(" B:");  
856
           SERIAL_PROTOCOLPGM(" B:");  
857
-          SERIAL_PROTOCOL(degBed());
858
-          //SERIAL_PROTOCOLPGM("/");
859
-          //SERIAL_PROTOCOL(degTargetBed());
857
+          SERIAL_PROTOCOL_F(degBed(),1);
858
+          SERIAL_PROTOCOLPGM(" /");
859
+          SERIAL_PROTOCOL_F(degTargetBed(),1);
860
         #endif //TEMP_BED_PIN
860
         #endif //TEMP_BED_PIN
861
       #else
861
       #else
862
         SERIAL_ERROR_START;
862
         SERIAL_ERROR_START;
888
       if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
888
       if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
889
       #ifdef AUTOTEMP
889
       #ifdef AUTOTEMP
890
         if (code_seen('S')) autotemp_min=code_value();
890
         if (code_seen('S')) autotemp_min=code_value();
891
-        if (code_seen('G')) autotemp_max=code_value();
891
+        if (code_seen('B')) autotemp_max=code_value();
892
         if (code_seen('F')) 
892
         if (code_seen('F')) 
893
         {
893
         {
894
           autotemp_factor=code_value();
894
           autotemp_factor=code_value();
915
           if( (millis() - codenum) > 1000UL )
915
           if( (millis() - codenum) > 1000UL )
916
           { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
916
           { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
917
             SERIAL_PROTOCOLPGM("T:");
917
             SERIAL_PROTOCOLPGM("T:");
918
-            SERIAL_PROTOCOL( degHotend(tmp_extruder) ); 
918
+            SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); 
919
             SERIAL_PROTOCOLPGM(" E:");
919
             SERIAL_PROTOCOLPGM(" E:");
920
-            SERIAL_PROTOCOL( (int)tmp_extruder ); 
920
+            SERIAL_PROTOCOL((int)tmp_extruder); 
921
             #ifdef TEMP_RESIDENCY_TIME
921
             #ifdef TEMP_RESIDENCY_TIME
922
               SERIAL_PROTOCOLPGM(" W:");
922
               SERIAL_PROTOCOLPGM(" W:");
923
               if(residencyStart > -1)
923
               if(residencyStart > -1)
966
             SERIAL_PROTOCOLPGM("T:");
966
             SERIAL_PROTOCOLPGM("T:");
967
             SERIAL_PROTOCOL(tt);
967
             SERIAL_PROTOCOL(tt);
968
             SERIAL_PROTOCOLPGM(" E:");
968
             SERIAL_PROTOCOLPGM(" E:");
969
-            SERIAL_PROTOCOL( (int)active_extruder ); 
969
+            SERIAL_PROTOCOL((int)active_extruder); 
970
             SERIAL_PROTOCOLPGM(" B:");
970
             SERIAL_PROTOCOLPGM(" B:");
971
-            SERIAL_PROTOCOLLN(degBed()); 
971
+            SERIAL_PROTOCOL_F(degBed(),1); 
972
+            SERIAL_PROTOCOLLN(""); 
972
             codenum = millis(); 
973
             codenum = millis(); 
973
           }
974
           }
974
           manage_heater();
975
           manage_heater();
1058
       for(int8_t i=0; i < NUM_AXIS; i++) 
1059
       for(int8_t i=0; i < NUM_AXIS; i++) 
1059
       {
1060
       {
1060
         if(code_seen(axis_codes[i])) 
1061
         if(code_seen(axis_codes[i])) 
1061
-          axis_steps_per_unit[i] = code_value();
1062
+          
1063
+          if(i == 3) { // E
1064
+            float value = code_value();
1065
+            if(value < 20.0) {
1066
+              float factor = axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab.
1067
+              max_e_jerk *= factor;
1068
+              max_feedrate[i] *= factor;
1069
+              axis_steps_per_sqr_second[i] *= factor;
1070
+            }
1071
+            axis_steps_per_unit[i] = value;
1072
+          }
1073
+          else {
1074
+            axis_steps_per_unit[i] = code_value();
1075
+          }
1062
       }
1076
       }
1063
       break;
1077
       break;
1064
     case 115: // M115
1078
     case 115: // M115

+ 36
- 58
Marlin/planner.cpp View File

51
     IntersectionDistance[s1_, s2_, a_, d_] := (2 a d - s1^2 + s2^2)/(4 a)
51
     IntersectionDistance[s1_, s2_, a_, d_] := (2 a d - s1^2 + s2^2)/(4 a)
52
 */
52
 */
53
                                                                                                             
53
                                                                                                             
54
-
55
-
56
-
57
 #include "Marlin.h"
54
 #include "Marlin.h"
58
 #include "planner.h"
55
 #include "planner.h"
59
 #include "stepper.h"
56
 #include "stepper.h"
377
 void getHighESpeed()
374
 void getHighESpeed()
378
 {
375
 {
379
   static float oldt=0;
376
   static float oldt=0;
380
-  if(!autotemp_enabled)
377
+  if(!autotemp_enabled){
381
     return;
378
     return;
382
-  if(degTargetHotend0()+2<autotemp_min)  //probably temperature set to zero.
379
+  }
380
+  if(degTargetHotend0()+2<autotemp_min) {  //probably temperature set to zero.
383
     return; //do nothing
381
     return; //do nothing
382
+  }
384
   
383
   
385
-  float high=0;
384
+  float high=0.0;
386
   uint8_t block_index = block_buffer_tail;
385
   uint8_t block_index = block_buffer_tail;
387
   
386
   
388
   while(block_index != block_buffer_head) {
387
   while(block_index != block_buffer_head) {
389
-    float se=block_buffer[block_index].steps_e/float(block_buffer[block_index].step_event_count)*block_buffer[block_index].nominal_rate;
390
-    //se; units steps/sec;
391
-    if(se>high)
392
-    {
393
-      high=se;
388
+    if((block_buffer[block_index].steps_x != 0) ||
389
+       (block_buffer[block_index].steps_y != 0) ||
390
+       (block_buffer[block_index].steps_z != 0)) {
391
+      float se=(float(block_buffer[block_index].steps_e)/float(block_buffer[block_index].step_event_count))*block_buffer[block_index].nominal_speed;
392
+      //se; mm/sec;
393
+      if(se>high)
394
+      {
395
+        high=se;
396
+      }
394
     }
397
     }
395
     block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
398
     block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
396
   }
399
   }
407
   }
410
   }
408
   oldt=t;
411
   oldt=t;
409
   setTargetHotend0(t);
412
   setTargetHotend0(t);
410
-//   SERIAL_ECHO_START;
411
-//   SERIAL_ECHOPAIR("highe",high);
412
-//   SERIAL_ECHOPAIR(" t",t);
413
-//   SERIAL_ECHOLN("");
414
 }
413
 }
415
 #endif
414
 #endif
416
 
415
 
456
     analogWrite(FAN_PIN,tail_fan_speed);
455
     analogWrite(FAN_PIN,tail_fan_speed);
457
   }
456
   }
458
   #endif
457
   #endif
458
+  #ifdef AUTOTEMP
459
+    getHighESpeed();
460
+  #endif
459
 }
461
 }
460
 
462
 
461
 
463
 
517
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
519
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
518
 
520
 
519
   // Bail if this is a zero-length block
521
   // Bail if this is a zero-length block
520
-  if (block->step_event_count <=dropsegments) { return; };
522
+  if (block->step_event_count <= dropsegments) { return; };
521
 
523
 
522
   block->fan_speed = FanSpeed;
524
   block->fan_speed = FanSpeed;
523
   
525
   
540
   // Enable all
542
   // Enable all
541
   if(block->steps_e != 0) { enable_e0();enable_e1();enable_e2(); }
543
   if(block->steps_e != 0) { enable_e0();enable_e1();enable_e2(); }
542
 
544
 
543
-
544
   if (block->steps_e == 0) {
545
   if (block->steps_e == 0) {
545
         if(feed_rate<mintravelfeedrate) feed_rate=mintravelfeedrate;
546
         if(feed_rate<mintravelfeedrate) feed_rate=mintravelfeedrate;
546
   }
547
   }
548
     	if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
549
     	if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
549
   } 
550
   } 
550
   
551
   
551
-  // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
552
-  int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
553
-  #ifdef SLOWDOWN
554
-    if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
555
-  #endif
556
-
557
   float delta_mm[4];
552
   float delta_mm[4];
558
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
553
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
559
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
554
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
569
   // Calculate speed in mm/second for each axis. No divide by zero due to previous checks.
564
   // Calculate speed in mm/second for each axis. No divide by zero due to previous checks.
570
   float inverse_second = feed_rate * inverse_millimeters;
565
   float inverse_second = feed_rate * inverse_millimeters;
571
   
566
   
572
-  block->nominal_speed = block->millimeters * inverse_second; // (mm/sec) Always > 0
573
-  block->nominal_rate = ceil(block->step_event_count * inverse_second); // (step/sec) Always > 0
574
-
567
+  int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
568
+ 
569
+  // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
570
+  #ifdef OLD_SLOWDOWN
571
+    if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
572
+  #endif
575
 
573
 
576
-/*
574
+  #ifdef SLOWDOWN
577
   //  segment time im micro seconds
575
   //  segment time im micro seconds
578
-  long segment_time = lround(1000000.0/inverse_second);
579
-  if ((blockcount>0) && (blockcount < (BLOCK_BUFFER_SIZE - 4))) {
580
-    if (segment_time<minsegmenttime)  { // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
581
-        segment_time=segment_time+lround(2*(minsegmenttime-segment_time)/blockcount);
576
+  unsigned long segment_time = lround(1000000.0/inverse_second);
577
+  if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) {
578
+    if (segment_time < minsegmenttime)  { // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
579
+        inverse_second=1000000.0/(segment_time+lround(2*(minsegmenttime-segment_time)/moves_queued));
582
     }
580
     }
583
   }
581
   }
584
-  else {
585
-    if (segment_time<minsegmenttime) segment_time=minsegmenttime;
586
-  }
582
+  #endif
587
   //  END OF SLOW DOWN SECTION    
583
   //  END OF SLOW DOWN SECTION    
588
-*/
589
 
584
 
585
+  
586
+  block->nominal_speed = block->millimeters * inverse_second; // (mm/sec) Always > 0
587
+  block->nominal_rate = ceil(block->step_event_count * inverse_second); // (step/sec) Always > 0
590
 
588
 
591
- // Calculate speed in mm/sec for each axis
589
+ // Calculate and limit speed in mm/sec for each axis
592
   float current_speed[4];
590
   float current_speed[4];
593
-  for(int i=0; i < 4; i++) {
594
-    current_speed[i] = delta_mm[i] * inverse_second;
595
-  }
596
-
597
-  // Limit speed per axis
598
   float speed_factor = 1.0; //factor <=1 do decrease speed
591
   float speed_factor = 1.0; //factor <=1 do decrease speed
599
   for(int i=0; i < 4; i++) {
592
   for(int i=0; i < 4; i++) {
593
+    current_speed[i] = delta_mm[i] * inverse_second;
600
     if(abs(current_speed[i]) > max_feedrate[i])
594
     if(abs(current_speed[i]) > max_feedrate[i])
601
       speed_factor = min(speed_factor, max_feedrate[i] / abs(current_speed[i]));
595
       speed_factor = min(speed_factor, max_feedrate[i] / abs(current_speed[i]));
602
   }
596
   }
633
 
627
 
634
   // Correct the speed  
628
   // Correct the speed  
635
   if( speed_factor < 1.0) {
629
   if( speed_factor < 1.0) {
636
-//    Serial.print("speed factor : "); Serial.println(speed_factor);
637
-    for(int i=0; i < 4; i++) {
638
-    if(abs(current_speed[i]) > max_feedrate[i])
639
-      speed_factor = min(speed_factor, max_feedrate[i] / abs(current_speed[i]));
640
- /*     
641
-      if(speed_factor < 0.1) {
642
-        Serial.print("speed factor : "); Serial.println(speed_factor);
643
-        Serial.print("current_speed"); Serial.print(i); Serial.print(" : "); Serial.println(current_speed[i]);
644
-      }
645
- */
646
-  }
647
     for(unsigned char i=0; i < 4; i++) {
630
     for(unsigned char i=0; i < 4; i++) {
648
       current_speed[i] *= speed_factor;
631
       current_speed[i] *= speed_factor;
649
     }
632
     }
784
     */
767
     */
785
   #endif // ADVANCE
768
   #endif // ADVANCE
786
 
769
 
787
-
788
-
789
-
790
   calculate_trapezoid_for_block(block, block->entry_speed/block->nominal_speed,
770
   calculate_trapezoid_for_block(block, block->entry_speed/block->nominal_speed,
791
     MINIMUM_PLANNER_SPEED/block->nominal_speed);
771
     MINIMUM_PLANNER_SPEED/block->nominal_speed);
792
     
772
     
797
   memcpy(position, target, sizeof(target)); // position[] = target[]
777
   memcpy(position, target, sizeof(target)); // position[] = target[]
798
 
778
 
799
   planner_recalculate();
779
   planner_recalculate();
800
-  #ifdef AUTOTEMP
801
-    getHighESpeed();
802
-  #endif
780
+
803
   st_wake_up();
781
   st_wake_up();
804
 }
782
 }
805
 
783
 

+ 2
- 8
Marlin/stepper.cpp View File

54
   static long old_advance = 0;
54
   static long old_advance = 0;
55
 #endif
55
 #endif
56
 static long e_steps[3];
56
 static long e_steps[3];
57
-static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
58
 static long acceleration_time, deceleration_time;
57
 static long acceleration_time, deceleration_time;
59
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
58
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
60
 static unsigned short acc_step_rate; // needed for deccelaration start point
59
 static unsigned short acc_step_rate; // needed for deccelaration start point
216
 
215
 
217
 void st_wake_up() {
216
 void st_wake_up() {
218
   //  TCNT1 = 0;
217
   //  TCNT1 = 0;
219
-  if(busy == false) 
220
   ENABLE_STEPPER_DRIVER_INTERRUPT();  
218
   ENABLE_STEPPER_DRIVER_INTERRUPT();  
221
 }
219
 }
222
 
220
 
295
     // Anything in the buffer?
293
     // Anything in the buffer?
296
     current_block = plan_get_current_block();
294
     current_block = plan_get_current_block();
297
     if (current_block != NULL) {
295
     if (current_block != NULL) {
296
+      current_block->busy = true;
298
       trapezoid_generator_reset();
297
       trapezoid_generator_reset();
299
       counter_x = -(current_block->step_event_count >> 1);
298
       counter_x = -(current_block->step_event_count >> 1);
300
       counter_y = counter_x;
299
       counter_y = counter_x;
773
     TIMSK0 |= (1<<OCIE0A);
772
     TIMSK0 |= (1<<OCIE0A);
774
   #endif //ADVANCE
773
   #endif //ADVANCE
775
   
774
   
776
-  #ifdef ENDSTOPS_ONLY_FOR_HOMING
777
-    enable_endstops(false);
778
-  #else
779
-    enable_endstops(true);
780
-  #endif
781
-  
775
+  enable_endstops(true); // Start with endstops active. After homing they can be disabled
782
   sei();
776
   sei();
783
 }
777
 }
784
 
778
 

+ 21
- 23
Marlin/temperature.cpp View File

95
   static int maxttemp[EXTRUDERS] = { 16383 }; // the first value used for all
95
   static int maxttemp[EXTRUDERS] = { 16383 }; // the first value used for all
96
   static int bed_minttemp = 0;
96
   static int bed_minttemp = 0;
97
   static int bed_maxttemp = 16383;
97
   static int bed_maxttemp = 16383;
98
-  static int heater_pin_map[EXTRUDERS] = { HEATER_0_PIN
99
-#if EXTRUDERS > 1
100
-                                         , HEATER_1_PIN
101
-#endif
102
-#if EXTRUDERS > 2
103
-                                         , HEATER_2_PIN
104
-#endif
105
-#if EXTRUDERS > 3
106
-  #error Unsupported number of extruders
107
-#endif
108
-  };
109
   static void *heater_ttbl_map[EXTRUDERS] = { (void *)heater_0_temptable
98
   static void *heater_ttbl_map[EXTRUDERS] = { (void *)heater_0_temptable
110
 #if EXTRUDERS > 1
99
 #if EXTRUDERS > 1
111
                                             , (void *)heater_1_temptable
100
                                             , (void *)heater_1_temptable
138
   float input;
127
   float input;
139
   int cycles=0;
128
   int cycles=0;
140
   bool heating = true;
129
   bool heating = true;
141
-  soft_pwm[0] = 255>>1;
142
 
130
 
143
   unsigned long temp_millis = millis();
131
   unsigned long temp_millis = millis();
144
   unsigned long t1=temp_millis;
132
   unsigned long t1=temp_millis;
154
   
142
   
155
   SERIAL_ECHOLN("PID Autotune start");
143
   SERIAL_ECHOLN("PID Autotune start");
156
   
144
   
157
-  //disable_heater(); // switch off all heaters.
145
+  disable_heater(); // switch off all heaters.
158
   
146
   
147
+  soft_pwm[0] = 255>>1;
148
+    
159
   for(;;) {
149
   for(;;) {
160
 
150
 
161
     if(temp_meas_ready == true) { // temp sample ready
151
     if(temp_meas_ready == true) { // temp sample ready
202
               SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
192
               SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
203
               SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
193
               SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
204
               SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
194
               SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
195
+              /*
205
               Kp = 0.33*Ku;
196
               Kp = 0.33*Ku;
206
               Ki = Kp/Tu;
197
               Ki = Kp/Tu;
207
               Kd = Kp*Tu/3;
198
               Kd = Kp*Tu/3;
216
               SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
207
               SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
217
               SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
208
               SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
218
               SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
209
               SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
210
+              */
219
             }
211
             }
220
           }
212
           }
221
           soft_pwm[0] = (bias + d) >> 1;
213
           soft_pwm[0] = (bias + d) >> 1;
225
       } 
217
       } 
226
     }
218
     }
227
     if(input > (temp + 20)) {
219
     if(input > (temp + 20)) {
228
-      SERIAL_PROTOCOLLNPGM("PID Autotune failed !, Temperature to high");
220
+      SERIAL_PROTOCOLLNPGM("PID Autotune failed! Temperature to high");
229
       return;
221
       return;
230
     }
222
     }
231
     if(millis() - temp_millis > 2000) {
223
     if(millis() - temp_millis > 2000) {
235
       SERIAL_PROTOCOLPGM(" @:");
227
       SERIAL_PROTOCOLPGM(" @:");
236
       SERIAL_PROTOCOLLN(getHeaterPower(0));       
228
       SERIAL_PROTOCOLLN(getHeaterPower(0));       
237
     }
229
     }
230
+    if(((millis() - t1) + (millis() - t2)) > (10L*60L*1000L*2L)) {
231
+      SERIAL_PROTOCOLLNPGM("PID Autotune failed! timeout");
232
+      return;
233
+    }
234
+    if(cycles > 5) {
235
+      SERIAL_PROTOCOLLNPGM("PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h");
236
+      return;
237
+    }
238
     LCD_STATUS;
238
     LCD_STATUS;
239
   }
239
   }
240
 }
240
 }
313
     // Check if temperature is within the correct range
313
     // Check if temperature is within the correct range
314
     if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) 
314
     if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) 
315
     {
315
     {
316
-      //analogWrite(heater_pin_map[e], pid_output);
317
       soft_pwm[e] = (int)pid_output >> 1;
316
       soft_pwm[e] = (int)pid_output >> 1;
318
     }
317
     }
319
     else {
318
     else {
320
-      //analogWrite(heater_pin_map[e], 0);
321
       soft_pwm[e] = 0;
319
       soft_pwm[e] = 0;
322
     }
320
     }
323
   } // End extruder for loop
321
   } // End extruder for loop
680
   target_raw[0]=0;
678
   target_raw[0]=0;
681
   soft_pwm[0]=0;
679
   soft_pwm[0]=0;
682
    #if HEATER_0_PIN > -1  
680
    #if HEATER_0_PIN > -1  
683
-     digitalWrite(HEATER_0_PIN,LOW);
681
+     WRITE(HEATER_0_PIN,LOW);
684
    #endif
682
    #endif
685
   #endif
683
   #endif
686
      
684
      
688
     target_raw[1]=0;
686
     target_raw[1]=0;
689
     soft_pwm[1]=0;
687
     soft_pwm[1]=0;
690
     #if HEATER_1_PIN > -1 
688
     #if HEATER_1_PIN > -1 
691
-      digitalWrite(HEATER_1_PIN,LOW);
689
+      WRITE(HEATER_1_PIN,LOW);
692
     #endif
690
     #endif
693
   #endif
691
   #endif
694
       
692
       
696
     target_raw[2]=0;
694
     target_raw[2]=0;
697
     soft_pwm[2]=0;
695
     soft_pwm[2]=0;
698
     #if HEATER_2_PIN > -1  
696
     #if HEATER_2_PIN > -1  
699
-      digitalWrite(HEATER_2_PIN,LOW);
697
+      WRITE(HEATER_2_PIN,LOW);
700
     #endif
698
     #endif
701
   #endif 
699
   #endif 
702
 
700
 
703
   #if TEMP_BED_PIN > -1
701
   #if TEMP_BED_PIN > -1
704
     target_raw_bed=0;
702
     target_raw_bed=0;
705
     #if HEATER_BED_PIN > -1  
703
     #if HEATER_BED_PIN > -1  
706
-      digitalWrite(HEATER_BED_PIN,LOW);
704
+      WRITE(HEATER_BED_PIN,LOW);
707
     #endif
705
     #endif
708
   #endif 
706
   #endif 
709
 }
707
 }
710
 
708
 
711
 void max_temp_error(uint8_t e) {
709
 void max_temp_error(uint8_t e) {
712
-  digitalWrite(heater_pin_map[e], 0);
710
+  disable_heater();
713
   if(IsStopped() == false) {
711
   if(IsStopped() == false) {
714
     SERIAL_ERROR_START;
712
     SERIAL_ERROR_START;
715
     SERIAL_ERRORLN(e);
713
     SERIAL_ERRORLN(e);
718
 }
716
 }
719
 
717
 
720
 void min_temp_error(uint8_t e) {
718
 void min_temp_error(uint8_t e) {
721
-  digitalWrite(heater_pin_map[e], 0);
719
+  disable_heater();
722
   if(IsStopped() == false) {
720
   if(IsStopped() == false) {
723
     SERIAL_ERROR_START;
721
     SERIAL_ERROR_START;
724
     SERIAL_ERRORLN(e);
722
     SERIAL_ERRORLN(e);
727
 }
725
 }
728
 
726
 
729
 void bed_max_temp_error(void) {
727
 void bed_max_temp_error(void) {
730
-  digitalWrite(HEATER_BED_PIN, 0);
728
+  WRITE(HEATER_BED_PIN, 0);
731
   if(IsStopped() == false) {
729
   if(IsStopped() == false) {
732
     SERIAL_ERROR_START;
730
     SERIAL_ERROR_START;
733
     SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
731
     SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");

Loading…
Cancel
Save