mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Merge pull request #8868 from stefanbode/patch-15
Fixed reboot on zero cross dimmer
This commit is contained in:
commit
b140467bbf
@ -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;
|
||||
|
@ -2185,10 +2185,12 @@ 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
|
||||
}
|
||||
if (!Settings.flag4.zerocross_dimmer) {
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// char msg[24];
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("LGT: Channels %s"), ToHex_P((const unsigned char *)cur_col_10, 10, msg, sizeof(msg)));
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user