|
@@ -87,7 +87,7 @@ long Stepper::counter_X = 0,
|
87
|
87
|
Stepper::counter_Z = 0,
|
88
|
88
|
Stepper::counter_E = 0;
|
89
|
89
|
|
90
|
|
-volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
|
|
90
|
+volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
|
91
|
91
|
|
92
|
92
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
93
|
93
|
|
|
@@ -372,6 +372,7 @@ void Stepper::isr() {
|
372
|
372
|
) endstops.update();
|
373
|
373
|
|
374
|
374
|
// Take multiple steps per interrupt (For high speed moves)
|
|
375
|
+ bool all_steps_done = false;
|
375
|
376
|
for (int8_t i = 0; i < step_loops; i++) {
|
376
|
377
|
#ifndef USBCON
|
377
|
378
|
customizedSerial.checkRx(); // Check for serial chars.
|
|
@@ -385,7 +386,7 @@ void Stepper::isr() {
|
385
|
386
|
#if DISABLED(MIXING_EXTRUDER)
|
386
|
387
|
// Don't step E here for mixing extruder
|
387
|
388
|
count_position[E_AXIS] += count_direction[E_AXIS];
|
388
|
|
- e_steps[TOOL_E_INDEX] += motor_direction(E_AXIS) ? -1 : 1;
|
|
389
|
+ motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
|
389
|
390
|
#endif
|
390
|
391
|
}
|
391
|
392
|
|
|
@@ -449,10 +450,12 @@ void Stepper::isr() {
|
449
|
450
|
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
450
|
451
|
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
451
|
452
|
|
|
453
|
+ // Advance the Bresenham counter; start a pulse if the axis needs a step
|
452
|
454
|
#define PULSE_START(AXIS) \
|
453
|
455
|
_COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
|
454
|
456
|
if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
|
455
|
457
|
|
|
458
|
+ // Stop an active pulse, reset the Bresenham counter, update the position
|
456
|
459
|
#define PULSE_STOP(AXIS) \
|
457
|
460
|
if (_COUNTER(AXIS) > 0) { \
|
458
|
461
|
_COUNTER(AXIS) -= current_block->step_event_count; \
|
|
@@ -460,6 +463,7 @@ void Stepper::isr() {
|
460
|
463
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
|
461
|
464
|
}
|
462
|
465
|
|
|
466
|
+ // If a minimum pulse time was specified get the CPU clock
|
463
|
467
|
#if MINIMUM_STEPPER_PULSE > 0
|
464
|
468
|
static uint32_t pulse_start;
|
465
|
469
|
pulse_start = TCNT0;
|
|
@@ -475,6 +479,7 @@ void Stepper::isr() {
|
475
|
479
|
PULSE_START(Z);
|
476
|
480
|
#endif
|
477
|
481
|
|
|
482
|
+ // For non-advance use linear interpolation for E also
|
478
|
483
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
479
|
484
|
#if ENABLED(MIXING_EXTRUDER)
|
480
|
485
|
// Keep updating the single E axis
|
|
@@ -491,6 +496,7 @@ void Stepper::isr() {
|
491
|
496
|
#endif
|
492
|
497
|
#endif // !ADVANCE && !LIN_ADVANCE
|
493
|
498
|
|
|
499
|
+ // For a minimum pulse time wait before stopping pulses
|
494
|
500
|
#if MINIMUM_STEPPER_PULSE > 0
|
495
|
501
|
#define CYCLES_EATEN_BY_CODE 10
|
496
|
502
|
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
|
|
@@ -524,18 +530,20 @@ void Stepper::isr() {
|
524
|
530
|
#endif
|
525
|
531
|
#endif // !ADVANCE && !LIN_ADVANCE
|
526
|
532
|
|
527
|
|
- step_events_completed++;
|
528
|
|
- if (step_events_completed >= current_block->step_event_count) break;
|
|
533
|
+ if (++step_events_completed >= current_block->step_event_count) {
|
|
534
|
+ all_steps_done = true;
|
|
535
|
+ break;
|
|
536
|
+ }
|
529
|
537
|
}
|
530
|
538
|
|
531
|
539
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
532
|
|
- // If we have esteps to execute, fire the next ISR "now"
|
|
540
|
+ // If we have esteps to execute, fire the next advance_isr "now"
|
533
|
541
|
if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
|
534
|
542
|
#endif
|
535
|
543
|
|
536
|
544
|
// Calculate new timer value
|
537
|
|
- unsigned short timer, step_rate;
|
538
|
|
- if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
|
|
545
|
+ uint16_t timer, step_rate;
|
|
546
|
+ if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
|
539
|
547
|
|
540
|
548
|
MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
541
|
549
|
acc_step_rate += current_block->initial_rate;
|
|
@@ -551,14 +559,14 @@ void Stepper::isr() {
|
551
|
559
|
#if ENABLED(LIN_ADVANCE)
|
552
|
560
|
|
553
|
561
|
if (current_block->use_advance_lead)
|
554
|
|
- current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
562
|
+ current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
555
|
563
|
|
556
|
564
|
if (current_block->use_advance_lead) {
|
557
|
565
|
#if ENABLED(MIXING_EXTRUDER)
|
558
|
566
|
MIXING_STEPPERS_LOOP(j)
|
559
|
|
- current_estep_rate[j] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
|
567
|
+ current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
560
|
568
|
#else
|
561
|
|
- current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
569
|
+ current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
562
|
570
|
#endif
|
563
|
571
|
}
|
564
|
572
|
|
|
@@ -588,10 +596,10 @@ void Stepper::isr() {
|
588
|
596
|
eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
589
|
597
|
#endif
|
590
|
598
|
}
|
591
|
|
- else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
|
|
599
|
+ else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
|
592
|
600
|
MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
593
|
601
|
|
594
|
|
- if (step_rate <= acc_step_rate) { // Still decelerating?
|
|
602
|
+ if (step_rate < acc_step_rate) { // Still decelerating?
|
595
|
603
|
step_rate = acc_step_rate - step_rate;
|
596
|
604
|
NOLESS(step_rate, current_block->final_rate);
|
597
|
605
|
}
|
|
@@ -608,9 +616,9 @@ void Stepper::isr() {
|
608
|
616
|
if (current_block->use_advance_lead) {
|
609
|
617
|
#if ENABLED(MIXING_EXTRUDER)
|
610
|
618
|
MIXING_STEPPERS_LOOP(j)
|
611
|
|
- current_estep_rate[j] = ((unsigned long)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
|
619
|
+ current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
612
|
620
|
#else
|
613
|
|
- current_estep_rate[TOOL_E_INDEX] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
621
|
+ current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8;
|
614
|
622
|
#endif
|
615
|
623
|
}
|
616
|
624
|
|
|
@@ -654,10 +662,10 @@ void Stepper::isr() {
|
654
|
662
|
step_loops = step_loops_nominal;
|
655
|
663
|
}
|
656
|
664
|
|
657
|
|
- OCR1A = (OCR1A < (TCNT1 + 16)) ? (TCNT1 + 16) : OCR1A;
|
|
665
|
+ NOLESS(OCR1A, TCNT1 + 16);
|
658
|
666
|
|
659
|
667
|
// If current block is finished, reset pointer
|
660
|
|
- if (step_events_completed >= current_block->step_event_count) {
|
|
668
|
+ if (all_steps_done) {
|
661
|
669
|
current_block = NULL;
|
662
|
670
|
planner.discard_current_block();
|
663
|
671
|
}
|
|
@@ -675,29 +683,61 @@ void Stepper::isr() {
|
675
|
683
|
old_OCR0A += eISR_Rate;
|
676
|
684
|
OCR0A = old_OCR0A;
|
677
|
685
|
|
678
|
|
- #define STEP_E_ONCE(INDEX) \
|
679
|
|
- if (e_steps[INDEX] != 0) { \
|
680
|
|
- E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
|
681
|
|
- if (e_steps[INDEX] < 0) { \
|
682
|
|
- E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \
|
683
|
|
- e_steps[INDEX]++; \
|
684
|
|
- } \
|
685
|
|
- else { \
|
686
|
|
- E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \
|
687
|
|
- e_steps[INDEX]--; \
|
688
|
|
- } \
|
|
686
|
+ #define SET_E_STEP_DIR(INDEX) \
|
|
687
|
+ E## INDEX ##_DIR_WRITE(e_steps[INDEX] <= 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
|
|
688
|
+
|
|
689
|
+ #define START_E_PULSE(INDEX) \
|
|
690
|
+ if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN)
|
|
691
|
+
|
|
692
|
+ #define STOP_E_PULSE(INDEX) \
|
|
693
|
+ if (e_steps[INDEX]) { \
|
|
694
|
+ e_steps[INDEX] < 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \
|
689
|
695
|
E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
|
690
|
696
|
}
|
691
|
697
|
|
|
698
|
+ SET_E_STEP_DIR(0);
|
|
699
|
+ #if E_STEPPERS > 1
|
|
700
|
+ SET_E_STEP_DIR(1);
|
|
701
|
+ #if E_STEPPERS > 2
|
|
702
|
+ SET_E_STEP_DIR(2);
|
|
703
|
+ #if E_STEPPERS > 3
|
|
704
|
+ SET_E_STEP_DIR(3);
|
|
705
|
+ #endif
|
|
706
|
+ #endif
|
|
707
|
+ #endif
|
|
708
|
+
|
692
|
709
|
// Step all E steppers that have steps
|
693
|
710
|
for (uint8_t i = 0; i < step_loops; i++) {
|
694
|
|
- STEP_E_ONCE(0);
|
|
711
|
+
|
|
712
|
+ #if MINIMUM_STEPPER_PULSE > 0
|
|
713
|
+ static uint32_t pulse_start;
|
|
714
|
+ pulse_start = TCNT0;
|
|
715
|
+ #endif
|
|
716
|
+
|
|
717
|
+ START_E_PULSE(0);
|
|
718
|
+ #if E_STEPPERS > 1
|
|
719
|
+ START_E_PULSE(1);
|
|
720
|
+ #if E_STEPPERS > 2
|
|
721
|
+ START_E_PULSE(2);
|
|
722
|
+ #if E_STEPPERS > 3
|
|
723
|
+ START_E_PULSE(3);
|
|
724
|
+ #endif
|
|
725
|
+ #endif
|
|
726
|
+ #endif
|
|
727
|
+
|
|
728
|
+ // For a minimum pulse time wait before stopping pulses
|
|
729
|
+ #if MINIMUM_STEPPER_PULSE > 0
|
|
730
|
+ #define CYCLES_EATEN_BY_E 10
|
|
731
|
+ while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_E) { /* nada */ }
|
|
732
|
+ #endif
|
|
733
|
+
|
|
734
|
+ STOP_E_PULSE(0);
|
695
|
735
|
#if E_STEPPERS > 1
|
696
|
|
- STEP_E_ONCE(1);
|
|
736
|
+ STOP_E_PULSE(1);
|
697
|
737
|
#if E_STEPPERS > 2
|
698
|
|
- STEP_E_ONCE(2);
|
|
738
|
+ STOP_E_PULSE(2);
|
699
|
739
|
#if E_STEPPERS > 3
|
700
|
|
- STEP_E_ONCE(3);
|
|
740
|
+ STOP_E_PULSE(3);
|
701
|
741
|
#endif
|
702
|
742
|
#endif
|
703
|
743
|
#endif
|