|
@@ -118,8 +118,8 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
|
118
|
118
|
constexpr hal_timer_t ADV_NEVER = HAL_TIMER_TYPE_MAX;
|
119
|
119
|
|
120
|
120
|
hal_timer_t Stepper::nextMainISR = 0,
|
121
|
|
- Stepper::nextAdvanceISR = ADV_NEVER,
|
122
|
|
- Stepper::eISR_Rate = ADV_NEVER;
|
|
121
|
+ Stepper::nextAdvanceISR = ADV_NEVER,
|
|
122
|
+ Stepper::eISR_Rate = ADV_NEVER;
|
123
|
123
|
|
124
|
124
|
volatile int Stepper::e_steps[E_STEPPERS];
|
125
|
125
|
int Stepper::final_estep_rate,
|
|
@@ -152,9 +152,10 @@ volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
|
152
|
152
|
long Stepper::counter_m[MIXING_STEPPERS];
|
153
|
153
|
#endif
|
154
|
154
|
|
155
|
|
-hal_timer_t Stepper::acc_step_rate; // needed for deceleration start point
|
156
|
155
|
uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
|
157
|
|
-hal_timer_t Stepper::OCR1A_nominal;
|
|
156
|
+
|
|
157
|
+hal_timer_t Stepper::OCR1A_nominal,
|
|
158
|
+ Stepper::acc_step_rate; // needed for deceleration start point
|
158
|
159
|
|
159
|
160
|
volatile long Stepper::endstops_trigsteps[XYZ];
|
160
|
161
|
|
|
@@ -557,13 +558,13 @@ void Stepper::isr() {
|
557
|
558
|
/**
|
558
|
559
|
* If a minimum pulse time was specified get the timer 0 value.
|
559
|
560
|
*
|
560
|
|
- * TCNT0 has an 8x prescaler, so it increments every 8 cycles.
|
|
561
|
+ * On AVR the TCNT0 timer has an 8x prescaler, so it increments every 8 cycles.
|
561
|
562
|
* That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
|
562
|
563
|
* 20 counts of TCNT0 -by itself- is a good pulse delay.
|
563
|
564
|
* 10µs = 160 or 200 cycles.
|
564
|
565
|
*/
|
565
|
566
|
#if EXTRA_CYCLES_XYZE > 20
|
566
|
|
- uint32_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
|
567
|
+ hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
567
|
568
|
#endif
|
568
|
569
|
|
569
|
570
|
#if HAS_X_STEP
|
|
@@ -676,12 +677,12 @@ void Stepper::isr() {
|
676
|
677
|
NOMORE(acc_step_rate, current_block->nominal_rate);
|
677
|
678
|
|
678
|
679
|
// step_rate to timer interval
|
679
|
|
- const hal_timer_t timer = calc_timer(acc_step_rate);
|
|
680
|
+ const hal_timer_t interval = calc_timer_interval(acc_step_rate);
|
680
|
681
|
|
681
|
|
- SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
682
|
+ SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
682
|
683
|
_NEXT_ISR(ocr_val);
|
683
|
684
|
|
684
|
|
- acceleration_time += timer;
|
|
685
|
+ acceleration_time += interval;
|
685
|
686
|
|
686
|
687
|
#if ENABLED(LIN_ADVANCE)
|
687
|
688
|
|
|
@@ -693,7 +694,7 @@ void Stepper::isr() {
|
693
|
694
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
|
694
|
695
|
#endif
|
695
|
696
|
}
|
696
|
|
- eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
|
|
697
|
+ eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], interval, step_loops);
|
697
|
698
|
|
698
|
699
|
#endif // LIN_ADVANCE
|
699
|
700
|
}
|
|
@@ -713,11 +714,11 @@ void Stepper::isr() {
|
713
|
714
|
step_rate = current_block->final_rate;
|
714
|
715
|
|
715
|
716
|
// step_rate to timer interval
|
716
|
|
- const hal_timer_t timer = calc_timer(step_rate);
|
|
717
|
+ const hal_timer_t interval = calc_timer_interval(step_rate);
|
717
|
718
|
|
718
|
|
- SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
719
|
+ SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
719
|
720
|
_NEXT_ISR(ocr_val);
|
720
|
|
- deceleration_time += timer;
|
|
721
|
+ deceleration_time += interval;
|
721
|
722
|
|
722
|
723
|
#if ENABLED(LIN_ADVANCE)
|
723
|
724
|
|
|
@@ -729,7 +730,7 @@ void Stepper::isr() {
|
729
|
730
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
|
730
|
731
|
#endif
|
731
|
732
|
}
|
732
|
|
- eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
|
|
733
|
+ eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], interval, step_loops);
|
733
|
734
|
|
734
|
735
|
#endif // LIN_ADVANCE
|
735
|
736
|
}
|
|
@@ -754,7 +755,7 @@ void Stepper::isr() {
|
754
|
755
|
#ifdef CPU_32_BIT
|
755
|
756
|
// Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
|
756
|
757
|
hal_timer_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM),
|
757
|
|
- stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
|
|
758
|
+ stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
|
758
|
759
|
HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
|
759
|
760
|
#else
|
760
|
761
|
NOLESS(OCR1A, TCNT1 + 16);
|
|
@@ -817,7 +818,7 @@ void Stepper::isr() {
|
817
|
818
|
for (uint8_t i = step_loops; i--;) {
|
818
|
819
|
|
819
|
820
|
#if EXTRA_CYCLES_E > 20
|
820
|
|
- uint32_t pulse_start = TCNT0;
|
|
821
|
+ hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
821
|
822
|
#endif
|
822
|
823
|
|
823
|
824
|
START_E_PULSE(0);
|
|
@@ -836,8 +837,8 @@ void Stepper::isr() {
|
836
|
837
|
|
837
|
838
|
// For minimum pulse time wait before stopping pulses
|
838
|
839
|
#if EXTRA_CYCLES_E > 20
|
839
|
|
- while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
840
|
|
- pulse_start = TCNT0;
|
|
840
|
+ while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
|
|
841
|
+ pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
841
|
842
|
#elif EXTRA_CYCLES_E > 0
|
842
|
843
|
DELAY_NOPS(EXTRA_CYCLES_E);
|
843
|
844
|
#endif
|
|
@@ -858,7 +859,7 @@ void Stepper::isr() {
|
858
|
859
|
|
859
|
860
|
// For minimum pulse time wait before looping
|
860
|
861
|
#if EXTRA_CYCLES_E > 20
|
861
|
|
- if (i) while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
|
862
|
+ if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
|
862
|
863
|
#elif EXTRA_CYCLES_E > 0
|
863
|
864
|
if (i) DELAY_NOPS(EXTRA_CYCLES_E);
|
864
|
865
|
#endif
|
|
@@ -1297,8 +1298,8 @@ void Stepper::report_positions() {
|
1297
|
1298
|
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
|
1298
|
1299
|
|
1299
|
1300
|
#if EXTRA_CYCLES_BABYSTEP > 20
|
1300
|
|
- #define _SAVE_START const uint32_t pulse_start = TCNT0
|
1301
|
|
- #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
|
1301
|
+ #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM)
|
|
1302
|
+ #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
|
1302
|
1303
|
#else
|
1303
|
1304
|
#define _SAVE_START NOOP
|
1304
|
1305
|
#if EXTRA_CYCLES_BABYSTEP > 0
|