Skip to content

Commit 549419e

Browse files
⚡️ Set steps_per_isr in calc_multistep_timer_interval
Co-Authored-By: tombrazier <[email protected]>
1 parent e4b83ad commit 549419e

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

Marlin/src/module/stepper.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ bool Stepper::abort_current_block;
189189
#endif
190190

191191
uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
192-
uint8_t Stepper::steps_per_isr; // Count of steps to perform per Stepper ISR call
192+
uint8_t Stepper::steps_per_isr = 1; // Count of steps to perform per Stepper ISR call
193193

194194
#if ENABLED(FREEZE_FEATURE)
195195
bool Stepper::frozen; // = false
@@ -2088,8 +2088,7 @@ hal_timer_t Stepper::calc_timer_interval(uint32_t step_rate) {
20882088
}
20892089

20902090
// Get the timer interval and the number of loops to perform per tick
2091-
hal_timer_t Stepper::calc_timer_interval(uint32_t step_rate, uint8_t &loops) {
2092-
uint8_t multistep = 1;
2091+
hal_timer_t Stepper::calc_multistep_timer_interval(uint32_t step_rate) {
20932092
#if ENABLED(DISABLE_MULTI_STEPPING)
20942093

20952094
// Just make sure the step rate is doable
@@ -2109,16 +2108,15 @@ hal_timer_t Stepper::calc_timer_interval(uint32_t step_rate, uint8_t &loops) {
21092108
(MAX_STEP_ISR_FREQUENCY_128X >> 7)
21102109
};
21112110

2112-
// Select the proper multistepping
2113-
uint8_t idx = 0;
2114-
while (idx < 7 && step_rate > (uint32_t)pgm_read_dword(&limit[idx])) {
2111+
// Find a doable step rate using multistepping
2112+
uint8_t multistep = 1;
2113+
for (uint8_t i = 0; i < 7 && step_rate > uint32_t(pgm_read_dword(&limit[i])); ++i) {
21152114
step_rate >>= 1;
21162115
multistep <<= 1;
2117-
++idx;
2118-
};
2116+
}
2117+
steps_per_isr = multistep;
21192118

21202119
#endif
2121-
loops = multistep;
21222120

21232121
return calc_timer_interval(step_rate);
21242122
}
@@ -2176,7 +2174,7 @@ hal_timer_t Stepper::block_phase_isr() {
21762174
// acc_step_rate is in steps/second
21772175

21782176
// step_rate to timer interval and steps per stepper isr
2179-
interval = calc_timer_interval(acc_step_rate << oversampling_factor, steps_per_isr);
2177+
interval = calc_multistep_timer_interval(acc_step_rate << oversampling_factor);
21802178
acceleration_time += interval;
21812179

21822180
#if ENABLED(LIN_ADVANCE)
@@ -2246,7 +2244,7 @@ hal_timer_t Stepper::block_phase_isr() {
22462244
#endif
22472245

22482246
// step_rate to timer interval and steps per stepper isr
2249-
interval = calc_timer_interval(step_rate << oversampling_factor, steps_per_isr);
2247+
interval = calc_multistep_timer_interval(step_rate << oversampling_factor);
22502248
deceleration_time += interval;
22512249

22522250
#if ENABLED(LIN_ADVANCE)
@@ -2308,7 +2306,7 @@ hal_timer_t Stepper::block_phase_isr() {
23082306
// Calculate the ticks_nominal for this nominal speed, if not done yet
23092307
if (ticks_nominal == 0) {
23102308
// step_rate to timer interval and loops for the nominal speed
2311-
ticks_nominal = calc_timer_interval(current_block->nominal_rate << oversampling_factor, steps_per_isr);
2309+
ticks_nominal = calc_multistep_timer_interval(current_block->nominal_rate << oversampling_factor);
23122310

23132311
#if ENABLED(LIN_ADVANCE)
23142312
if (la_active)
@@ -2628,7 +2626,7 @@ hal_timer_t Stepper::block_phase_isr() {
26282626
#endif
26292627

26302628
// Calculate the initial timer interval
2631-
interval = calc_timer_interval(current_block->initial_rate << oversampling_factor, steps_per_isr);
2629+
interval = calc_multistep_timer_interval(current_block->initial_rate << oversampling_factor);
26322630
acceleration_time += interval;
26332631

26342632
#if ENABLED(LIN_ADVANCE)

Marlin/src/module/stepper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ class Stepper {
834834
static hal_timer_t calc_timer_interval(uint32_t step_rate);
835835

836836
// Calculate timing interval and steps-per-ISR for the given step rate
837-
static hal_timer_t calc_timer_interval(uint32_t step_rate, uint8_t &loops);
837+
static hal_timer_t calc_multistep_timer_interval(uint32_t step_rate);
838838

839839
#if ENABLED(S_CURVE_ACCELERATION)
840840
static void _calc_bezier_curve_coeffs(const int32_t v0, const int32_t v1, const uint32_t av);

0 commit comments

Comments
 (0)