From c440ca7369ce4bde939c51de03c0117b1b642ccc Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 1 Apr 2019 18:44:13 +0200 Subject: [PATCH] Revert "Phase correct PWM for bed, frequency 40KHz." --- Firmware/timer02.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Firmware/timer02.c b/Firmware/timer02.c index 113c7246..8309f940 100644 --- a/Firmware/timer02.c +++ b/Firmware/timer02.c @@ -11,11 +11,19 @@ uint8_t timer02_pwm0 = 0; - void timer02_set_pwm0(uint8_t pwm0) { - TCCR0A |= (2 << COM0B0); //switch OC0B to OCR mode - OCR0B = (uint16_t)OCR0A * pwm0 / 255; + if (timer02_pwm0 == pwm0) return; + if (pwm0) + { + TCCR0A |= (2 << COM0B0); + OCR0B = pwm0 - 1; + } + else + { + TCCR0A &= ~(2 << COM0B0); + OCR0B = 0; + } timer02_pwm0 = pwm0; } @@ -31,12 +39,13 @@ void timer02_init(void) TIMSK0 &= ~(1<