|
@@ -267,41 +267,28 @@ class Stepper {
|
267
|
267
|
// Set direction bits for all steppers
|
268
|
268
|
static void set_directions();
|
269
|
269
|
|
|
270
|
+ // Limit the speed to 10KHz for AVR
|
|
271
|
+ #ifndef STEP_DOUBLER_FREQUENCY
|
|
272
|
+ #define STEP_DOUBLER_FREQUENCY 10000
|
|
273
|
+ #endif
|
|
274
|
+
|
270
|
275
|
FORCE_INLINE static uint32_t calc_timer_interval(uint32_t step_rate) {
|
271
|
276
|
uint32_t timer;
|
272
|
277
|
|
273
|
278
|
NOMORE(step_rate, uint32_t(MAX_STEP_FREQUENCY));
|
274
|
279
|
|
275
|
|
- // TODO: HAL: tidy this up, use Conditionals_post.h
|
276
|
|
- #ifdef CPU_32_BIT
|
277
|
|
- #if ENABLED(DISABLE_MULTI_STEPPING)
|
278
|
|
- step_loops = 1;
|
279
|
|
- #else
|
280
|
|
- if (step_rate > STEP_DOUBLER_FREQUENCY * 2) { // If steprate > (STEP_DOUBLER_FREQUENCY * 2) kHz >> step 4 times
|
281
|
|
- step_rate >>= 2;
|
282
|
|
- step_loops = 4;
|
283
|
|
- }
|
284
|
|
- else if (step_rate > STEP_DOUBLER_FREQUENCY) { // If steprate > STEP_DOUBLER_FREQUENCY kHz >> step 2 times
|
285
|
|
- step_rate >>= 1;
|
286
|
|
- step_loops = 2;
|
287
|
|
- }
|
288
|
|
- else {
|
289
|
|
- step_loops = 1;
|
290
|
|
- }
|
291
|
|
- #endif
|
292
|
|
- #else
|
293
|
|
- if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
|
|
280
|
+ #if DISABLED(DISABLE_MULTI_STEPPING)
|
|
281
|
+ if (step_rate > STEP_DOUBLER_FREQUENCY * 2) { // If steprate > (STEP_DOUBLER_FREQUENCY * 2) kHz >> step 4 times
|
294
|
282
|
step_rate >>= 2;
|
295
|
283
|
step_loops = 4;
|
296
|
284
|
}
|
297
|
|
- else if (step_rate > 10000) { // If steprate > 10kHz >> step 2 times
|
|
285
|
+ else if (step_rate > STEP_DOUBLER_FREQUENCY) { // If steprate > STEP_DOUBLER_FREQUENCY kHz >> step 2 times
|
298
|
286
|
step_rate >>= 1;
|
299
|
287
|
step_loops = 2;
|
300
|
288
|
}
|
301
|
|
- else {
|
302
|
|
- step_loops = 1;
|
303
|
|
- }
|
|
289
|
+ else
|
304
|
290
|
#endif
|
|
291
|
+ step_loops = 1;
|
305
|
292
|
|
306
|
293
|
#ifdef CPU_32_BIT
|
307
|
294
|
// In case of high-performance processor, it is able to calculate in real-time
|
|
@@ -309,8 +296,9 @@ class Stepper {
|
309
|
296
|
timer = uint32_t(HAL_STEPPER_TIMER_RATE) / step_rate;
|
310
|
297
|
NOLESS(timer, min_time_per_step); // (STEP_DOUBLER_FREQUENCY * 2 kHz - this should never happen)
|
311
|
298
|
#else
|
312
|
|
- NOLESS(step_rate, uint32_t(F_CPU / 500000U));
|
313
|
|
- step_rate -= F_CPU / 500000; // Correct for minimal speed
|
|
299
|
+ constexpr uint32_t min_step_rate = F_CPU / 500000U;
|
|
300
|
+ NOLESS(step_rate, min_step_rate);
|
|
301
|
+ step_rate -= min_step_rate; // Correct for minimal speed
|
314
|
302
|
if (step_rate >= (8 * 256)) { // higher step rate
|
315
|
303
|
const uint8_t tmp_step_rate = (step_rate & 0x00FF);
|
316
|
304
|
const uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
|