Browse Source

Allow buffer clean without release command

Scott Lahteine 7 years ago
parent
commit
93560836de
2 changed files with 27 additions and 22 deletions
  1. 26
    21
      Marlin/stepper.cpp
  2. 1
    1
      Marlin/stepper.h

+ 26
- 21
Marlin/stepper.cpp View File

83
 // private:
83
 // private:
84
 
84
 
85
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
85
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
86
-uint16_t Stepper::cleaning_buffer_counter = 0;
86
+int16_t Stepper::cleaning_buffer_counter = 0;
87
 
87
 
88
 #if ENABLED(X_DUAL_ENDSTOPS)
88
 #if ENABLED(X_DUAL_ENDSTOPS)
89
   bool Stepper::locked_x_motor = false, Stepper::locked_x2_motor = false;
89
   bool Stepper::locked_x_motor = false, Stepper::locked_x2_motor = false;
381
 
381
 
382
   uint16_t ocr_val;
382
   uint16_t ocr_val;
383
 
383
 
384
-  #define ENDSTOP_NOMINAL_OCR_VAL 3000    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
385
-  #define OCR_VAL_TOLERANCE 1000          // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
384
+  #define ENDSTOP_NOMINAL_OCR_VAL 3000 // Check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
385
+  #define OCR_VAL_TOLERANCE       1000 // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
386
 
386
 
387
   #if DISABLED(LIN_ADVANCE)
387
   #if DISABLED(LIN_ADVANCE)
388
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
388
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
393
 
393
 
394
   #define _SPLIT(L) (ocr_val = (uint16_t)L)
394
   #define _SPLIT(L) (ocr_val = (uint16_t)L)
395
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
395
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
396
+
396
     #define SPLIT(L) _SPLIT(L)
397
     #define SPLIT(L) _SPLIT(L)
397
-  #else                 // sample endstops in between step pulses
398
+
399
+  #else // !ENDSTOP_INTERRUPTS_FEATURE : Sample endstops between stepping ISRs
400
+
398
     static uint32_t step_remaining = 0;
401
     static uint32_t step_remaining = 0;
402
+
399
     #define SPLIT(L) do { \
403
     #define SPLIT(L) do { \
400
       _SPLIT(L); \
404
       _SPLIT(L); \
401
       if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
405
       if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
407
 
411
 
408
     if (step_remaining && ENDSTOPS_ENABLED) {   // Just check endstops - not yet time for a step
412
     if (step_remaining && ENDSTOPS_ENABLED) {   // Just check endstops - not yet time for a step
409
       endstops.update();
413
       endstops.update();
410
-      if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
411
-        step_remaining -= ENDSTOP_NOMINAL_OCR_VAL;
412
-        ocr_val = ENDSTOP_NOMINAL_OCR_VAL;
413
-      }
414
-      else {
415
-        ocr_val = step_remaining;
416
-        step_remaining = 0;  //  last one before the ISR that does the step
417
-      }
418
 
414
 
415
+      // Next ISR either for endstops or stepping
416
+      ocr_val = step_remaining <= ENDSTOP_NOMINAL_OCR_VAL ? step_remaining : ENDSTOP_NOMINAL_OCR_VAL;
417
+      step_remaining -= ocr_val;
419
       _NEXT_ISR(ocr_val);
418
       _NEXT_ISR(ocr_val);
420
-
421
       NOLESS(OCR1A, TCNT1 + 16);
419
       NOLESS(OCR1A, TCNT1 + 16);
422
-
423
       _ENABLE_ISRs(); // re-enable ISRs
420
       _ENABLE_ISRs(); // re-enable ISRs
424
       return;
421
       return;
425
     }
422
     }
426
-  #endif
427
 
423
 
424
+  #endif // !ENDSTOP_INTERRUPTS_FEATURE
425
+
426
+  //
427
+  // When cleaning, discard the current block and run fast
428
+  //
428
   if (cleaning_buffer_counter) {
429
   if (cleaning_buffer_counter) {
429
-    --cleaning_buffer_counter;
430
     current_block = NULL;
430
     current_block = NULL;
431
     planner.discard_current_block();
431
     planner.discard_current_block();
432
-    #ifdef SD_FINISHED_RELEASECOMMAND
433
-      if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
434
-    #endif
435
-    _NEXT_ISR(200); // Run at max speed - 10 KHz
436
-    _ENABLE_ISRs(); // re-enable ISRs
432
+    if (cleaning_buffer_counter < 0)
433
+      ++cleaning_buffer_counter;            // Count up for endstop hit
434
+    else {
435
+      --cleaning_buffer_counter;            // Count down for abort print
436
+      #ifdef SD_FINISHED_RELEASECOMMAND
437
+        if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
438
+      #endif
439
+    }
440
+    _NEXT_ISR(200);                             // Run at max speed - 10 KHz
441
+    _ENABLE_ISRs();
437
     return;
442
     return;
438
   }
443
   }
439
 
444
 

+ 1
- 1
Marlin/stepper.h View File

104
   private:
104
   private:
105
 
105
 
106
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
106
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
107
-    static uint16_t cleaning_buffer_counter;
107
+    static int16_t cleaning_buffer_counter;
108
 
108
 
109
     #if ENABLED(X_DUAL_ENDSTOPS)
109
     #if ENABLED(X_DUAL_ENDSTOPS)
110
       static bool locked_x_motor, locked_x2_motor;
110
       static bool locked_x_motor, locked_x2_motor;

Loading…
Cancel
Save