Control / pause / resume background tasks
Posted: Sat Sep 30, 2017 12:03 pm
Hi all,
TL:DR; I'd like to know if putting WiFi to sleep will stop all background tasks that would otherwise run across loop()s and in wait()s, and if there are any others, how to stop them too.
I’m working on a project that involves controlling a motor using PID control techniques. The code works great with an Arduino Micro, now I'm porting it on an ESP8266 with Arduino platform.
Most of the time the system is idle and ready to accept commands from internet. But sometimes I want the processor to be completely dedicated to one task, i.e. not running any other task, for 4-5 seconds. To be more specific, during those 4-5 seconds a routine in my code should be invoked every 30-31ms.
This because if the PID loop is not run at regular intervals, the motor may spin more than necessary and potentially cause some mechanical damage.
Right now the code runs fine, but I see fairly long pauses (even 4 seconds) every once in a while. This is probably due to the Wi-Fi stack running some background tasks.
I know that the ESP8266 runs several tasks between loop()s and in wait()s. I know that most of them are Wi-Fi related, so I guess that putting the Wi-Fi on sleep will make for more predictable timings.
Is it true? Or are there more time-consuming background tasks? Can I stop them too, without disrupting general functionality of the ESP?
What happens if I simply give no opportunity for these tasks to run, by not returning from loop() and not calling any wait() until my important task is over?
Thanks!
Kind regards,
Enrico
TL:DR; I'd like to know if putting WiFi to sleep will stop all background tasks that would otherwise run across loop()s and in wait()s, and if there are any others, how to stop them too.
I’m working on a project that involves controlling a motor using PID control techniques. The code works great with an Arduino Micro, now I'm porting it on an ESP8266 with Arduino platform.
Most of the time the system is idle and ready to accept commands from internet. But sometimes I want the processor to be completely dedicated to one task, i.e. not running any other task, for 4-5 seconds. To be more specific, during those 4-5 seconds a routine in my code should be invoked every 30-31ms.
This because if the PID loop is not run at regular intervals, the motor may spin more than necessary and potentially cause some mechanical damage.
Right now the code runs fine, but I see fairly long pauses (even 4 seconds) every once in a while. This is probably due to the Wi-Fi stack running some background tasks.
I know that the ESP8266 runs several tasks between loop()s and in wait()s. I know that most of them are Wi-Fi related, so I guess that putting the Wi-Fi on sleep will make for more predictable timings.
Is it true? Or are there more time-consuming background tasks? Can I stop them too, without disrupting general functionality of the ESP?
What happens if I simply give no opportunity for these tasks to run, by not returning from loop() and not calling any wait() until my important task is over?
Thanks!
Kind regards,
Enrico