8000 Overshoot mitigation w/o PWM frequency change. · dok-net/arduino-esp8266@2eb980b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2eb980b

Browse files
committed
Overshoot mitigation w/o PWM frequency change.
1 parent 3736e9a commit 2eb980b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

cores/esp8266/core_esp8266_waveform.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
359359
waveNextEventCcy = wave.endDutyCcy = wave.nextPeriodCcy;
360360
}
361361
else if (wave.autoPwm && static_cast<int32_t>(now - wave.nextPeriodCcy) >= 0) {
362-
const uint32_t adj = (overshootCcys + scaleCcys(wave.dutyCcys)) / wave.periodCcys;
363-
// maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods
364-
waveNextEventCcy = wave.endDutyCcy = wave.nextPeriodCcy + adj * wave.dutyCcys;
365-
wave.nextPeriodCcy += adj * wave.periodCcys;
362+
waveNextEventCcy = wave.endDutyCcy = wave.nextPeriodCcy + scaleCcys(wave.dutyCcys) - overshootCcys;
363+
wave.nextPeriodCcy += scaleCcys(wave.periodCcys);
366364
// adapt expiry such that it occurs during intended cycle
367365
if (WaveformMode::EXPIRES == wave.mode)
368-
wave.expiryCcy += adj * wave.periodCcys;
366+
wave.expiryCcy += scaleCcys(wave.periodCcys);
369367
}
370368
else {
371369
waveNextEventCcy = wave.nextPeriodCcy;
@@ -387,15 +385,7 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
387385
wave.nextPeriodCcy += scaleCcys(wave.periodCcys);
388386
wave.endDutyCcy = now + scaleCcys(wave.dutyCcys);
389387
if (static_cast<int32_t>(wave.endDutyCcy - wave.nextPeriodCcy) >= 0) {
390-
const uint32_t adj = (overshootCcys + scaleCcys(wave.dutyCcys)) / wave.periodCcys;
391-
wave.nextPeriodCcy += adj * wave.periodCcys;
392-
if (wave.autoPwm) {
393-
// maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods
394-
wave.endDutyCcy += adj * wave.dutyCcys;
395-
}
396-
// adapt expiry such that it occurs during intended cycle
397-
if (WaveformMode::EXPIRES == wave.mode)
398-
wave.expiryCcy += adj * wave.periodCcys;
388+
wave.endDutyCcy = wave.nextPeriodCcy;
399389
}
400390
waveform.states |= pinBit;
401391
if (16 == pin) {

0 commit comments

Comments
 (0)
0