Skip to content

Commit bde83e8

Browse files
Fix waveform missing edges on cycle rollover (#4945)
When the ESP cycle counter rolls over, the "now" can be smaller than the next-edge time of a waveform generator. This would cause the edge to be missed on that specific pin, and make it look like PWM was hung. Use proper comparison between current time and edge time. Fixes #4944 Also remove the "sigma-delta.c.unused" file which was replaced by a working one some time ago.
1 parent 3906ee4 commit bde83e8

File tree

2 files changed

+2
-200
lines changed

2 files changed

+2
-200
lines changed

cores/esp8266/core_esp8266_sigma_delta.c.unused

-192
This file was deleted.

cores/esp8266/core_esp8266_waveform.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ static inline ICACHE_RAM_ATTR uint32_t min_u32(uint32_t a, uint32_t b) {
102102
return b;
103103
}
104104

105-
static inline ICACHE_RAM_ATTR uint32_t min_s32(int32_t a, int32_t b) {
106-
if (a < b) {
107-
return a;
108-
}
109-
return b;
110-
}
111-
112105
static inline ICACHE_RAM_ATTR void ReloadTimer(uint32_t a) {
113106
// Below a threshold you actually miss the edge IRQ, so ensure enough time
114107
if (a > 32) {
@@ -251,7 +244,8 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
251244

252245
// Check for toggles
253246
now = GetCycleCount();
254-
if (now >= wave->nextServiceCycle) {
247+
int32_t cyclesToGo = wave->nextServiceCycle - now;
248+
if (cyclesToGo < 0) {
255249
wave->state = !wave->state;
256250
if (wave->state) {
257251
SetGPIO(wave->gpioMask);

0 commit comments

Comments
 (0)