-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Sleep and delay() #35
Comments
esp32 or Esp8266?
Back when I implemented this the ESP32 sleep features were not stabile enough to use them. taskmanager.cpp line 110, (for esp8266) adding a delay(n) where n = 0,1,2 would be fine for the idle sleep (light sleep). Something similar for ESP32 should be added. But, this general area is where an automatic idle level sleep would be triggered. |
Sorry, ESP8266. My use case is one where I update an OLED screen every 50ms, so I This is assuming that delaying for longer has power advantages, otherwise I guess just adding a delay of 1 ms in my code would be equivalent. |
I don't believe calling delay causes any power advantage on esp8266. You have to enter sleep to get any advantages; which is an explicit call. But we can ask on the esp8266 Arduino gitter channel and get a quick answer for that. Note that they request calling delay() or yield() when in tight loops. But the way you are supposed to call the taskmanager.Loop() within the sketches loop() means that it quickly enters and leaves the sketches loop() and thus there is no need to call delay() or yield(). |
If you're on light sleep, calling delay does save power, it took me from 80 mA down to 60ish. In another program I wrote that used the Task library, I noticed that some interrupts wouldn't get processed sometimes unless I called |
What about calling delay(0) or just yield()? If either of these will cause the same ma drop, then I would be all in for putting that into the location I mentioned above. |
I will measure various delays and report back, though I think it only benefits the CPU for the amount of time it's sleeping. Will check, though. |
Alright, so:
Unfortunately I don't have very reliable equipment, these tests were done with a Ruideng UM25C USB meter, so the refresh frequency is pretty low. Anything under 20 was pretty spiky, though, so I ended up setting the delay to 20ms for my needs. If you want to look at the code, it's here: https://gitlab.com/stavros/do-not-be-alarmed |
Ok, with this knowledge, then I would not include it in my library. BUT it does warrant a FAQ entry in the wiki and maybe an update to the samples to include a delay(1) with a comment in the main loop() after calling taskmanager.Loop(). like
|
That works, I was mainly wondering because you advise against calling My other question would be if, since you know when the next task is going to run, you could |
It does know "the time interval to the next task".
|
Ah okay, I don't know why this is a problem but maybe you could just skip the delay if it's less than a few ms, where it wouldn't be effective anyway?
Yes, I do this in other applications and this would definitely need to be an option when instantiating.
This is very likely (although I think even Arduino recommends adding a Either way, this isn't a big deal, I can just |
I really think you should put together a minimal sketch (without task) and check an empty loop versus a loop with a delay(1) and then go to the esp8266 team and ask why this is so. Since they are calling loop, they already service all the normal things behind the scenes. |
Feature request: Expose a user provided feature to inject action when next task is greater than wait period and would possibly enter an "idle mode" for N milliseconds. Today AVR will enter a sleep mode but other architectures it maybe more sketch specific as outlined above. |
I'm using this excellent library to run tasks, but I want the ESP to sleep otherwise. I have implemented light sleep, but that only runs on a
delay()
call. If my fastest task is 50ms and I don't care about accuracy (I'm fine being 20ms over), can I add a 20msdelay()
call in the loop? The only other thing that runs is the Task scheduler.Would it be possible to have Task optionally call
delay()
in its downtime, so I don't have to do it?The text was updated successfully, but these errors were encountered: