Update xsns_01_counter.ino

This commit is contained in:
stefanbode 2020-07-07 16:22:55 +02:00 committed by GitHub
parent debd2b7562
commit 7c2d9673a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,11 +83,12 @@ void CounterUpdate(uint8_t index)
// restart PWM each second (german 50Hz has to up to 0.01% deviation) // restart PWM each second (german 50Hz has to up to 0.01% deviation)
// set COUNTERDEBOUNCELOW 1 to catch the raising edge // set COUNTERDEBOUNCELOW 1 to catch the raising edge
// Zero-HIGH is typical 2ms // 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(); const uint32_t current_cycle = ESP.getCycleCount();
// stop pwm on PIN to start in Sync with rising edge // stop pwm on PIN to start in Sync with rising edge
// calculate timeoffset to fire PWM // 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); digitalWrite(Pin(GPIO_PWM1, index), LOW);
// 1000µs to ensure not to fire on the next sinus wave // 1000µs to ensure not to fire on the next sinus wave
if (dimm_time < (1000000 / Settings.pwm_frequency)-1000) { if (dimm_time < (1000000 / Settings.pwm_frequency)-1000) {