From f2e686ab266ab7bbae68a7d556af1ba88a62bdc0 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Tue, 7 Jul 2020 16:17:43 +0200 Subject: [PATCH 1/5] Fixes some reboots on change the dimmer --- tasmota/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index d5baaed93..cc0fd9bf3 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -118,7 +118,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t network_ethernet : 1; // bit 14 (v8.3.1.3) - CMND_ETHERNET uint32_t tuyamcu_baudrate : 1; // bit 15 (v8.3.1.6) - SetOption97 - Set Baud rate for TuyaMCU serial communication (0 = 9600 or 1 = 115200) uint32_t rotary_uses_rules : 1; // bit 16 (v8.3.1.6) - SetOption98 - Use rules instead of light control - uint32_t spare17 : 1; + uint32_t zerocross_dimmer : 1; // bit 17 (v8.3.1.4) = SetOption99 - Enable zerocross dimmer on PWM DIMMER uint32_t spare18 : 1; uint32_t spare19 : 1; uint32_t spare20 : 1; From debd2b7562ce8a10586c4420fce1586962bc05ef Mon Sep 17 00:00:00 2001 From: stefanbode Date: Tue, 7 Jul 2020 16:19:26 +0200 Subject: [PATCH 2/5] Update xdrv_04_light.ino --- tasmota/xdrv_04_light.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 00cdd96b6..86293c2b2 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -2185,7 +2185,9 @@ void LightSetOutputs(const uint16_t *cur_col_10) { if (!isChannelCT(i)) { // if CT don't use pwm_min and pwm_max 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 } - analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col); + if (!Settings.flag4.zerocross_dimmer) { + analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col); + } } } } From 7c2d9673a1d8aedf4a7fe6739193970d4cff2d30 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Tue, 7 Jul 2020 16:22:55 +0200 Subject: [PATCH 3/5] Update xsns_01_counter.ino --- tasmota/xsns_01_counter.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index c3584f111..54463648f 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -83,11 +83,12 @@ void CounterUpdate(uint8_t index) // restart PWM each second (german 50Hz has to up to 0.01% deviation) // set COUNTERDEBOUNCELOW 1 to catch the raising edge // Zero-HIGH is typical 2ms - if (RtcSettings.pulse_counter[index]%100 == 0 && PinUsed(GPIO_PWM1, index)) { + if (bitRead(Counter.pin_state, index) && Settings.flag4.zerocross_dimmer) { const uint32_t current_cycle = ESP.getCycleCount(); // stop pwm on PIN to start in Sync with rising edge // calculate timeoffset to fire PWM - uint16_t dimm_time= 10000 * (100 - light_state.getDimmer(index)) / Settings.pwm_frequency; + uint16_t cur_col = Light.fade_start_10[0 + Light.pwm_offset]; + uint32_t dimm_time= 1000000 / Settings.pwm_frequency * (1024 - cur_col) / 1024; digitalWrite(Pin(GPIO_PWM1, index), LOW); // 1000µs to ensure not to fire on the next sinus wave if (dimm_time < (1000000 / Settings.pwm_frequency)-1000) { From ce7070b0a5c26354de894e96ce5fa4b2b496deaf Mon Sep 17 00:00:00 2001 From: stefanbode Date: Tue, 7 Jul 2020 16:26:44 +0200 Subject: [PATCH 4/5] Update xsns_01_counter.ino --- tasmota/xsns_01_counter.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 54463648f..fb61a05d6 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -81,9 +81,8 @@ void CounterUpdate(uint8_t index) if bitRead(Counter.pin_state, index) { // PWMfrequency 100 // restart PWM each second (german 50Hz has to up to 0.01% deviation) - // set COUNTERDEBOUNCELOW 1 to catch the raising edge // Zero-HIGH is typical 2ms - if (bitRead(Counter.pin_state, index) && Settings.flag4.zerocross_dimmer) { + if (RtcSettings.pulse_counter[index]%100 == 0 && PinUsed(GPIO_PWM1, index) && Settings.flag4.zerocross_dimmer) { const uint32_t current_cycle = ESP.getCycleCount(); // stop pwm on PIN to start in Sync with rising edge // calculate timeoffset to fire PWM From 90f29695bbba0aa957fe192b226cf569ac03a5c5 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Tue, 7 Jul 2020 16:31:35 +0200 Subject: [PATCH 5/5] Update xsns_01_counter.ino --- tasmota/xsns_01_counter.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index fb61a05d6..ae03ef324 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -166,7 +166,7 @@ void CounterInit(void) if (PinUsed(GPIO_CNTR1, i)) { Counter.any_counter = true; pinMode(Pin(GPIO_CNTR1, i), bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP); - if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high)) { + if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high) && !Settings.flag4.zerocross_dimmer) { Counter.pin_state = 0; attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], FALLING); } else {