8000 Fixing overshoot mitigation, 3x 880Hz, 256 states now. · dok-net/arduino-esp8266@8c7841d · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8c7841d

Browse files
committed
Fixing overshoot mitigation, 3x 880Hz, 256 states now.
1 parent 2b6838a commit 8c7841d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cores/esp8266/core_esp8266_waveform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
332332
wave.nextPeriodCcy += wave.periodCcys;
333333
nextEdgeCcy = wave.endDutyCcy = wave.nextPeriodCcy;
334334
}
335-
else if (wave.autoPwm && now >= wave.nextPeriodCcy) {
336-
const uint32_t adj = 2 + ((overshootCcys / wave.periodCcys) << 1);
335+
else if (wave.autoPwm && static_cast<int32_t>(now - wave.nextPeriodCcy) >= 0) {
336+
const uint32_t adj = (overshootCcys + wave.dutyCcys) / wave.periodCcys;
337337
// maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods
338338
nextEdgeCcy = wave.endDutyCcy = wave.nextPeriodCcy + adj * wave.dutyCcys;
339339
wave.nextPeriodCcy += adj * wave.periodCcys;
@@ -360,8 +360,8 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
360360
else {
361361
wave.nextPeriodCcy += wave.periodCcys;
362362
wave.endDutyCcy = now + wave.dutyCcys;
363-
if (overshootCcys >= wave.dutyCcys) {
364-
const uint32_t adj = 1 + ((overshootCcys / wave.dutyCcys) << 1);
363+
if (static_cast<int32_t>(wave.endDutyCcy - wave.nextPeriodCcy) >= 0) {
364+
const uint32_t adj = (overshootCcys + wave.dutyCcys) / wave.periodCcys;
365365
wave.nextPeriodCcy += adj * wave.periodCcys;
366366
if (wave.autoPwm) {
367367
// maintain phase, maintain duty/idle ratio, temporarily reduce frequency by fwdPeriods

0 commit comments

Comments
 (0)
0