From feffc1986744cdf10f9e8ca474f4a1aa4ca10dfe Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 16 Nov 2021 14:06:36 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20fast=20PWM=20WGM=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to #23102 --- Marlin/src/HAL/AVR/fast_pwm.cpp | 10 ++++++++-- Marlin/src/feature/spindle_laser.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Marlin/src/HAL/AVR/fast_pwm.cpp b/Marlin/src/HAL/AVR/fast_pwm.cpp index cbe4fed94a..804e5fad30 100644 --- a/Marlin/src/HAL/AVR/fast_pwm.cpp +++ b/Marlin/src/HAL/AVR/fast_pwm.cpp @@ -200,7 +200,10 @@ void set_pwm_frequency(const pin_t pin, int f_desired) { res = res_temp_fast; j = i; // Set the Wave Generation Mode to FAST PWM - wgm = timer.n == 2 ? TERN(USE_OCR2A_AS_TOP, WGM2_FAST_PWM_OCR2A, WGM2_FAST_PWM) : WGM_FAST_PWM_ICRn; + if (timer.n == 2) + wgm = TERN(USE_OCR2A_AS_TOP, WGM2_FAST_PWM_OCR2A, WGM2_FAST_PWM); + else + wgm = WGM_FAST_PWM_ICRn; } // If PHASE CORRECT values are closes to desired f else if (f_phase_diff < f_diff) { @@ -208,7 +211,10 @@ void set_pwm_frequency(const pin_t pin, int f_desired) { res = res_temp_phase_correct; j = i; // Set the Wave Generation Mode to PWM PHASE CORRECT - wgm = timer.n == 2 ? TERN(USE_OCR2A_AS_TOP, WGM2_PWM_PC_OCR2A, WGM2_PWM_PC) : WGM_PWM_PC_ICRn; + if (timer.n == 2) + wgm = TERN(USE_OCR2A_AS_TOP, WGM2_PWM_PC_OCR2A, WGM2_FAST_PWM); + else + wgm = WGM_PWM_PC_ICRn; } } } diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 9297e9b95c..cde2b47d90 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -62,7 +62,7 @@ void SpindleLaser::init() { OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off #endif #if ENABLED(SPINDLE_CHANGE_DIR) - OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3) + OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR); // Init rotation to clockwise (M3) #endif #if ENABLED(SPINDLE_LASER_USE_PWM) SET_PWM(SPINDLE_LASER_PWM_PIN);