Is it possible to change clock speed when running sketch?
Low-power lib drops the current consumption from 20mA to 9.5mA at 8MHz, it is still too much. Is there a way how to set clockspeed (for example) to 1MHz, go to sleep, after interrupt wake up, set clockspeed back to the 8Mhz (for 3v3), do some stuff and then go sleep again?
Thanks
1 Answer 1
Absolutely. The built-in prescaler can dynamically change the clock speed for most of the systems on the chip (USB still needs to run at full speed in order to operate properly).
#include <avr/power.h>
...
clock_prescale_set(clock_div_32);
sleep();
clock_prescale_set(clock_div_1);
...
See the datasheet and AVR Libc documentation for more details.
-
Thanks, I've just tryed this, but it didn't help. The power consumption is the same as before.
clock_prescale_set(clock_div_8); attachInterrupt(INTERRUPT_PIN, wokenUp, RISING); LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
Andreisk– Andreisk2017年11月05日 14:22:44 +00:00Commented Nov 5, 2017 at 14:22 -
1Probably because most of the clocks are off in that power mode, so aren't running in the first place.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2017年11月05日 14:23:48 +00:00Commented Nov 5, 2017 at 14:23
-
What should I do then do achieve the lowest power consumption with wake up by interrupt?Andreisk– Andreisk2017年11月05日 14:28:35 +00:00Commented Nov 5, 2017 at 14:28
-
Disable unneeded peripherals. Reduce overall clock speed. It's all in the datasheet and application notes.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2017年11月05日 14:31:39 +00:00Commented Nov 5, 2017 at 14:31
-
Also remove the power led from the Arduino board, as that is also using power without doing anything useful.Gerben– Gerben2017年11月05日 16:52:26 +00:00Commented Nov 5, 2017 at 16:52
Explore related questions
See similar questions with these tags.