Fix PWM flickering during wifi connection (#8046)

This commit is contained in:
Stephan Hadinger 2020-04-07 22:18:29 +02:00
parent 8b7aca39f2
commit 11746d942e
2 changed files with 20 additions and 5 deletions

View File

@ -14,6 +14,7 @@
- Add command ``SetOption91 1`` to enable fading at startup / power on
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
- Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189)
- Fix PWM flickering during wifi connection (#8046)
### 8.2.0.2 20200328

View File

@ -274,7 +274,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
// cyclesToGo = -((-cyclesToGo) % (wave->nextTimeHighCycles + wave->nextTimeLowCycles));
//
// 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;
if (waveformState & mask) {
if (i == 16) {
@ -282,17 +286,27 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
} else {
SetGPIO(mask);
}
if (overshoot) {
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 {
if (i == 16) {
GP16O &= ~1; // GPIO16 write slow as it's RMW
} else {
ClearGPIO(mask);
}
if (overshoot) {
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 {
uint32_t deltaCycles = wave->nextServiceCycle - now;
nextEventCycles = min_u32(nextEventCycles, deltaCycles);