From 0dd1c4458d505ca811efb697ae069dafcd028d7e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Mar 2018 23:06:57 -0600 Subject: [PATCH] Put more code between pulse start and stop (#9959) --- Marlin/src/module/stepper.cpp | 85 +++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 6834cc642..bf4aa4118 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -443,48 +443,24 @@ void Stepper::isr() { // Take multiple steps per interrupt (For high speed moves) bool all_steps_done = false; for (uint8_t i = step_loops; i--;) { - #if ENABLED(LIN_ADVANCE) - - counter_E += current_block->steps[E_AXIS]; - if (counter_E > 0) { - counter_E -= current_block->step_event_count; - #if DISABLED(MIXING_EXTRUDER) - // Don't step E here for mixing extruder - count_position[E_AXIS] += count_direction[E_AXIS]; - motor_direction(E_AXIS) ? --e_steps : ++e_steps; - #endif - } - - #if ENABLED(MIXING_EXTRUDER) - // Step mixing steppers proportionally - const bool dir = motor_direction(E_AXIS); - MIXING_STEPPERS_LOOP(j) { - counter_m[j] += current_block->steps[E_AXIS]; - if (counter_m[j] > 0) { - counter_m[j] -= current_block->mix_event_count[j]; - dir ? --e_steps[j] : ++e_steps[j]; - } - } - #endif - - #endif // LIN_ADVANCE #define _COUNTER(AXIS) counter_## AXIS #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) \ + #define PULSE_START(AXIS) do{ \ _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \ - if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); } + if (_COUNTER(AXIS) > 0) _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); }while(0) - // Stop an active pulse, reset the Bresenham counter, update the position - #define PULSE_STOP(AXIS) \ + // Advance the Bresenham counter; start a pulse if the axis needs a step + #define STEP_TICK(AXIS) \ if (_COUNTER(AXIS) > 0) { \ _COUNTER(AXIS) -= current_block->step_event_count; \ - count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ - _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \ - } + count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; } + + // Stop an active pulse, if any + #define PULSE_STOP(AXIS) _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0) /** * Estimate the number of cycles that the stepper logic already takes @@ -563,8 +539,30 @@ void Stepper::isr() { PULSE_START(Z); #endif - // For non-advance use linear interpolation for E also - #if DISABLED(LIN_ADVANCE) + #if ENABLED(LIN_ADVANCE) + + counter_E += current_block->steps[E_AXIS]; + if (counter_E > 0) { + #if DISABLED(MIXING_EXTRUDER) + // Don't step E here for mixing extruder + motor_direction(E_AXIS) ? --e_steps : ++e_steps; + #endif + } + + #if ENABLED(MIXING_EXTRUDER) + // Step mixing steppers proportionally + const bool dir = motor_direction(E_AXIS); + MIXING_STEPPERS_LOOP(j) { + counter_m[j] += current_block->steps[E_AXIS]; + if (counter_m[j] > 0) { + counter_m[j] -= current_block->mix_event_count[j]; + dir ? --e_steps[j] : ++e_steps[j]; + } + } + #endif + + #else // !LIN_ADVANCE - use linear interpolation for E also + #if ENABLED(MIXING_EXTRUDER) // Keep updating the single E axis counter_E += current_block->steps[E_AXIS]; @@ -580,6 +578,18 @@ void Stepper::isr() { #endif #endif // !LIN_ADVANCE + #if HAS_X_STEP + STEP_TICK(X); + #endif + #if HAS_Y_STEP + STEP_TICK(Y); + #endif + #if HAS_Z_STEP + STEP_TICK(Z); + #endif + + STEP_TICK(E); // Always tick the single E axis + // For minimum pulse time wait before stopping pulses #if EXTRA_CYCLES_XYZE > 20 while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } @@ -600,11 +610,6 @@ void Stepper::isr() { #if DISABLED(LIN_ADVANCE) #if ENABLED(MIXING_EXTRUDER) - // Always step the single E axis - if (counter_E > 0) { - counter_E -= current_block->step_event_count; - count_position[E_AXIS] += count_direction[E_AXIS]; - } MIXING_STEPPERS_LOOP(j) { if (counter_m[j] > 0) { counter_m[j] -= current_block->mix_event_count[j]; @@ -686,6 +691,7 @@ void Stepper::isr() { SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL _NEXT_ISR(ocr_val); + deceleration_time += interval; #if ENABLED(LIN_ADVANCE) @@ -714,6 +720,7 @@ void Stepper::isr() { SPLIT(OCR1A_nominal); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL _NEXT_ISR(ocr_val); + // ensure we're running at the correct step rate, even if we just came off an acceleration step_loops = step_loops_nominal; }