@@ -331,20 +331,20 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
331
331
const uint32_t overshootCcys = now - ((waveform.states & (1UL << pin)) ? wave.endDutyCcy : wave.nextPeriodCcy );
332
332
const uint32_t fwdPeriods = static_cast <uint32_t >(overshootCcys) >= idleCcys ?
333
333
((overshootCcys + wave.dutyCcys ) / wave.periodCcys ) : 0 ;
334
- const uint32_t fwdPeriodCcys = fwdPeriods * wave.periodCcys ;
335
334
uint32_t nextEdgeCcy;
336
335
if (waveform.states & (1UL << pin)) {
337
336
// up to and including this period 100% duty
338
337
const bool endOfPeriod = wave.nextPeriodCcy == wave.endDutyCcy ;
339
338
// active configuration and forward 100% duty
340
339
if (!idleCcys) {
341
- wave.nextPeriodCcy += fwdPeriodCcys ;
340
+ wave.nextPeriodCcy += fwdPeriods * wave. periodCcys ;
342
341
wave.endDutyCcy = wave.nextPeriodCcy ;
343
342
nextEdgeCcy = wave.nextPeriodCcy ;
344
343
}
345
344
else if (endOfPeriod) {
346
345
// preceeding period had zero idle cycle, continue direct into new duty cycle
347
- if (fwdPeriods) {
346
+ if (fwdPeriods >= 2 ) {
347
+ const uint32_t fwdPeriodCcys = (fwdPeriods - 1 ) * wave.periodCcys ;
348
348
wave.nextPeriodCcy += fwdPeriodCcys;
349
349
// adapt expiry such that it occurs during intended cycle
350
350
if (WaveformMode::EXPIRES == wave.mode )
@@ -379,14 +379,15 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
379
379
}
380
380
else {
381
381
if (!wave.dutyCcys ) {
382
- wave.nextPeriodCcy += fwdPeriodCcys + wave.periodCcys ;
382
+ wave.nextPeriodCcy += (fwdPeriods + 1 ) * wave.periodCcys ;
383
383
wave.endDutyCcy = wave.nextPeriodCcy ;
384
384
}
385
385
else {
386
386
waveform.states ^= 1UL << pin;
387
387
wave.nextPeriodCcy += wave.periodCcys ;
388
388
wave.endDutyCcy = now + wave.dutyCcys ;
389
389
if (fwdPeriods) {
390
+ const uint32_t fwdPeriodCcys = fwdPeriods * wave.periodCcys ;
390
391
wave.nextPeriodCcy += fwdPeriodCcys;
391
392
if (wave.autoPwm ) {
392
393
// maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods
0 commit comments