|
@@ -91,9 +91,11 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
|
91
|
91
|
|
92
|
92
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
93
|
93
|
|
|
94
|
+ constexpr uint16_t ADV_NEVER = 65535;
|
|
95
|
+
|
94
|
96
|
uint16_t Stepper::nextMainISR = 0,
|
95
|
|
- Stepper::nextAdvanceISR = 65535,
|
96
|
|
- Stepper::eISR_Rate = 65535;
|
|
97
|
+ Stepper::nextAdvanceISR = ADV_NEVER,
|
|
98
|
+ Stepper::eISR_Rate = ADV_NEVER;
|
97
|
99
|
|
98
|
100
|
#if ENABLED(LIN_ADVANCE)
|
99
|
101
|
volatile int Stepper::e_steps[E_STEPPERS];
|
|
@@ -107,6 +109,9 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
|
107
|
109
|
Stepper::advance_rate,
|
108
|
110
|
Stepper::advance;
|
109
|
111
|
#endif
|
|
112
|
+
|
|
113
|
+ #define ADV_RATE(T, L) (e_steps[TOOL_E_INDEX] ? (T) * (L) / abs(e_steps[TOOL_E_INDEX]) : ADV_NEVER)
|
|
114
|
+
|
110
|
115
|
#endif
|
111
|
116
|
|
112
|
117
|
long Stepper::acceleration_time, Stepper::deceleration_time;
|
|
@@ -632,7 +637,7 @@ void Stepper::isr() {
|
632
|
637
|
#endif // ADVANCE or LIN_ADVANCE
|
633
|
638
|
|
634
|
639
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
635
|
|
- eISR_Rate = !e_steps[TOOL_E_INDEX] ? 65535 : timer * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
|
640
|
+ eISR_Rate = ADV_RATE(timer, step_loops);
|
636
|
641
|
#endif
|
637
|
642
|
}
|
638
|
643
|
else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
|
|
@@ -683,7 +688,7 @@ void Stepper::isr() {
|
683
|
688
|
#endif // ADVANCE or LIN_ADVANCE
|
684
|
689
|
|
685
|
690
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
686
|
|
- eISR_Rate = !e_steps[TOOL_E_INDEX] ? 65535 : timer * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
|
691
|
+ eISR_Rate = ADV_RATE(timer, step_loops);
|
687
|
692
|
#endif
|
688
|
693
|
}
|
689
|
694
|
else {
|
|
@@ -693,7 +698,7 @@ void Stepper::isr() {
|
693
|
698
|
if (current_block->use_advance_lead)
|
694
|
699
|
current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
|
695
|
700
|
|
696
|
|
- eISR_Rate = !e_steps[TOOL_E_INDEX] ? 65535 : OCR1A_nominal * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
|
|
701
|
+ eISR_Rate = ADV_RATE(OCR1A_nominal, step_loops_nominal);
|
697
|
702
|
|
698
|
703
|
#endif
|
699
|
704
|
|
|
@@ -812,7 +817,7 @@ void Stepper::isr() {
|
812
|
817
|
// The next main ISR comes first
|
813
|
818
|
OCR1A = nextMainISR;
|
814
|
819
|
// New interval for the next advance ISR, if any
|
815
|
|
- if (nextAdvanceISR && nextAdvanceISR != 65535)
|
|
820
|
+ if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
|
816
|
821
|
nextAdvanceISR -= nextMainISR;
|
817
|
822
|
// Will call Stepper::isr on the next interrupt
|
818
|
823
|
nextMainISR = 0;
|