🐛 Fix fast PWM WGM code

Followup to #23102
This commit is contained in:
Scott Lahteine
2021-11-16 14:06:36 -06:00
parent f637e1c501
commit feffc19867
2 changed files with 9 additions and 3 deletions

View File

@ -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;
}
}
}