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; 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); + } } } } diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index c3584f111..ae03ef324 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -81,13 +81,13 @@ 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 (RtcSettings.pulse_counter[index]%100 == 0 && PinUsed(GPIO_PWM1, index)) { + 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 - 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) { @@ -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 {