Skip to content

Commit f0f1a85

Browse files
authored
Merge pull request #17177 from stefanbode/patch-1
AC-Dimmer Power lookup table
2 parents dc93d31 + fce9668 commit f0f1a85

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

tasmota/tasmota_xdrv_driver/xdrv_04_light.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,10 +2191,10 @@ void LightSetOutputs(const uint16_t *cur_col_10) {
21912191
}
21922192
if (!Settings->flag4.zerocross_dimmer) {
21932193
#ifdef ESP32
2194-
TasmotaGlobal.pwm_value[i] = cur_col; // mark the new expected value
2194+
TasmotaGlobal.pwm_value[i] = ac_zero_cross_power(cur_col); // mark the new expected value
21952195
// AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", i, cur_col);
21962196
#else // ESP32
2197-
analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col : cur_col);
2197+
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));
21982198
// AddLog(LOG_LEVEL_DEBUG_MORE, "analogWrite-%i 0x%03X", bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings->pwm_range - cur_col : cur_col);
21992199
#endif // ESP32
22002200
}

tasmota/tasmota_xdrv_driver/xdrv_04_light_utils.ino

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ typedef struct gamma_table_t {
3131
uint16_t to_gamma;
3232
} gamma_table_t;
3333

34+
const gamma_table_t ac_dimmer_table[] = { // don't put in PROGMEM for performance reasons
35+
{ 0, 0 },
36+
{ 1, 64 },
37+
{ 5, 144 },
38+
{ 10, 205 },
39+
{ 50, 500 },
40+
{ 90, 795 },
41+
{ 95, 866 },
42+
{ 99, 936 },
43+
{ 100, 1000 },
44+
{ 0xFFFF, 0xFFFF } // fail-safe if out of range
45+
};
46+
3447
const gamma_table_t gamma_table[] = { // don't put in PROGMEM for performance reasons
3548
{ 1, 1 },
3649
{ 4, 1 },
@@ -318,6 +331,11 @@ uint16_t ledGammaReverse_internal(uint16_t vg, const struct gamma_table_t *gt_pt
318331
}
319332
}
320333

334+
// 10 bits power select to 10 bits timing based on sinus curve
335+
uint16_t ac_zero_cross_power(uint16_t v) {
336+
return ledGamma_internal(v, ac_dimmer_table)/10;
337+
}
338+
321339
// 10 bits in, 10 bits out
322340
uint16_t ledGamma10_10(uint16_t v) {
323341
return ledGamma_internal(v, gamma_table);
@@ -345,4 +363,4 @@ uint16_t ledGammaFast(uint16_t v) {
345363

346364
uint16_t leddGammaReverseFast(uint16_t vg) {
347365
return ledGammaReverse_internal(vg, gamma_table_fast);
348-
}
366+
}

0 commit comments

Comments
 (0)