0

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

asked Nov 5, 2017 at 13:57

1 Answer 1

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.

answered Nov 5, 2017 at 14:08
5
  • 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); Commented Nov 5, 2017 at 14:22
  • 1
    Probably because most of the clocks are off in that power mode, so aren't running in the first place. Commented Nov 5, 2017 at 14:23
  • What should I do then do achieve the lowest power consumption with wake up by interrupt? Commented Nov 5, 2017 at 14:28
  • Disable unneeded peripherals. Reduce overall clock speed. It's all in the datasheet and application notes. Commented 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. Commented Nov 5, 2017 at 16:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.