@@ -359,13 +359,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
359
359
waveNextEventCcy = wave.endDutyCcy = wave.nextPeriodCcy ;
360
360
}
361
361
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 );
366
364
// adapt expiry such that it occurs during intended cycle
367
365
if (WaveformMode::EXPIRES == wave.mode )
368
- wave.expiryCcy += adj * wave.periodCcys ;
366
+ wave.expiryCcy += scaleCcys ( wave.periodCcys ) ;
369
367
}
370
368
else {
371
369
waveNextEventCcy = wave.nextPeriodCcy ;
@@ -387,15 +385,7 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
387
385
wave.nextPeriodCcy += scaleCcys (wave.periodCcys );
388
386
wave.endDutyCcy = now + scaleCcys (wave.dutyCcys );
389
387
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 ;
399
389
}
400
390
waveform.states |= pinBit;
401
391
if (16 == pin) {
0 commit comments