Skip to content

Commit feffc19

Browse files
committed
🐛 Fix fast PWM WGM code
Followup to #23102
1 parent f637e1c commit feffc19

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Marlin/src/HAL/AVR/fast_pwm.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,21 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
200200
res = res_temp_fast;
201201
j = i;
202202
// Set the Wave Generation Mode to FAST PWM
203-
wgm = timer.n == 2 ? TERN(USE_OCR2A_AS_TOP, WGM2_FAST_PWM_OCR2A, WGM2_FAST_PWM) : WGM_FAST_PWM_ICRn;
203+
if (timer.n == 2)
204+
wgm = TERN(USE_OCR2A_AS_TOP, WGM2_FAST_PWM_OCR2A, WGM2_FAST_PWM);
205+
else
206+
wgm = WGM_FAST_PWM_ICRn;
204207
}
205208
// If PHASE CORRECT values are closes to desired f
206209
else if (f_phase_diff < f_diff) {
207210
f = f_temp_phase_correct;
208211
res = res_temp_phase_correct;
209212
j = i;
210213
// Set the Wave Generation Mode to PWM PHASE CORRECT
211-
wgm = timer.n == 2 ? TERN(USE_OCR2A_AS_TOP, WGM2_PWM_PC_OCR2A, WGM2_PWM_PC) : WGM_PWM_PC_ICRn;
214+
if (timer.n == 2)
215+
wgm = TERN(USE_OCR2A_AS_TOP, WGM2_PWM_PC_OCR2A, WGM2_FAST_PWM);
216+
else
217+
wgm = WGM_PWM_PC_ICRn;
212218
}
213219
}
214220
}

Marlin/src/feature/spindle_laser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void SpindleLaser::init() {
6262
OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off
6363
#endif
6464
#if ENABLED(SPINDLE_CHANGE_DIR)
65-
OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3)
65+
OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR); // Init rotation to clockwise (M3)
6666
#endif
6767
#if ENABLED(SPINDLE_LASER_USE_PWM)
6868
SET_PWM(SPINDLE_LASER_PWM_PIN);

0 commit comments

Comments
 (0)