@@ -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