-->
Page 1 of 1

SOLVED: Possible error: analogWrite/PWM from Arduino IDE

PostPosted: Wed Nov 25, 2015 6:47 pm
by ArnieO
Using analogWrite(GPIO, value) to a GPIO pin gives a PWM signal that can be used for instance to fade LEDs.
It has 10 bit resolution, input values ranging from 0 through 1023.
So far so good.
However, I see instabilities for the highest values:
1023: OK, gives a flat signal
In the range 1022 down to around 1010 the signal becomes unstable, with short bursts of wrong pulses at seemingly random intervals from half a second to several seconds.
From around 1010 and downwards, it seems to be stable.
Has anyone else seen this?
I think it might be an error in the Arduino IDE compiler, as I am running several LED faders programmed with LUA, and I have never seen this issue on those modules.

Re: Possible error: analogWrite from Arduino IDE to make PWM

PostPosted: Thu Nov 26, 2015 3:45 pm
by ArnieO
After some searching, I found this is a known issue: https://github.com/esp8266/Arduino/issues/836

I found a workaround that gets rid of the flickering on my ESP-03: Reduce the PWM frequency to 200 Hz:
Code: Select allanalogWriteFreq(200);

I found this to be the highest frequency that avoided flickering on my ESP-03. Other modules might need an other frequency, so you might need to do some trials.