From 6a040a69670e66e1e0122c8849fbc87b9df68da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Sat, 18 Mar 2017 20:28:57 +0100 Subject: [PATCH] SOFT_PWM: Do not switch off heaters twice on pwm_count wraparound MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After wraparound, pwm_count <= pwm_mask holds, thus soft_pwm_X <= pwm_count guarantees soft_pwm_X < pwm_mask is true, and the heater will be switched off in the first branch. Do not evaluate the pwm conditions a second time, this reduces the instruction count (4 instructions per PWM) and text size (6 byte). Signed-off-by: Stefan BrĂ¼ns --- Marlin/temperature.cpp | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 33ef2ccda..83c5e7176 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1594,33 +1594,34 @@ void Temperature::isr() { #endif #endif } - - if (soft_pwm_0 <= pwm_count_tmp) WRITE_HEATER_0(0); - #if HOTENDS > 1 - if (soft_pwm_1 <= pwm_count_tmp) WRITE_HEATER_1(0); + else { + if (soft_pwm_0 <= pwm_count_tmp) WRITE_HEATER_0(0); + #if HOTENDS > 1 + if (soft_pwm_1 <= pwm_count_tmp) WRITE_HEATER_1(0); + #endif #if HOTENDS > 2 if (soft_pwm_2 <= pwm_count_tmp) WRITE_HEATER_2(0); - #if HOTENDS > 3 - if (soft_pwm_3 <= pwm_count_tmp) WRITE_HEATER_3(0); - #endif #endif - #endif - - #if HAS_HEATER_BED - if (soft_pwm_BED <= pwm_count_tmp) WRITE_HEATER_BED(0); - #endif - - #if ENABLED(FAN_SOFT_PWM) - #if HAS_FAN0 - if (soft_pwm_fan[0] <= pwm_count_tmp) WRITE_FAN(0); + #if HOTENDS > 3 + if (soft_pwm_3 <= pwm_count_tmp) WRITE_HEATER_3(0); #endif - #if HAS_FAN1 - if (soft_pwm_fan[1] <= pwm_count_tmp) WRITE_FAN1(0); + + #if HAS_HEATER_BED + if (soft_pwm_BED <= pwm_count_tmp) WRITE_HEATER_BED(0); #endif - #if HAS_FAN2 - if (soft_pwm_fan[2] <= pwm_count_tmp) WRITE_FAN2(0); + + #if ENABLED(FAN_SOFT_PWM) + #if HAS_FAN0 + if (soft_pwm_fan[0] <= pwm_count_tmp) WRITE_FAN(0); + #endif + #if HAS_FAN1 + if (soft_pwm_fan[1] <= pwm_count_tmp) WRITE_FAN1(0); + #endif + #if HAS_FAN2 + if (soft_pwm_fan[2] <= pwm_count_tmp) WRITE_FAN2(0); + #endif #endif - #endif + } // SOFT_PWM_SCALE to frequency: //