From 9fa9f1ab016453e0114975f0f28a413489dcd305 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Sun, 18 Apr 2021 23:02:08 +0200 Subject: [PATCH] demo of PWM 100% problem on ESP32 --- tasmota/xdrv_04_light.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index f41ace288..503e4c2dc 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -122,7 +122,7 @@ \*********************************************************************************************/ #define XDRV_04 4 -// #define DEBUG_LIGHT + #define DEBUG_LIGHT enum LightSchemes { LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX }; @@ -1967,7 +1967,12 @@ void LightSetOutputs(const uint16_t *cur_col_10) { cur_col = cur_col > 0 ? changeUIntScale(cur_col, 0, Settings.pwm_range, Light.pwm_min, Light.pwm_max) : 0; // shrink to the range of pwm_min..pwm_max } if (!Settings.flag4.zerocross_dimmer) { - analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col); + uint16_t pwm = bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col; + #ifdef ESP32 + if (pwm = Settings.pwm_range) pwm = Settings.pwm_range+1; // ESP32 full PWM is 1024 (1023 on ESP8266) + #endif + //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("LIT: PWM%d = %d"), i, pwm); + analogWrite(Pin(GPIO_PWM1, i), pwm); } #ifdef USE_PWM_DIMMER // Animate brightness LEDs to follow PWM dimmer brightness