Преглед изворни кода

Merge pull request #6912 from thinkyhead/bf_better_pulse_delay

Account for dual XYZ in pulse delay cycles estimate
Scott Lahteine пре 7 година
родитељ
комит
155aa62fb0
1 измењених фајлова са 49 додато и 13 уклоњено
  1. 49
    13
      Marlin/stepper.cpp

+ 49
- 13
Marlin/stepper.cpp Прегледај датотеку

528
         _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
528
         _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
529
       }
529
       }
530
 
530
 
531
+    /**
532
+     * Estimate the number of cycles that the stepper logic already takes
533
+     * up between the start and stop of the X stepper pulse.
534
+     *
535
+     * Currently this uses very modest estimates of around 5 cycles.
536
+     * True values may be derived by careful testing.
537
+     *
538
+     * Once any delay is added, the cost of the delay code itself
539
+     * may be subtracted from this value to get a more accurate delay.
540
+     * Delays under 20 cycles (1.25µs) will be very accurate, using NOPs.
541
+     * Longer delays use a loop. The resolution is 8 cycles.
542
+     */
531
     #if HAS_X_STEP
543
     #if HAS_X_STEP
532
-      #define _COUNT_STEPPERS_1 1
544
+      #define _CYCLE_APPROX_1 5
533
     #else
545
     #else
534
-      #define _COUNT_STEPPERS_1 0
546
+      #define _CYCLE_APPROX_1 0
547
+    #endif
548
+    #if ENABLED(X_DUAL_STEPPER_DRIVERS)
549
+      #define _CYCLE_APPROX_2 _CYCLE_APPROX_1 + 4
550
+    #else
551
+      #define _CYCLE_APPROX_2 _CYCLE_APPROX_1
535
     #endif
552
     #endif
536
     #if HAS_Y_STEP
553
     #if HAS_Y_STEP
537
-      #define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1 + 1
554
+      #define _CYCLE_APPROX_3 _CYCLE_APPROX_2 + 5
555
+    #else
556
+      #define _CYCLE_APPROX_3 _CYCLE_APPROX_2
557
+    #endif
558
+    #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
559
+      #define _CYCLE_APPROX_4 _CYCLE_APPROX_3 + 4
538
     #else
560
     #else
539
-      #define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1
561
+      #define _CYCLE_APPROX_4 _CYCLE_APPROX_3
540
     #endif
562
     #endif
541
     #if HAS_Z_STEP
563
     #if HAS_Z_STEP
542
-      #define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2 + 1
564
+      #define _CYCLE_APPROX_5 _CYCLE_APPROX_4 + 5
565
+    #else
566
+      #define _CYCLE_APPROX_5 _CYCLE_APPROX_4
567
+    #endif
568
+    #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
569
+      #define _CYCLE_APPROX_6 _CYCLE_APPROX_5 + 4
543
     #else
570
     #else
544
-      #define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2
571
+      #define _CYCLE_APPROX_6 _CYCLE_APPROX_5
545
     #endif
572
     #endif
546
     #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
573
     #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
547
-      #define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3 + 1
574
+      #if ENABLED(MIXING_EXTRUDER)
575
+        #define _CYCLE_APPROX_7 _CYCLE_APPROX_6 + (MIXING_STEPPERS) * 6
576
+      #else
577
+        #define _CYCLE_APPROX_7 _CYCLE_APPROX_6 + 5
578
+      #endif
548
     #else
579
     #else
549
-      #define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3
580
+      #define _CYCLE_APPROX_7 _CYCLE_APPROX_6
550
     #endif
581
     #endif
551
 
582
 
552
-    #define CYCLES_EATEN_XYZE ((_COUNT_STEPPERS_4) * 5)
583
+    #define CYCLES_EATEN_XYZE _CYCLE_APPROX_7
553
     #define EXTRA_CYCLES_XYZE (STEP_PULSE_CYCLES - (CYCLES_EATEN_XYZE))
584
     #define EXTRA_CYCLES_XYZE (STEP_PULSE_CYCLES - (CYCLES_EATEN_XYZE))
554
 
585
 
555
-    // If a minimum pulse time was specified get the timer 0 value
556
-    // which increments every 4µs on 16MHz and every 3.2µs on 20MHz.
557
-    // Two or 3 counts of TCNT0 should be a sufficient delay.
586
+    /**
587
+     * If a minimum pulse time was specified get the timer 0 value.
588
+     *
589
+     * TCNT0 has an 8x prescaler, so it increments every 8 cycles. 
590
+     * That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
591
+     * 20 counts of TCNT0 -by itself- is a good pulse delay.
592
+     * 10µs = 160 or 200 cycles.
593
+     */
558
     #if EXTRA_CYCLES_XYZE > 20
594
     #if EXTRA_CYCLES_XYZE > 20
559
       uint32_t pulse_start = TCNT0;
595
       uint32_t pulse_start = TCNT0;
560
     #endif
596
     #endif
627
       break;
663
       break;
628
     }
664
     }
629
 
665
 
630
-    // For minimum pulse time wait before stopping pulses
666
+    // For minimum pulse time wait after stopping pulses also
631
     #if EXTRA_CYCLES_XYZE > 20
667
     #if EXTRA_CYCLES_XYZE > 20
632
       if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
668
       if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
633
     #elif EXTRA_CYCLES_XYZE > 0
669
     #elif EXTRA_CYCLES_XYZE > 0

Loading…
Откажи
Сачувај