From f806f60fc1c0150e42610c466f799dbd9d76fae4 Mon Sep 17 00:00:00 2001 From: Mihail Dumitrescu Date: Sun, 28 Apr 2024 11:30:24 +0300 Subject: [PATCH 1/2] Move cruise LASER_POWER_TRAP code to cruise block. More succint comments. --- Marlin/src/module/stepper.cpp | 41 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 6426c7f4a2e3..589e382e7ca9 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2337,10 +2337,7 @@ hal_timer_t Stepper::block_phase_isr() { * Laser power variables are calulated and stored in this block by the planner code. * trap_ramp_active_pwr - the active power in this block across accel or decel trap steps. * trap_ramp_entry_incr - holds the precalculated value to increase the current power per accel step. - * - * Apply the starting active power and then increase power per step by the trap_ramp_entry_incr value if positive. */ - #if ENABLED(LASER_POWER_TRAP) if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS) { if (planner.laser_inline.status.isPowered && planner.laser_inline.status.isEnabled) { @@ -2418,10 +2415,7 @@ hal_timer_t Stepper::block_phase_isr() { } #endif // LIN_ADVANCE - /** - * Adjust Laser Power - Decelerating - * trap_ramp_entry_decr - holds the precalculated value to decrease the current power per decel step. - */ + // Adjust Laser Power - Decelerating #if ENABLED(LASER_POWER_TRAP) if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS) { if (planner.laser_inline.status.isPowered && planner.laser_inline.status.isEnabled) { @@ -2451,30 +2445,25 @@ hal_timer_t Stepper::block_phase_isr() { if (la_active) la_interval = calc_timer_interval(current_block->nominal_rate >> current_block->la_scaling); #endif + + // Adjust Laser Power - Cruise + #if ENABLED(LASER_POWER_TRAP) + if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS) { + if (planner.laser_inline.status.isPowered && planner.laser_inline.status.isEnabled) { + if (current_block->laser.trap_ramp_entry_incr > 0) { + current_block->laser.trap_ramp_active_pwr = current_block->laser.power; + cutter.apply_power(current_block->laser.power); + } + } + // Not a powered move. + else cutter.apply_power(0); + } + #endif } // The timer interval is just the nominal value for the nominal speed interval = ticks_nominal; } - - /** - * Adjust Laser Power - Cruise - * power - direct or floor adjusted active laser power. - */ - #if ENABLED(LASER_POWER_TRAP) - if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS) { - if (step_events_completed + 1 == accelerate_until) { - if (planner.laser_inline.status.isPowered && planner.laser_inline.status.isEnabled) { - if (current_block->laser.trap_ramp_entry_incr > 0) { - current_block->laser.trap_ramp_active_pwr = current_block->laser.power; - cutter.apply_power(current_block->laser.power); - } - } - // Not a powered move. - else cutter.apply_power(0); - } - } - #endif } #if ENABLED(LASER_FEATURE) From 51d115670e345b21900d07a450f57276647f28f3 Mon Sep 17 00:00:00 2001 From: Mihail Dumitrescu Date: Fri, 10 May 2024 19:00:15 +0300 Subject: [PATCH 2/2] Multiply laser ramp by steps_per_isr to fix multistepping case. --- Marlin/src/module/stepper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 589e382e7ca9..b8fb847a36f6 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2343,7 +2343,7 @@ hal_timer_t Stepper::block_phase_isr() { if (planner.laser_inline.status.isPowered && planner.laser_inline.status.isEnabled) { if (current_block->laser.trap_ramp_entry_incr > 0) { cutter.apply_power(current_block->laser.trap_ramp_active_pwr); - current_block->laser.trap_ramp_active_pwr += current_block->laser.trap_ramp_entry_incr; + current_block->laser.trap_ramp_active_pwr += current_block->laser.trap_ramp_entry_incr * steps_per_isr; } } // Not a powered move. @@ -2420,7 +2420,7 @@ hal_timer_t Stepper::block_phase_isr() { if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS) { if (planner.laser_inline.status.isPowered && planner.laser_inline.status.isEnabled) { if (current_block->laser.trap_ramp_exit_decr > 0) { - current_block->laser.trap_ramp_active_pwr -= current_block->laser.trap_ramp_exit_decr; + current_block->laser.trap_ramp_active_pwr -= current_block->laser.trap_ramp_exit_decr * steps_per_isr; cutter.apply_power(current_block->laser.trap_ramp_active_pwr); } // Not a powered move.