Skip to content

Commit

Permalink
🐛 Fix Fast PWM on AVR (MarlinFirmware#25030)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellensp authored and thinkyhead committed Dec 16, 2022
1 parent ecdf07f commit 86a10dc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Marlin/src/HAL/AVR/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ void MarlinHAL::set_pwm_frequency(const pin_t pin, const uint16_t f_desired) {
LIMIT(res_pc_temp, 1U, maxtop);

// Calculate frequencies of test prescaler and resolution values
const int f_diff = ABS(f - int(f_desired)),
f_fast_temp = (F_CPU) / (p * (1 + res_fast_temp)),
f_fast_diff = ABS(f_fast_temp - int(f_desired)),
f_pc_temp = (F_CPU) / (2 * p * res_pc_temp),
f_pc_diff = ABS(f_pc_temp - int(f_desired));
const uint16_t f_fast_temp = (F_CPU) / (p * (1 + res_fast_temp)),
f_pc_temp = (F_CPU) / (2 * p * res_pc_temp);
const int f_diff = _MAX(f, f_desired) - _MIN(f, f_desired),
f_fast_diff = _MAX(f_fast_temp, f_desired) - _MIN(f_fast_temp, f_desired),
f_pc_diff = _MAX(f_pc_temp, f_desired) - _MIN(f_pc_temp, f_desired);

if (f_fast_diff < f_diff && f_fast_diff <= f_pc_diff) { // FAST values are closest to desired f
// Set the Wave Generation Mode to FAST PWM
Expand Down

0 comments on commit 86a10dc

Please sign in to comment.