From d554844a51691c4e88d0fab8e7893b62e090f235 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 11 Mar 2023 19:19:36 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Use=20cached=20la=5Factive?= =?UTF-8?q?=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: tombrazier <68918209+tombrazier@users.noreply.github.com> --- Marlin/src/module/stepper.cpp | 14 ++++++++------ Marlin/src/module/stepper.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index a3183c1b12..acb394f281 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -230,6 +230,7 @@ uint32_t Stepper::advance_divisor = 0, int32_t Stepper::la_delta_error = 0, Stepper::la_dividend = 0, Stepper::la_advance_steps = 0; + bool Stepper::la_active = false; #endif #if HAS_SHAPING @@ -1868,7 +1869,7 @@ void Stepper::pulse_phase_isr() { PULSE_PREP(E); #if ENABLED(LIN_ADVANCE) - if (step_needed.e && current_block->la_advance_rate) { + if (la_active && step_needed.e) { // don't actually step here, but do subtract movements steps // from the linear advance step count step_needed.e = false; @@ -2170,7 +2171,7 @@ hal_timer_t Stepper::block_phase_isr() { acceleration_time += interval; #if ENABLED(LIN_ADVANCE) - if (current_block->la_advance_rate) { + if (la_active) { const uint32_t la_step_rate = la_advance_steps < current_block->max_adv_steps ? current_block->la_advance_rate : 0; la_interval = calc_timer_interval(acc_step_rate + la_step_rate) << current_block->la_scaling; } @@ -2240,7 +2241,7 @@ hal_timer_t Stepper::block_phase_isr() { deceleration_time += interval; #if ENABLED(LIN_ADVANCE) - if (current_block->la_advance_rate) { + if (la_active) { const uint32_t la_step_rate = la_advance_steps > current_block->final_adv_steps ? current_block->la_advance_rate : 0; if (la_step_rate != step_rate) { bool reverse_e = la_step_rate > step_rate; @@ -2301,7 +2302,7 @@ hal_timer_t Stepper::block_phase_isr() { ticks_nominal = calc_timer_interval(current_block->nominal_rate << oversampling_factor, steps_per_isr); #if ENABLED(LIN_ADVANCE) - if (current_block->la_advance_rate) + if (la_active) la_interval = calc_timer_interval(current_block->nominal_rate) << current_block->la_scaling; #endif } @@ -2556,11 +2557,12 @@ hal_timer_t Stepper::block_phase_isr() { // Initialize the trapezoid generator from the current block. #if ENABLED(LIN_ADVANCE) + la_active = (current_block->la_advance_rate != 0); #if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1 // If the now active extruder wasn't in use during the last move, its pressure is most likely gone. if (stepper_extruder != last_moved_extruder) la_advance_steps = 0; #endif - if (current_block->la_advance_rate) { + if (la_active) { // Apply LA scaling and discount the effect of frequency scaling la_dividend = (advance_dividend.e << current_block->la_scaling) << oversampling_factor; } @@ -2621,7 +2623,7 @@ hal_timer_t Stepper::block_phase_isr() { acceleration_time += interval; #if ENABLED(LIN_ADVANCE) - if (current_block->la_advance_rate) { + if (la_active) { const uint32_t la_step_rate = la_advance_steps < current_block->max_adv_steps ? current_block->la_advance_rate : 0; la_interval = calc_timer_interval(current_block->initial_rate + la_step_rate) << current_block->la_scaling; } diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 2336bfb405..61dcb3804c 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -574,6 +574,7 @@ class Stepper { static int32_t la_delta_error, // Analogue of delta_error.e for E steps in LA ISR la_dividend, // Analogue of advance_dividend.e for E steps in LA ISR la_advance_steps; // Count of steps added to increase nozzle pressure + static bool la_active; // Whether linear advance is used on the present segment. #endif #if ENABLED(INTEGRATED_BABYSTEPPING)