I know it's possible to change the clock prescaler at runtime. But is there a way to set the prescaler that is used at boot on an ATMega328? I'm aware of the fuses, but those are pretty permanent. I want it to start up at 8MHz and see if it's running on a lower voltage backup battery first. And if not, then switch to 16MHz. I've tried doing it as the first thing in setup() but it doesn't seem fast enough.

• but, if you select a clock divide by 8, shouldn't F_CPU now be 2MHZ instead of 16MHZ?
– user51817
Aug 22, 2014 at 9:49

I'm aware of the fuses, but those are pretty permanent

You can use the CLKDIV8 fuse, it only controls the preloaded cpu divider value so I don't consider it a permanent change.
The fuse sets the default loaded value to CLKPR (Clock prescale register) to either

• clk/1
• clk/8

Then in your code you can just set the divider to clk/1 to restore the cpu speed to 16MHz

I'm not sure but unless the bootloader is adaptive this change may affect the UART speed and create problems with the Arduino bootloader, this needs to be tested.

I did a test with my Arduino pro mini (m328p). After enabling the CLKDIV8 fuse using an external programmer, the Arduino bootloader becomes unresponsive and I don't see any way to override the UART speed that Arduiono IDE tries to use.

## Updated Solution

I found another solution that doesn't need to change the bootloader, you just create a new profile for the board that has the CLDIV8 fuse enabled.

You need to modify the file boards.txt (e.g. arduino-1.5.5\hardware\arduino\avr\boards.txt), the baud rate for each board is stored there.

Locate the section that refers to your board, for example in my case

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
## -------------------------------------------------



Now copy and paste that section to create a duplicate entry that we are going to modify. In that entry you'll have to change the name so that it doesn't conflict with the existing one (any new name will do), and set the baud rate to 1/8 of the one that was originally used.
I'm showing the changes in bold

The old entry with the new one following it look like this in my case:

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
## -------------------------------------------------

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 CLKDIV8
## -------------------------------------------------