10000 Shorten progression when going off 100% duty. · dok-net/arduino-esp8266@60336ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 60336ba

Browse files
committed
Shorten progression when going off 100% duty.
1 parent c9bf43c commit 60336ba

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cores/esp8266/core_esp8266_waveform.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,20 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
331331
const uint32_t overshootCcys = now - ((waveform.states & (1UL << pin)) ? wave.endDutyCcy : wave.nextPeriodCcy);
332332
const uint32_t fwdPeriods = static_cast<uint32_t>(overshootCcys) >= idleCcys ?
333333
((overshootCcys + wave.dutyCcys) / wave.periodCcys) : 0;
334-
const uint32_t fwdPeriodCcys = fwdPeriods * wave.periodCcys;
335334
uint32_t nextEdgeCcy;
336335
if (waveform.states & (1UL << pin)) {
337336
// up to and including this period 100% duty
338337
const bool endOfPeriod = wave.nextPeriodCcy == wave.endDutyCcy;
339338
// active configuration and forward 100% duty
340339
if (!idleCcys) {
341-
wave.nextPeriodCcy += fwdPeriodCcys;
340+
wave.nextPeriodCcy += fwdPeriods * wave.periodCcys;
342341
wave.endDutyCcy = wave.nextPeriodCcy;
343342
nextEdgeCcy = wave.nextPeriodCcy;
344343
}
345344
else if (endOfPeriod) {
346345
// 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;
348348
wave.nextPeriodCcy += fwdPeriodCcys;
349349
// adapt expiry such that it occurs during intended cycle
350350
if (WaveformMode::EXPIRES == wave.mode)
@@ -379,14 +379,15 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
379379
}
380380
else {
381381
if (!wave.dutyCcys) {
382-
wave.nextPeriodCcy += fwdPeriodCcys + wave.periodCcys;
382+
wave.nextPeriodCcy += (fwdPeriods + 1) * wave.periodCcys;
383383
wave.endDutyCcy = wave.nextPeriodCcy;
384384
}
385385
else {
386386
waveform.states ^= 1UL << pin;
387387
wave.nextPeriodCcy += wave.periodCcys;
388388
wave.endDutyCcy = now + wave.dutyCcys;
389389
if (fwdPeriods) {
390+
const uint32_t fwdPeriodCcys = fwdPeriods * wave.periodCcys;
390391
wave.nextPeriodCcy += fwdPeriodCcys;
391392
if (wave.autoPwm) {
392393
// maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods

0 commit comments

Comments
 (0)
0