8000 Let duty cycle overshoot correction depend on relative impact compare… · dok-net/arduino-esp8266@a2db0c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2db0c4

Browse files
committed
Let duty cycle overshoot correction depend on relative impact compareed to both period and duty.
1 parent de8201d commit a2db0c4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cores/esp8266/core_esp8266_waveform.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys,
164164
}
165165
// sanity checks, including mixed signed/unsigned arithmetic safety
166166
if ((pin > 16) || isFlashInterfacePin(pin) || (alignPhase > 16) ||
167-
static_cast<int32_t>(periodCcys) <= 0 || highCcys > periodCcys) {
167+
static_cast<int32_t>(periodCcys) <= 0 ||
168+
(periodCcys >> 6) == 0 ||
169+
highCcys > periodCcys) {
168170
return false;
169171
}
170172
Waveform& wave = waveform.pins[pin];
@@ -355,8 +357,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
355357
wave.nextPeriodCcy += wave.periodCcys;
356358
nextEdgeCcy = wave.endDutyCcy;
357359
}
358-
else if (wave.autoPwm && (overshootCcys << 6) > wave.periodCcys && wave.nextEventCcy == wave.endDutyCcy) {
359-
uint32_t adjPeriods = (overshootCcys << 6) / wave.periodCcys;
360+
else if (wave.autoPwm &&
361+
overshootCcys >= (wave.periodCcys >> 6) &&
362+
overshootCcys >= (wave.dutyCcys >> 3) &&
363+
wave.nextEventCcy == wave.endDutyCcy) {
364+
uint32_t adjPeriods = overshootCcys / (wave.periodCcys >> 6);
360365
wave.nextPeriodCcy += adjPeriods * wave.periodCcys;
361366
// adapt expiry such that it occurs during intended cycle
362367
if (WaveformMode::EXPIRES == wave.mode) {

0 commit comments

Comments
 (0)
0