mirror of https://github.com/arendst/Tasmota.git
Fix PWM flickering during wifi connection (#8046)
This commit is contained in:
parent
8b7aca39f2
commit
11746d942e
|
@ -14,6 +14,7 @@
|
||||||
- Add command ``SetOption91 1`` to enable fading at startup / power on
|
- Add command ``SetOption91 1`` to enable fading at startup / power on
|
||||||
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
|
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
|
||||||
- Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189)
|
- Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189)
|
||||||
|
- Fix PWM flickering during wifi connection (#8046)
|
||||||
|
|
||||||
### 8.2.0.2 20200328
|
### 8.2.0.2 20200328
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
|
||||||
// cyclesToGo = -((-cyclesToGo) % (wave->nextTimeHighCycles + wave->nextTimeLowCycles));
|
// cyclesToGo = -((-cyclesToGo) % (wave->nextTimeHighCycles + wave->nextTimeLowCycles));
|
||||||
//
|
//
|
||||||
// Alternative version with lower CPU impact:
|
// Alternative version with lower CPU impact:
|
||||||
// while (-cyclesToGo > wave->nextTimeHighCycles + wave->nextTimeLowCycles) { cyclesToGo += wave->nextTimeHighCycles + wave->nextTimeLowCycles)};
|
// while (-cyclesToGo > wave->nextTimeHighCycles + wave->nextTimeLowCycles) { cyclesToGo += wave->nextTimeHighCycles + wave->nextTimeLowCycles); }
|
||||||
|
//
|
||||||
|
// detect interrupt storm, for example during wifi connection.
|
||||||
|
// if we overshoot the cycle by more than 25%, we forget phase and keep PWM duration
|
||||||
|
int32_t overshoot = (-cyclesToGo) > ((wave->nextTimeHighCycles + wave->nextTimeLowCycles) >> 2);
|
||||||
waveformState ^= mask;
|
waveformState ^= mask;
|
||||||
if (waveformState & mask) {
|
if (waveformState & mask) {
|
||||||
if (i == 16) {
|
if (i == 16) {
|
||||||
|
@ -282,16 +286,26 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
|
||||||
} else {
|
} else {
|
||||||
SetGPIO(mask);
|
SetGPIO(mask);
|
||||||
}
|
}
|
||||||
wave->nextServiceCycle += wave->nextTimeHighCycles;
|
if (overshoot) {
|
||||||
nextEventCycles = min_u32(nextEventCycles, max_32(wave->nextTimeHighCycles + cyclesToGo, microsecondsToClockCycles(1)));
|
wave->nextServiceCycle = now + wave->nextTimeHighCycles;
|
||||||
|
nextEventCycles = min_u32(nextEventCycles, wave->nextTimeHighCycles);
|
||||||
|
} else {
|
||||||
|
wave->nextServiceCycle += wave->nextTimeHighCycles;
|
||||||
|
nextEventCycles = min_u32(nextEventCycles, max_32(wave->nextTimeHighCycles + cyclesToGo, microsecondsToClockCycles(1)));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (i == 16) {
|
if (i == 16) {
|
||||||
GP16O &= ~1; // GPIO16 write slow as it's RMW
|
GP16O &= ~1; // GPIO16 write slow as it's RMW
|
||||||
} else {
|
} else {
|
||||||
ClearGPIO(mask);
|
ClearGPIO(mask);
|
||||||
}
|
}
|
||||||
wave->nextServiceCycle += wave->nextTimeLowCycles;
|
if (overshoot) {
|
||||||
nextEventCycles = min_u32(nextEventCycles, max_32(wave->nextTimeLowCycles + cyclesToGo, microsecondsToClockCycles(1)));
|
wave->nextServiceCycle = now + wave->nextTimeLowCycles;
|
||||||
|
nextEventCycles = min_u32(nextEventCycles, wave->nextTimeLowCycles);
|
||||||
|
} else {
|
||||||
|
wave->nextServiceCycle += wave->nextTimeLowCycles;
|
||||||
|
nextEventCycles = min_u32(nextEventCycles, max_32(wave->nextTimeLowCycles + cyclesToGo, microsecondsToClockCycles(1)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint32_t deltaCycles = wave->nextServiceCycle - now;
|
uint32_t deltaCycles = wave->nextServiceCycle - now;
|
||||||
|
|
Loading…
Reference in New Issue