From 7dd00036172fac5ea32867f0c6fa986767a95ed5 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 24 Nov 2022 09:37:07 +0100 Subject: [PATCH] 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 +}