From eabff30e75429fe1db715c46c123fde678e689e6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Sep 2016 23:59:16 -0500 Subject: [PATCH] Improve MINIMUM_STEPPER_PULSE --- Marlin/Conditionals_post.h | 3 +++ Marlin/macros.h | 3 +++ Marlin/stepper.cpp | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Marlin/Conditionals_post.h b/Marlin/Conditionals_post.h index 89b8afb65..1b5e4188e 100644 --- a/Marlin/Conditionals_post.h +++ b/Marlin/Conditionals_post.h @@ -708,4 +708,7 @@ #define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER)) #endif + // Stepper pulse duration, in cycles + #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND) + #endif // CONDITIONALS_POST_H diff --git a/Marlin/macros.h b/Marlin/macros.h index b098597c5..56b5c8bba 100644 --- a/Marlin/macros.h +++ b/Marlin/macros.h @@ -36,6 +36,9 @@ #define CRITICAL_SECTION_END SREG = _sreg; #endif +// Clock speed factor +#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 + // Remove compiler warning on an unused variable #define UNUSED(x) (void) (x) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 9eef09c40..00595e110 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -460,8 +460,10 @@ void Stepper::isr() { _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \ } + #define CYCLES_EATEN_BY_CODE 240 + // If a minimum pulse time was specified get the CPU clock - #if MINIMUM_STEPPER_PULSE > 0 + #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE static uint32_t pulse_start; pulse_start = TCNT0; #endif @@ -494,9 +496,8 @@ void Stepper::isr() { #endif // !ADVANCE && !LIN_ADVANCE // For a minimum pulse time wait before stopping pulses - #if MINIMUM_STEPPER_PULSE > 0 - #define CYCLES_EATEN_BY_CODE 10 - while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ } + #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE + while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_CODE) { /* nada */ } #endif #if HAS_X_STEP @@ -688,10 +689,12 @@ void Stepper::isr() { E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \ } + #define CYCLES_EATEN_BY_E 60 + // Step all E steppers that have steps for (uint8_t i = 0; i < step_loops; i++) { - #if MINIMUM_STEPPER_PULSE > 0 + #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E static uint32_t pulse_start; pulse_start = TCNT0; #endif @@ -708,9 +711,8 @@ void Stepper::isr() { #endif // For a minimum pulse time wait before stopping pulses - #if MINIMUM_STEPPER_PULSE > 0 - #define CYCLES_EATEN_BY_E 10 - while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_E) { /* nada */ } + #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E + while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_E) { /* nada */ } #endif STOP_E_PULSE(0);