Merge pull request #17177 from stefanbode/patch-1

AC-Dimmer Power lookup table
This commit is contained in:
Theo Arends 2022-11-24 14:35:29 +01:00 committed by GitHub
commit f0f1a85984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -2191,10 +2191,10 @@ 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
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_col);
#else // ESP32
analogWrite(Pin(GPIO_PWM1, i), 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_col : cur_col);
#endif // ESP32
}

View File

@ -31,6 +31,19 @@ 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 },
{ 1, 64 },
{ 5, 144 },
{ 10, 205 },
{ 50, 500 },
{ 90, 795 },
{ 95, 866 },
{ 99, 936 },
{ 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 +331,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 +363,4 @@ uint16_t ledGammaFast(uint16_t v) {
uint16_t leddGammaReverseFast(uint16_t vg) {
return ledGammaReverse_internal(vg, gamma_table_fast);
}
}