From 7dd00036172fac5ea32867f0c6fa986767a95ed5 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 24 Nov 2022 09:37:07 +0100 Subject: [PATCH 1/5] Update AC-Dimmer power calculation Power on AC-Dimmer is based on integral over the sinus. Implement mapping table to get a more linear power behavior. --- .../xdrv_04_light_utils.ino | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino index dffc12019..ebe69a08f 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino @@ -31,6 +31,17 @@ typedef struct gamma_table_t { uint16_t to_gamma; } gamma_table_t; +const gamma_table_t ac_dimmer_table[] = { // don't put in PROGMEM for performance reasons + { 0, 0 }, + { 5, 144 }, + { 10, 205 }, + { 50, 500 }, + { 90, 795 }, + { 95, 866 }, + { 100, 1000 }, + { 0xFFFF, 0xFFFF } // fail-safe if out of range +}; + const gamma_table_t gamma_table[] = { // don't put in PROGMEM for performance reasons { 1, 1 }, { 4, 1 }, @@ -318,6 +329,11 @@ uint16_t ledGammaReverse_internal(uint16_t vg, const struct gamma_table_t *gt_pt } } +// 10 bits power select to 10 bits timing based on sinus curve +uint16_t ac_zero_cross_power(uint16_t v) { + return ledGamma_internal(v, ac_dimmer_table)/10; +} + // 10 bits in, 10 bits out uint16_t ledGamma10_10(uint16_t v) { return ledGamma_internal(v, gamma_table); @@ -345,4 +361,4 @@ uint16_t ledGammaFast(uint16_t v) { uint16_t leddGammaReverseFast(uint16_t vg) { return ledGammaReverse_internal(vg, gamma_table_fast); -} \ No newline at end of file +} From 8bc46aa0d965c1745cade6c6b4778448553cd234 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 24 Nov 2022 09:39:46 +0100 Subject: [PATCH 2/5] AC-Dimmer update change to linear power distribution on PWM --- tasmota/tasmota_xdrv_driver/xdrv_04_light.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino index c865603c8..6f665d27b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino @@ -2191,11 +2191,11 @@ void LightSetOutputs(const uint16_t *cur_col_10) { } if (!Settings->flag4.zerocross_dimmer) { #ifdef ESP32 - TasmotaGlobal.pwm_value[i] = cur_col; // mark the new expected value - // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", i, cur_col); + TasmotaGlobal.pwm_value[i] = ac_zero_cross_power(cur_col); // mark the new expected value + // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", i, cur_col2); #else // ESP32 - analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col : cur_col); - // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col : cur_col); + analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - ac_zero_cross_power(cur_col) : ac_zero_cross_power(cur_col)); + // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col2 : cur_col2); #endif // ESP32 } } From b5448535b2ee6cb302cead123546589f90ca7111 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 24 Nov 2022 10:51:58 +0100 Subject: [PATCH 3/5] Update dimmer loockup table --- tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino index ebe69a08f..1a4412962 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino @@ -33,13 +33,16 @@ typedef struct gamma_table_t { const gamma_table_t ac_dimmer_table[] = { // don't put in PROGMEM for performance reasons { 0, 0 }, + { 1, 64 }, { 5, 144 }, { 10, 205 }, { 50, 500 }, { 90, 795 }, { 95, 866 }, + { 99, 936 }, { 100, 1000 }, { 0xFFFF, 0xFFFF } // fail-safe if out of range + { 0xFFFF, 0xFFFF } // fail-safe if out of range }; const gamma_table_t gamma_table[] = { // don't put in PROGMEM for performance reasons From e3f0445a5dfb0cff956e8457087f2a866710307b Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 24 Nov 2022 13:56:34 +0100 Subject: [PATCH 4/5] fix duplicate line --- tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino index 1a4412962..11c8359ba 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino @@ -42,7 +42,6 @@ const gamma_table_t ac_dimmer_table[] = { // don't put in PROGMEM for performa { 99, 936 }, { 100, 1000 }, { 0xFFFF, 0xFFFF } // fail-safe if out of range - { 0xFFFF, 0xFFFF } // fail-safe if out of range }; const gamma_table_t gamma_table[] = { // don't put in PROGMEM for performance reasons From fce966800f2fa170c153da9d2f1de712fc3c7ec9 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 24 Nov 2022 14:09:56 +0100 Subject: [PATCH 5/5] bugfix in comment --- tasmota/tasmota_xdrv_driver/xdrv_04_light.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino index 6f665d27b..a4c305416 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino @@ -2192,10 +2192,10 @@ void LightSetOutputs(const uint16_t *cur_col_10) { if (!Settings->flag4.zerocross_dimmer) { #ifdef ESP32 TasmotaGlobal.pwm_value[i] = ac_zero_cross_power(cur_col); // mark the new expected value - // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", i, cur_col2); + // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", i, cur_col); #else // ESP32 analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - ac_zero_cross_power(cur_col) : ac_zero_cross_power(cur_col)); - // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col2 : cur_col2); + // AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col : cur_col); #endif // ESP32 } }