performance power consumption in loop thread

securet
Posts: 2
Joined: Fri Apr 19, 2019 11:22 pm

performance power consumption in loop thread

Postby securet » Wed May 01, 2019 4:10 pm

hi,

when I wait for something in the main loop like:

Code: Select all

void loop() {

	if(boolValue){ //boolvalue normall is false
	//do something
	}
}
would it spare a lot of power if I add some delay in the loop like:

Code: Select all

void loop() {

	if(boolValue){ //boolvalue normall is false
	//do something
	}

//added delay
delay(10);

}
or does the compiler or processor automatically detect the situation and throttle down and there is no need for the delay?

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: performance power consumption in loop thread

Postby boarchuz » Thu May 02, 2019 8:15 am

The underlying FreeRTOS scheduler can save a bit of juice if there are no active tasks, but I'm not sure if this is implemented in Arduino yet. Assume it will be one day if it isn't already.
You're right that looping over that boolean won't do the trick, the task will just be very busy checking it. delay() will work, but it would be even better to use a semaphore or event group (assuming this boolean is normally set in an interrupt or another task or something?).

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: performance power consumption in loop thread

Postby ESP_Angus » Fri May 03, 2019 1:51 am

boarchuz is right.

To save power when the CPU is idle (no task is running), the "automatic light sleep" / "tickless idle" options have to be enabled in the project config. Arduino doesn't currently enable these features.

If you switch to ESP-IDF, you can enable these in your project.

Who is online

Users browsing this forum: No registered users and 66 guests