@@ -318,9 +318,9 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
318
318
}
319
319
uint32_t nextEdgeCcy;
320
320
if (waveform.states & (1UL << pin)) {
321
- // up to and including this period 100% duty
321
+ // up to and including this period 100% duty
322
322
const bool endOfPeriod = wave.nextPeriodCcy == wave.endDutyCcy ;
323
- // active configuration and forward 100% duty
323
+ // active configuration and forward 100% duty
324
324
if (!idleCcys) {
325
325
wave.nextPeriodCcy += (fwdPeriods + 1 ) * wave.periodCcys ;
326
326
wave.endDutyCcy = wave.nextPeriodCcy ;
@@ -333,15 +333,9 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
333
333
wave.nextPeriodCcy += wave.periodCcys ;
334
334
nextEdgeCcy = wave.endDutyCcy ;
335
335
}
336
- else if (fwdPeriods) {
337
- // maintain phase, maintain duty/idle ratio, temporarily reduce frequency by skipPeriods
338
- fwdPeriods = (overshootCcys + wave.periodCcys ) / wave.dutyCcys ;
339
- wave.endDutyCcy += fwdPeriods * wave.dutyCcys ;
340
- wave.nextPeriodCcy += fwdPeriods * wave.periodCcys ;
341
- nextEdgeCcy = wave.endDutyCcy ;
342
- }
343
336
else {
344
337
waveform.states ^= 1UL << pin;
338
+ // the idle cycle code updating for the next period will approximate the duty/idle ratio.
345
339
nextEdgeCcy = wave.nextPeriodCcy + overshootCcys;
346
340
if (pin == 16 ) {
347
341
GP16O &= ~1 ; // GPIO16 write slow as it's RMW
@@ -360,7 +354,7 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
360
354
waveform.states ^= 1UL << pin;
361
355
if (fwdPeriods)
362
356
{
363
- // maintain phase, maintain duty/idle ratio, temporarily reduce frequency by skipPeriods
357
+ // maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods
364
358
wave.endDutyCcy =
365
359
wave.nextPeriodCcy + (fwdPeriods + 1 ) * wave.dutyCcys +
366
360
(overshootCcys + wave.dutyCcys - fwdPeriods * wave.periodCcys );
0 commit comments