|
|
@ -267,41 +267,28 @@ class Stepper {
|
|
|
|
// Set direction bits for all steppers
|
|
|
|
// Set direction bits for all steppers
|
|
|
|
static void set_directions();
|
|
|
|
static void set_directions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Limit the speed to 10KHz for AVR
|
|
|
|
|
|
|
|
#ifndef STEP_DOUBLER_FREQUENCY
|
|
|
|
|
|
|
|
#define STEP_DOUBLER_FREQUENCY 10000
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static uint32_t calc_timer_interval(uint32_t step_rate) {
|
|
|
|
FORCE_INLINE static uint32_t calc_timer_interval(uint32_t step_rate) {
|
|
|
|
uint32_t timer;
|
|
|
|
uint32_t timer;
|
|
|
|
|
|
|
|
|
|
|
|
NOMORE(step_rate, uint32_t(MAX_STEP_FREQUENCY));
|
|
|
|
NOMORE(step_rate, uint32_t(MAX_STEP_FREQUENCY));
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: HAL: tidy this up, use Conditionals_post.h
|
|
|
|
#if DISABLED(DISABLE_MULTI_STEPPING)
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
if (step_rate > STEP_DOUBLER_FREQUENCY * 2) { // If steprate > (STEP_DOUBLER_FREQUENCY * 2) kHz >> step 4 times
|
|
|
|
#if ENABLED(DISABLE_MULTI_STEPPING)
|
|
|
|
|
|
|
|
step_loops = 1;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (step_rate > STEP_DOUBLER_FREQUENCY * 2) { // If steprate > (STEP_DOUBLER_FREQUENCY * 2) kHz >> step 4 times
|
|
|
|
|
|
|
|
step_rate >>= 2;
|
|
|
|
|
|
|
|
step_loops = 4;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (step_rate > STEP_DOUBLER_FREQUENCY) { // If steprate > STEP_DOUBLER_FREQUENCY kHz >> step 2 times
|
|
|
|
|
|
|
|
step_rate >>= 1;
|
|
|
|
|
|
|
|
step_loops = 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
step_loops = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
|
|
|
|
|
|
|
|
step_rate >>= 2;
|
|
|
|
step_rate >>= 2;
|
|
|
|
step_loops = 4;
|
|
|
|
step_loops = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (step_rate > 10000) { // If steprate > 10kHz >> step 2 times
|
|
|
|
else if (step_rate > STEP_DOUBLER_FREQUENCY) { // If steprate > STEP_DOUBLER_FREQUENCY kHz >> step 2 times
|
|
|
|
step_rate >>= 1;
|
|
|
|
step_rate >>= 1;
|
|
|
|
step_loops = 2;
|
|
|
|
step_loops = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
step_loops = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
step_loops = 1;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
// In case of high-performance processor, it is able to calculate in real-time
|
|
|
|
// In case of high-performance processor, it is able to calculate in real-time
|
|
|
@ -309,8 +296,9 @@ class Stepper {
|
|
|
|
timer = uint32_t(HAL_STEPPER_TIMER_RATE) / step_rate;
|
|
|
|
timer = uint32_t(HAL_STEPPER_TIMER_RATE) / step_rate;
|
|
|
|
NOLESS(timer, min_time_per_step); // (STEP_DOUBLER_FREQUENCY * 2 kHz - this should never happen)
|
|
|
|
NOLESS(timer, min_time_per_step); // (STEP_DOUBLER_FREQUENCY * 2 kHz - this should never happen)
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
NOLESS(step_rate, uint32_t(F_CPU / 500000U));
|
|
|
|
constexpr uint32_t min_step_rate = F_CPU / 500000U;
|
|
|
|
step_rate -= F_CPU / 500000; // Correct for minimal speed
|
|
|
|
NOLESS(step_rate, min_step_rate);
|
|
|
|
|
|
|
|
step_rate -= min_step_rate; // Correct for minimal speed
|
|
|
|
if (step_rate >= (8 * 256)) { // higher step rate
|
|
|
|
if (step_rate >= (8 * 256)) { // higher step rate
|
|
|
|
const uint8_t tmp_step_rate = (step_rate & 0x00FF);
|
|
|
|
const uint8_t tmp_step_rate = (step_rate & 0x00FF);
|
|
|
|
const uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
|
|
|
|
const uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
|
|
|
|