Quellcode durchsuchen

Put more code between pulse start and stop (#9959)

Scott Lahteine vor 7 Jahren
Ursprung
Commit
0dd1c4458d
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden
1 geänderte Dateien mit 46 neuen und 39 gelöschten Zeilen
  1. 46
    39
      Marlin/src/module/stepper.cpp

+ 46
- 39
Marlin/src/module/stepper.cpp Datei anzeigen

@@ -443,48 +443,24 @@ void Stepper::isr() {
443 443
   // Take multiple steps per interrupt (For high speed moves)
444 444
   bool all_steps_done = false;
445 445
   for (uint8_t i = step_loops; i--;) {
446
-    #if ENABLED(LIN_ADVANCE)
447
-
448
-      counter_E += current_block->steps[E_AXIS];
449
-      if (counter_E > 0) {
450
-        counter_E -= current_block->step_event_count;
451
-        #if DISABLED(MIXING_EXTRUDER)
452
-          // Don't step E here for mixing extruder
453
-          count_position[E_AXIS] += count_direction[E_AXIS];
454
-          motor_direction(E_AXIS) ? --e_steps : ++e_steps;
455
-        #endif
456
-      }
457
-
458
-      #if ENABLED(MIXING_EXTRUDER)
459
-        // Step mixing steppers proportionally
460
-        const bool dir = motor_direction(E_AXIS);
461
-        MIXING_STEPPERS_LOOP(j) {
462
-          counter_m[j] += current_block->steps[E_AXIS];
463
-          if (counter_m[j] > 0) {
464
-            counter_m[j] -= current_block->mix_event_count[j];
465
-            dir ? --e_steps[j] : ++e_steps[j];
466
-          }
467
-        }
468
-      #endif
469
-
470
-    #endif // LIN_ADVANCE
471 446
 
472 447
     #define _COUNTER(AXIS) counter_## AXIS
473 448
     #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
474 449
     #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
475 450
 
476 451
     // Advance the Bresenham counter; start a pulse if the axis needs a step
477
-    #define PULSE_START(AXIS) \
452
+    #define PULSE_START(AXIS) do{ \
478 453
       _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
479
-      if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
454
+      if (_COUNTER(AXIS) > 0) _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); }while(0)
480 455
 
481
-    // Stop an active pulse, reset the Bresenham counter, update the position
482
-    #define PULSE_STOP(AXIS) \
456
+    // Advance the Bresenham counter; start a pulse if the axis needs a step
457
+    #define STEP_TICK(AXIS) \
483 458
       if (_COUNTER(AXIS) > 0) { \
484 459
         _COUNTER(AXIS) -= current_block->step_event_count; \
485
-        count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
486
-        _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
487
-      }
460
+        count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; }
461
+
462
+    // Stop an active pulse, if any
463
+    #define PULSE_STOP(AXIS) _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0)
488 464
 
489 465
     /**
490 466
      * Estimate the number of cycles that the stepper logic already takes
@@ -563,8 +539,30 @@ void Stepper::isr() {
563 539
       PULSE_START(Z);
564 540
     #endif
565 541
 
566
-    // For non-advance use linear interpolation for E also
567
-    #if DISABLED(LIN_ADVANCE)
542
+    #if ENABLED(LIN_ADVANCE)
543
+
544
+      counter_E += current_block->steps[E_AXIS];
545
+      if (counter_E > 0) {
546
+        #if DISABLED(MIXING_EXTRUDER)
547
+          // Don't step E here for mixing extruder
548
+          motor_direction(E_AXIS) ? --e_steps : ++e_steps;
549
+        #endif
550
+      }
551
+
552
+      #if ENABLED(MIXING_EXTRUDER)
553
+        // Step mixing steppers proportionally
554
+        const bool dir = motor_direction(E_AXIS);
555
+        MIXING_STEPPERS_LOOP(j) {
556
+          counter_m[j] += current_block->steps[E_AXIS];
557
+          if (counter_m[j] > 0) {
558
+            counter_m[j] -= current_block->mix_event_count[j];
559
+            dir ? --e_steps[j] : ++e_steps[j];
560
+          }
561
+        }
562
+      #endif
563
+
564
+    #else // !LIN_ADVANCE - use linear interpolation for E also
565
+
568 566
       #if ENABLED(MIXING_EXTRUDER)
569 567
         // Keep updating the single E axis
570 568
         counter_E += current_block->steps[E_AXIS];
@@ -580,6 +578,18 @@ void Stepper::isr() {
580 578
       #endif
581 579
     #endif // !LIN_ADVANCE
582 580
 
581
+    #if HAS_X_STEP
582
+      STEP_TICK(X);
583
+    #endif
584
+    #if HAS_Y_STEP
585
+      STEP_TICK(Y);
586
+    #endif
587
+    #if HAS_Z_STEP
588
+      STEP_TICK(Z);
589
+    #endif
590
+
591
+    STEP_TICK(E); // Always tick the single E axis
592
+
583 593
     // For minimum pulse time wait before stopping pulses
584 594
     #if EXTRA_CYCLES_XYZE > 20
585 595
       while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
@@ -600,11 +610,6 @@ void Stepper::isr() {
600 610
 
601 611
     #if DISABLED(LIN_ADVANCE)
602 612
       #if ENABLED(MIXING_EXTRUDER)
603
-        // Always step the single E axis
604
-        if (counter_E > 0) {
605
-          counter_E -= current_block->step_event_count;
606
-          count_position[E_AXIS] += count_direction[E_AXIS];
607
-        }
608 613
         MIXING_STEPPERS_LOOP(j) {
609 614
           if (counter_m[j] > 0) {
610 615
             counter_m[j] -= current_block->mix_event_count[j];
@@ -686,6 +691,7 @@ void Stepper::isr() {
686 691
 
687 692
     SPLIT(interval);  // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
688 693
     _NEXT_ISR(ocr_val);
694
+
689 695
     deceleration_time += interval;
690 696
 
691 697
     #if ENABLED(LIN_ADVANCE)
@@ -714,6 +720,7 @@ void Stepper::isr() {
714 720
 
715 721
     SPLIT(OCR1A_nominal);  // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
716 722
     _NEXT_ISR(ocr_val);
723
+
717 724
     // ensure we're running at the correct step rate, even if we just came off an acceleration
718 725
     step_loops = step_loops_nominal;
719 726
   }

Laden…
Abbrechen
Speichern