Skip to content

Commit 93f7360

Browse files
sjasonsmithmarknn3
authored andcommitted
Reduce Step Smoothing ceiling to 50% CPU usage (MarlinFirmware#18719)
1 parent 4f41a6e commit 93f7360

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Marlin/src/module/stepper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,11 +2099,11 @@ uint32_t Stepper::block_phase_isr() {
20992099
#if ENABLED(ADAPTIVE_STEP_SMOOTHING)
21002100
uint8_t oversampling = 0; // Assume no axis smoothing (via oversampling)
21012101
// Decide if axis smoothing is possible
2102-
uint32_t max_rate = current_block->nominal_rate; // Get the maximum rate (maximum event speed)
2102+
uint32_t max_rate = current_block->nominal_rate; // Get the step event rate
21032103
while (max_rate < MIN_STEP_ISR_FREQUENCY) { // As long as more ISRs are possible...
21042104
max_rate <<= 1; // Try to double the rate
2105-
if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break; // Don't exceed the estimated ISR limit
2106-
++oversampling; // Increase the oversampling (used for left-shift)
2105+
if (max_rate < MIN_STEP_ISR_FREQUENCY) // Don't exceed the estimated ISR limit
2106+
++oversampling; // Increase the oversampling (used for left-shift)
21072107
}
21082108
oversampling_factor = oversampling; // For all timer interval calculations
21092109
#else

Marlin/src/module/stepper.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@
229229
#define MAX_STEP_ISR_FREQUENCY_2X ((F_CPU) / ISR_EXECUTION_CYCLES(2))
230230
#define MAX_STEP_ISR_FREQUENCY_1X ((F_CPU) / ISR_EXECUTION_CYCLES(1))
231231

232-
// The minimum allowable frequency for step smoothing will be 1/10 of the maximum nominal frequency (in Hz)
233-
#define MIN_STEP_ISR_FREQUENCY MAX_STEP_ISR_FREQUENCY_1X
232+
// The minimum step ISR rate used by ADAPTIVE_STEP_SMOOTHING to target 50% CPU usage
233+
// This does not account for the possibility of multi-stepping.
234+
// Perhaps DISABLE_MULTI_STEPPING should be required with ADAPTIVE_STEP_SMOOTHING.
235+
#define MIN_STEP_ISR_FREQUENCY (MAX_STEP_ISR_FREQUENCY_1X / 2)
234236

235237
//
236238
// Stepper class definition

0 commit comments

Comments
 (0)