From 0e4107da344812562468400f708a938c54e3fa07 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 01:40:29 -0500 Subject: [PATCH 01/10] Minor cleanup of homeaxis, etc. --- Marlin/Marlin_main.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 33257e2dbb..b8c84a9298 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2049,8 +2049,8 @@ static void clean_up_after_endstop_or_probe_move() { #endif #endif - #define DEPLOY_PROBE() set_probe_deployed( true ) - #define STOW_PROBE() set_probe_deployed( false ) + #define DEPLOY_PROBE() set_probe_deployed(true) + #define STOW_PROBE() set_probe_deployed(false) // returns false for ok and true for failure static bool set_probe_deployed(bool deploy) { @@ -2073,8 +2073,8 @@ static void clean_up_after_endstop_or_probe_move() { if (axis_unhomed_error(true, true, true )) { stop(); return true; } #endif - float oldXpos = current_position[X_AXIS]; // save x position - float oldYpos = current_position[Y_AXIS]; // save y position + float oldXpos = current_position[X_AXIS], + oldYpos = current_position[Y_AXIS]; #ifdef _TRIGGERED_WHEN_STOWED_TEST @@ -2430,10 +2430,10 @@ static void do_homing_move(AxisEnum axis, float where, float fr_mm_s = 0.0) { #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS) static void homeaxis(AxisEnum axis) { - #define HOMEAXIS_DO(LETTER) \ - ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) + #define CAN_HOME(A) \ + (axis == A##_AXIS && ((A##_MIN_PIN > -1 && A##_HOME_DIR < 0) || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0))) - if (!(axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : false)) return; + if (!CAN_HOME(X) && !CAN_HOME(Y) && !CAN_HOME(Z)) return; #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { @@ -2532,7 +2532,7 @@ static void homeaxis(AxisEnum axis) { #endif // Put away the Z probe - #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP) + #if HOMING_Z_WITH_PROBE if (axis == Z_AXIS) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> "); @@ -3104,9 +3104,7 @@ inline void gcode_G28() { #if ENABLED(Z_SAFE_HOMING) #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>"); - } + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>"); #endif if (home_all_axis) { @@ -3127,10 +3125,7 @@ inline void gcode_G28() { destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", current_position); - DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", destination); - } + if (DEBUGGING(LEVELING)) DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", destination); #endif // Move in the XY plane From 7e20448a2dc4e4b176fa5454f470015dd5d815cb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 13:29:13 -0500 Subject: [PATCH 02/10] Add HOMING_Z_WITH_PROBE conditional --- Marlin/Conditionals_post.h | 2 ++ Marlin/Marlin_main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/Conditionals_post.h b/Marlin/Conditionals_post.h index ca477f9f18..d0a7c67a8f 100644 --- a/Marlin/Conditionals_post.h +++ b/Marlin/Conditionals_post.h @@ -127,6 +127,8 @@ */ #define HAS_PROBING_PROCEDURE (ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)) + #define HOMING_Z_WITH_PROBE (HAS_BED_PROBE && Z_HOME_DIR < 0 && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)) + // Boundaries for probing based on set limits #define MIN_PROBE_X (max(X_MIN_POS, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER)) #define MAX_PROBE_X (min(X_MAX_POS, X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER)) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b8c84a9298..26b719acf6 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1586,7 +1586,7 @@ static void set_axis_is_at_home(AxisEnum axis) { if (axis == Z_AXIS) { #if HAS_BED_PROBE && Z_HOME_DIR < 0 - #if DISABLED(Z_MIN_PROBE_ENDSTOP) + #if HOMING_Z_WITH_PROBE current_position[Z_AXIS] -= zprobe_zoffset; #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { @@ -2449,7 +2449,7 @@ static void homeaxis(AxisEnum axis) { home_dir(axis); // Homing Z towards the bed? Deploy the Z probe or endstop. - #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP) + #if HOMING_Z_WITH_PROBE if (axis == Z_AXIS) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> "); From b2e5ec85d7f707494b8a281e0d13b3502e75adb0 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:15:41 -0500 Subject: [PATCH 03/10] Add [XYZ]_CENTER conditionals --- Marlin/Conditionals_post.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Marlin/Conditionals_post.h b/Marlin/Conditionals_post.h index d0a7c67a8f..6eab11dac3 100644 --- a/Marlin/Conditionals_post.h +++ b/Marlin/Conditionals_post.h @@ -35,11 +35,14 @@ #endif /** - * Axis lengths + * Axis lengths and center */ #define X_MAX_LENGTH (X_MAX_POS - (X_MIN_POS)) #define Y_MAX_LENGTH (Y_MAX_POS - (Y_MIN_POS)) #define Z_MAX_LENGTH (Z_MAX_POS - (Z_MIN_POS)) + #define X_CENTER float((X_MIN_POS + X_MAX_POS) * 0.5) + #define Y_CENTER float((Y_MIN_POS + Y_MAX_POS) * 0.5) + #define Z_CENTER float((Z_MIN_POS + Z_MAX_POS) * 0.5) /** * CoreXY and CoreXZ From d554c1dda81bdccd4b49ea4dc0462268e3f28c46 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:16:13 -0500 Subject: [PATCH 04/10] Clean up planner kernel pass methods --- Marlin/planner.cpp | 12 +++++------- Marlin/planner.h | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index dd065988fc..3a1ffd1393 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -203,9 +203,8 @@ void Planner::calculate_trapezoid_for_block(block_t* block, float entry_factor, // The kernel called by recalculate() when scanning the plan from last to first entry. -void Planner::reverse_pass_kernel(block_t* previous, block_t* current, block_t* next) { +void Planner::reverse_pass_kernel(block_t* current, block_t* next) { if (!current) return; - UNUSED(previous); if (next) { // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising. @@ -250,15 +249,14 @@ void Planner::reverse_pass() { block[2] = block[1]; block[1] = block[0]; block[0] = &block_buffer[b]; - reverse_pass_kernel(block[0], block[1], block[2]); + reverse_pass_kernel(block[1], block[2]); } } } // The kernel called by recalculate() when scanning the plan from first to last entry. -void Planner::forward_pass_kernel(block_t* previous, block_t* current, block_t* next) { +void Planner::forward_pass_kernel(block_t* previous, block_t* current) { if (!previous) return; - UNUSED(next); // If the previous block is an acceleration block, but it is not long enough to complete the // full speed change within the block, we need to adjust the entry speed accordingly. Entry @@ -288,9 +286,9 @@ void Planner::forward_pass() { block[0] = block[1]; block[1] = block[2]; block[2] = &block_buffer[b]; - forward_pass_kernel(block[0], block[1], block[2]); + forward_pass_kernel(block[0], block[1]); } - forward_pass_kernel(block[1], block[2], NULL); + forward_pass_kernel(block[1], block[2]); } /** diff --git a/Marlin/planner.h b/Marlin/planner.h index 740553668a..e1159294a0 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -320,8 +320,8 @@ class Planner { static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor); - static void reverse_pass_kernel(block_t* previous, block_t* current, block_t* next); - static void forward_pass_kernel(block_t* previous, block_t* current, block_t* next); + static void reverse_pass_kernel(block_t* current, block_t* next); + static void forward_pass_kernel(block_t* previous, block_t* current); static void reverse_pass(); static void forward_pass(); From 08f717e5f7f2798bc8701018170a776d5d10b3aa Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:19:49 -0500 Subject: [PATCH 05/10] Use bit-size typedefs for some stepper vars --- Marlin/stepper.cpp | 18 +++++++++--------- Marlin/stepper.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 64805f1acc..a962a08267 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -87,7 +87,7 @@ long Stepper::counter_X = 0, Stepper::counter_Z = 0, Stepper::counter_E = 0; -volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block +volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE) @@ -534,8 +534,8 @@ void Stepper::isr() { #endif // Calculate new timer value - unsigned short timer, step_rate; - if (step_events_completed <= (unsigned long)current_block->accelerate_until) { + uint16_t timer, step_rate; + if (step_events_completed <= (uint32_t)current_block->accelerate_until) { MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate); acc_step_rate += current_block->initial_rate; @@ -551,14 +551,14 @@ void Stepper::isr() { #if ENABLED(LIN_ADVANCE) if (current_block->use_advance_lead) - current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8; + current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8; if (current_block->use_advance_lead) { #if ENABLED(MIXING_EXTRUDER) MIXING_STEPPERS_LOOP(j) - current_estep_rate[j] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8; + current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8; #else - current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8; + current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8; #endif } @@ -588,7 +588,7 @@ void Stepper::isr() { eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]); #endif } - else if (step_events_completed > (unsigned long)current_block->decelerate_after) { + else if (step_events_completed > (uint32_t)current_block->decelerate_after) { MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate); if (step_rate <= acc_step_rate) { // Still decelerating? @@ -608,9 +608,9 @@ void Stepper::isr() { if (current_block->use_advance_lead) { #if ENABLED(MIXING_EXTRUDER) MIXING_STEPPERS_LOOP(j) - current_estep_rate[j] = ((unsigned long)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8; + current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8; #else - current_estep_rate[TOOL_E_INDEX] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8; + current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8; #endif } diff --git a/Marlin/stepper.h b/Marlin/stepper.h index 177ccf182e..b38b0e8f45 100644 --- a/Marlin/stepper.h +++ b/Marlin/stepper.h @@ -102,7 +102,7 @@ class Stepper { // Counter variables for the Bresenham line tracer static long counter_X, counter_Y, counter_Z, counter_E; - static volatile unsigned long step_events_completed; // The number of step events executed in the current block + static volatile uint32_t step_events_completed; // The number of step events executed in the current block #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE) static unsigned char old_OCR0A; From d9bcc7bb4518d88c3e04770fdc30792cd88e9de1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:20:48 -0500 Subject: [PATCH 06/10] Set a bool when a stepper block is done --- Marlin/stepper.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index a962a08267..e8989286b5 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -372,6 +372,7 @@ void Stepper::isr() { ) endstops.update(); // Take multiple steps per interrupt (For high speed moves) + bool all_steps_done = false; for (int8_t i = 0; i < step_loops; i++) { #ifndef USBCON customizedSerial.checkRx(); // Check for serial chars. @@ -524,8 +525,10 @@ void Stepper::isr() { #endif #endif // !ADVANCE && !LIN_ADVANCE - step_events_completed++; - if (step_events_completed >= current_block->step_event_count) break; + if (++step_events_completed >= current_block->step_event_count) { + all_steps_done = true; + break; + } } #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE) @@ -657,7 +660,7 @@ void Stepper::isr() { OCR1A = (OCR1A < (TCNT1 + 16)) ? (TCNT1 + 16) : OCR1A; // If current block is finished, reset pointer - if (step_events_completed >= current_block->step_event_count) { + if (all_steps_done) { current_block = NULL; planner.discard_current_block(); } From 4ec3d1ea587d70745c6ab159f54822697405f418 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:21:15 -0500 Subject: [PATCH 07/10] Add some commentary to stepper ISR --- Marlin/stepper.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index e8989286b5..9875053a6b 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -450,10 +450,12 @@ void Stepper::isr() { #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN + // Advance the Bresenham counter; start a pulse if the axis needs a step #define PULSE_START(AXIS) \ _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \ if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); } + // Stop an active pulse, reset the Bresenham counter, update the position #define PULSE_STOP(AXIS) \ if (_COUNTER(AXIS) > 0) { \ _COUNTER(AXIS) -= current_block->step_event_count; \ @@ -461,6 +463,7 @@ void Stepper::isr() { _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \ } + // If a minimum pulse time was specified get the CPU clock #if MINIMUM_STEPPER_PULSE > 0 static uint32_t pulse_start; pulse_start = TCNT0; @@ -476,6 +479,7 @@ void Stepper::isr() { PULSE_START(Z); #endif + // For non-advance use linear interpolation for E also #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE) #if ENABLED(MIXING_EXTRUDER) // Keep updating the single E axis @@ -492,6 +496,7 @@ void Stepper::isr() { #endif #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 */ } @@ -532,7 +537,7 @@ void Stepper::isr() { } #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE) - // If we have esteps to execute, fire the next ISR "now" + // If we have esteps to execute, fire the next advance_isr "now" if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2; #endif From 9725bcd0995ce37454016e6d1f762025b183c5e5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:21:43 -0500 Subject: [PATCH 08/10] Minor "optimizations" in stepper ISR --- Marlin/stepper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 9875053a6b..1beeb2ce62 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -386,7 +386,7 @@ void Stepper::isr() { #if DISABLED(MIXING_EXTRUDER) // Don't step E here for mixing extruder count_position[E_AXIS] += count_direction[E_AXIS]; - e_steps[TOOL_E_INDEX] += motor_direction(E_AXIS) ? -1 : 1; + motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX]; #endif } @@ -599,7 +599,7 @@ void Stepper::isr() { else if (step_events_completed > (uint32_t)current_block->decelerate_after) { MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate); - if (step_rate <= acc_step_rate) { // Still decelerating? + if (step_rate < acc_step_rate) { // Still decelerating? step_rate = acc_step_rate - step_rate; NOLESS(step_rate, current_block->final_rate); } @@ -662,7 +662,7 @@ void Stepper::isr() { step_loops = step_loops_nominal; } - OCR1A = (OCR1A < (TCNT1 + 16)) ? (TCNT1 + 16) : OCR1A; + NOLESS(OCR1A, TCNT1 + 16); // If current block is finished, reset pointer if (all_steps_done) { From 8c7ee4599e01be99cef45e4a900bfd8e74c75219 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:22:42 -0500 Subject: [PATCH 09/10] Optimize stepper advance_isr --- Marlin/stepper.cpp | 51 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 1beeb2ce62..a604c92716 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -683,29 +683,50 @@ void Stepper::isr() { old_OCR0A += eISR_Rate; OCR0A = old_OCR0A; - #define STEP_E_ONCE(INDEX) \ - if (e_steps[INDEX] != 0) { \ - E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \ - if (e_steps[INDEX] < 0) { \ - E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \ - e_steps[INDEX]++; \ - } \ - else { \ - E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \ - e_steps[INDEX]--; \ - } \ + #define SET_E_STEP_DIR(INDEX) \ + E## INDEX ##_DIR_WRITE(e_steps[INDEX] <= 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR) + + #define START_E_PULSE(INDEX) \ + if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN) + + #define STOP_E_PULSE(INDEX) \ + if (e_steps[INDEX]) { \ + e_steps[INDEX] < 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \ E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \ } + SET_E_STEP_DIR(0); + #if E_STEPPERS > 1 + SET_E_STEP_DIR(1); + #if E_STEPPERS > 2 + SET_E_STEP_DIR(2); + #if E_STEPPERS > 3 + SET_E_STEP_DIR(3); + #endif + #endif + #endif + // Step all E steppers that have steps for (uint8_t i = 0; i < step_loops; i++) { - STEP_E_ONCE(0); + + START_E_PULSE(0); + #if E_STEPPERS > 1 + START_E_PULSE(1); + #if E_STEPPERS > 2 + START_E_PULSE(2); + #if E_STEPPERS > 3 + START_E_PULSE(3); + #endif + #endif + #endif + + STOP_E_PULSE(0); #if E_STEPPERS > 1 - STEP_E_ONCE(1); + STOP_E_PULSE(1); #if E_STEPPERS > 2 - STEP_E_ONCE(2); + STOP_E_PULSE(2); #if E_STEPPERS > 3 - STEP_E_ONCE(3); + STOP_E_PULSE(3); #endif #endif #endif From 426f66258692a0cdfcab545eb48fbd57bba20bac Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Aug 2016 14:22:58 -0500 Subject: [PATCH 10/10] Apply MINIMUM_STEPPER_PULSE in stepper advance_isr --- Marlin/stepper.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index a604c92716..51459602f0 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -709,6 +709,11 @@ void Stepper::isr() { // Step all E steppers that have steps for (uint8_t i = 0; i < step_loops; i++) { + #if MINIMUM_STEPPER_PULSE > 0 + static uint32_t pulse_start; + pulse_start = TCNT0; + #endif + START_E_PULSE(0); #if E_STEPPERS > 1 START_E_PULSE(1); @@ -720,6 +725,12 @@ void Stepper::isr() { #endif #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 */ } + #endif + STOP_E_PULSE(0); #if E_STEPPERS > 1 STOP_E_PULSE(1);