mirror of https://github.com/arendst/Tasmota.git
Update xsns_01_counter.ino
This commit is contained in:
parent
2d3d4863b4
commit
c11e948b81
|
@ -44,6 +44,9 @@ struct COUNTER {
|
|||
bool any_counter = false;
|
||||
} Counter;
|
||||
|
||||
uint32_t last_cycle;
|
||||
uint32_t cycle_time;
|
||||
|
||||
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception
|
||||
void CounterUpdate(uint8_t index) ICACHE_RAM_ATTR;
|
||||
void CounterUpdate1(void) ICACHE_RAM_ATTR;
|
||||
|
@ -75,7 +78,32 @@ void CounterUpdate(uint8_t index)
|
|||
Counter.timer_low_high[index] = time;
|
||||
Counter.pin_state ^= (1<<index);
|
||||
// do not count on rising edge
|
||||
if bitRead(Counter.pin_state, index) return;
|
||||
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)) {
|
||||
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;
|
||||
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) {
|
||||
delayMicroseconds(dimm_time);
|
||||
// fire small PWM signal to start TRIAC/SSR. Kill on next
|
||||
// zero phase automatic.
|
||||
// calculate actual cycle time and adapt frequency im milli Hz steps
|
||||
// add 100.000 cpu ticks to ensure right step calculation
|
||||
uint32_t steps = (current_cycle-last_cycle+100000)/(clockCyclesPerMicrosecond() * 10000);
|
||||
cycle_time = (current_cycle-last_cycle)/steps;
|
||||
analogWriteCCyPeriod(Pin(GPIO_PWM1, index), 5, cycle_time );
|
||||
}
|
||||
last_cycle = current_cycle;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
debounce_time = time - Counter.timer[index];
|
||||
|
|
Loading…
Reference in New Issue