-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
analogWrite is reset to the minimum or maximum value #4944
Comments
@X-Stas-EEE I'll try and repro and look at this tonight. If you have the chance, could you add a |
@earlephilhower OK, I'll run the test again with this line. Hope the bug will be caught this night. Otherwise, I'll leave the ESP running for a couple of days. I will not be able to observe the execution of the test this weekend. |
@earlephilhower The bug is still there, even with the Wi-Fi switched off. The modified sketch: #include <ESP8266WiFi.h>
#define LED_PIN D1 // GPIO5
#define BUZ_PIN D2 // GPIO4
int bright;
bool increase;
int note;
unsigned long cur_millis = millis();
unsigned long prev_millis = cur_millis;
void setup() {
WiFi.mode(WIFI_OFF);
Serial.begin(115200);
Serial.print("\n\nSDK Version=");
Serial.println(ESP.getCoreVersion());
pinMode(LED_PIN, OUTPUT);
pinMode(BUZ_PIN, OUTPUT);
bright = 0;
increase = true;
}
void loop() {
cur_millis = millis();
if (abs(cur_millis - prev_millis) > 100) {
analogWrite(LED_PIN, bright);
if (increase) {
bright++;
} else {
bright--;
}
if (bright >= 105) {
increase = false;
} else if (bright <= 10) {
increase = true;
}
prev_millis = cur_millis;
tone(BUZ_PIN, (double)bright+200, 85);
}
} |
Thanks! I think this is related to Arduino/cores/esp8266/core_esp8266_waveform.c Line 254 in 3906ee4
I should be subtracting the two values and checking for <0. As-is, I think I can make it fail by making nextservicecycle = 2^32-1 cycles and the ESP cycle counter overflowing before I get to handfle it. In that case, this edge will not be caught because now=1 , which is past the service time but < nextservicecycle .
I will try and repro the failure on my system tonight, then do the fix and see if it lasts a full day. |
Was able to catch it after only ~25 minutes of runtime. It has a chance of self-correcting every 2^32/80M = ~53 seconds due to counter wraparound. Just did the fix (1-liner) and restarted and started my logic analyzer. With any luck the USB analyzer will run overnight and not crash (crappy analyzer, unrelated to the code or ESP8266!) and I can dump and post-process to verify no PWM freezes. |
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 esp8266#4944 Also remove the "sigma-delta.c.unused" file which was replaced by a working one some time ago.
The logic analyzer only captured ~2.5hrs before stopping, but analysis of that time shows it was clean, and the LED was still fading in and out this morning, so I think we've got a fix! Please give PR #4945 a try, @X-Stas-EEE. |
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.
@earlephilhower |
Cool, looking fwd. to the update! FWIW the brightness levels should be absolutely unaffected, the change was related to it missing an edge when the edge happened near a timer wraparound (~every minute IIRC) which would end up causing a full-on or full-off until (at least) the next time the wraparound occurred. Pretty obvious problem in the code, but only hit in cases when the interrupt was a little late (due to other things, like add'l waveforms). |
Everithing looks good so far. I've deleted my previous comment because it contained erroneous information. |
@earlephilhower I confirm that the bug has been fixed! Thanks a lot for your work! |
Platform
Settings in IDE
Problem Description
AnalogWrite is reset to zero or maximum value. The plugged led gets stuck on the maximum PWM level or turns off. At the same time the buzzer continues to play sounds. Thus, it becomes clear that the module does not hang. To replicate the problem run the attached code and wait for a while. It may take a few hours. The problem is mentioned in #4640
Sketch
Debug Messages
The text was updated successfully, but these errors were encountered: