|
@@ -528,33 +528,69 @@ void Stepper::isr() {
|
528
|
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
|
543
|
#if HAS_X_STEP
|
532
|
|
- #define _COUNT_STEPPERS_1 1
|
|
544
|
+ #define _CYCLE_APPROX_1 5
|
533
|
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
|
552
|
#endif
|
536
|
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
|
560
|
#else
|
539
|
|
- #define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1
|
|
561
|
+ #define _CYCLE_APPROX_4 _CYCLE_APPROX_3
|
540
|
562
|
#endif
|
541
|
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
|
570
|
#else
|
544
|
|
- #define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2
|
|
571
|
+ #define _CYCLE_APPROX_6 _CYCLE_APPROX_5
|
545
|
572
|
#endif
|
546
|
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
|
579
|
#else
|
549
|
|
- #define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3
|
|
580
|
+ #define _CYCLE_APPROX_7 _CYCLE_APPROX_6
|
550
|
581
|
#endif
|
551
|
582
|
|
552
|
|
- #define CYCLES_EATEN_XYZE ((_COUNT_STEPPERS_4) * 5)
|
|
583
|
+ #define CYCLES_EATEN_XYZE _CYCLE_APPROX_7
|
553
|
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
|
594
|
#if EXTRA_CYCLES_XYZE > 20
|
559
|
595
|
uint32_t pulse_start = TCNT0;
|
560
|
596
|
#endif
|
|
@@ -627,7 +663,7 @@ void Stepper::isr() {
|
627
|
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
|
667
|
#if EXTRA_CYCLES_XYZE > 20
|
632
|
668
|
if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
633
|
669
|
#elif EXTRA_CYCLES_XYZE > 0
|