Skip to content

Commit

Permalink
Fix waveform missing edges on cycle rollover (#4945)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
earlephilhower authored Jul 22, 2018
1 parent 3906ee4 commit bde83e8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 200 deletions.
192 changes: 0 additions & 192 deletions cores/esp8266/core_esp8266_sigma_delta.c.unused

This file was deleted.

10 changes: 2 additions & 8 deletions cores/esp8266/core_esp8266_waveform.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ static inline ICACHE_RAM_ATTR uint32_t min_u32(uint32_t a, uint32_t b) {
return b;
}

static inline ICACHE_RAM_ATTR uint32_t min_s32(int32_t a, int32_t b) {
if (a < b) {
return a;
}
return b;
}

static inline ICACHE_RAM_ATTR void ReloadTimer(uint32_t a) {
// Below a threshold you actually miss the edge IRQ, so ensure enough time
if (a > 32) {
Expand Down Expand Up @@ -251,7 +244,8 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {

// Check for toggles
now = GetCycleCount();
if (now >= wave->nextServiceCycle) {
int32_t cyclesToGo = wave->nextServiceCycle - now;
if (cyclesToGo < 0) {
wave->state = !wave->state;
if (wave->state) {
SetGPIO(wave->gpioMask);
Expand Down

0 comments on commit bde83e8

Please sign in to comment.