-->
Page 1 of 1

Flicker (glitches) on PWM if more than 2 channels used

PostPosted: Sat Sep 24, 2016 12:06 pm
by snafu
In my setup[1] I have lots of flicker on my PWM outputs driving LEDs. If I use only two channels, everything is fine. If I add one or more channels there are heavy glitches. This happens on all combinations of output ports I tested.

I read about similar problems in the net and here. I lowered PWM frequency with analogWriteFreq(200); even down to 40 Hz, tryed using yield(), nothing helped.

Disabling WiFi is not an option, cause this project is an NTP controlled clock.

Any suggestions?
Thanks in advance!

[1] NodeMCU Board V2, Arduino IDE 1.6.7,

Code: Select all#define QUART1  D3
#define QUART2  D4
#define QUART3  D5
#define QUART4  D6

unsigned int PWM_loop;

void setup() {
  analogWriteFreq(200);     // to avoid flicker due to other interrupts in esp?
  }

void loop()
  { 
  for (int PWM_loop=0; PWM_loop <= 1023; PWM_loop++){
    analogWrite(QUART1, PWM_loop);
    analogWrite(QUART2, PWM_loop);
    analogWrite(QUART3, PWM_loop);
    analogWrite(QUART4, PWM_loop);
    delay(5);
//    yield();
    }

  for (int PWM_loop=1023; PWM_loop >= 0; PWM_loop--){
    analogWrite(QUART1, PWM_loop);
    analogWrite(QUART2, PWM_loop);
    analogWrite(QUART3, PWM_loop);
    analogWrite(QUART4, PWM_loop);
    delay(5);
//    yield();
    }       
  }