Too much digital input polling causing WDT reset?
Posted: Tue Nov 01, 2016 6:26 pm
I'm polling pin D4 frequently and I think its causing:
Soft WDT reset
ctx: cont
Its for a POV set up and I'm trying to calculate the speed of rotation so I can set a variable delay to adjust the speed of the LED fill routine.
I have a couple of delay(0); statements which solved my previous WDT crashes but when I introduced the polling it started happening again.
Working out roughly in my head I could be polling the pin roughly twice a ms in an extreme case. Is this too much? Perhaps I should use an interrupt but I was worried about problems with the wifi.
I won't post my whole sketch but here is the main loop and the two helper functions it uses. The rest is just variable definitions, wifi and LED set up.
Soft WDT reset
ctx: cont
Its for a POV set up and I'm trying to calculate the speed of rotation so I can set a variable delay to adjust the speed of the LED fill routine.
I have a couple of delay(0); statements which solved my previous WDT crashes but when I introduced the polling it started happening again.
Working out roughly in my head I could be polling the pin roughly twice a ms in an extreme case. Is this too much? Perhaps I should use an interrupt but I was worried about problems with the wifi.
I won't post my whole sketch but here is the main loop and the two helper functions it uses. The rest is just variable definitions, wifi and LED set up.
Code: Select all
void reedSwitch() { //routine when one revolution is detected
variableDelay = ((millis() - lasttime - CYCLETIME) * 1000) / 176; //calculate variable delay to make one image frame = approximately one revolution
constrain (variableDelay, 0, 2000); //constrain delay because of worries about watchdog timer!
butToggle = false; //set toggle for repeated reed switch readings
goback = true; //set toggle for running the LED routine next time around
}
void sickLED(int vd) {
lasttime = millis();
goback = false; //set toggle
int f = numberOfSlices;
int z; //a counter
for (int x = 0; x < f; x++) {
for (z = 0; z < 48; z++) {
leds[z + 13] = monroe[(x * 48) + (z)]; //fill led array from a larger array of image data
}
FastLED.show(); //send data to pixels
delay(0); //keep the watchdog timer happy
if (!digitalRead(pushButton) && butToggle) { //check for reed switch activation. If it is closed set toggles and exit draw routing
reedSwitch();
delay(0);
return;
} else {
if (digitalRead(pushButton)) {
butToggle = true;
}
}
//1500 fan sppeed 1 ~ 4 rps
//800 fan speed 2 ~ 6 rps
//565 fan speed 3
delayMicroseconds(vd); //may need to increase / decrease depending on spin rate
}
void loop() {
ArduinoOTA.handle(); //system call
if (goback) sickLED(variableDelay); //if toggle set, run the routine which sets a frame of LEDS
if (!digitalRead(pushButton) && butToggle) { //if reed switch newly activated......
reedSwitch();
} else {
if (digitalRead(pushButton)) { //if reed switch is closed
butToggle = true; //set toggle
FastLED.clear(); // clear leds
FastLED.show();
}
}
if ((millis() - lasttime) > 5000) {
FastLED.clear();
FastLED.show();
}
}
}