Page 1 of 1

performance power consumption in loop thread

Posted: Wed May 01, 2019 4:10 pm
by securet
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?

Re: performance power consumption in loop thread

Posted: Thu May 02, 2019 8:15 am
by boarchuz
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?).

Re: performance power consumption in loop thread

Posted: Fri May 03, 2019 1:51 am
by ESP_Angus
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.