Skip to content

Commit

Permalink
⚡️ Use cached la_active state
Browse files Browse the repository at this point in the history
Co-Authored-By: tombrazier <[email protected]>
  • Loading branch information
thinkyhead and tombrazier committed Mar 12, 2023
1 parent 194f587 commit d554844
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/module/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d554844

Please sign in to comment.