I am trying to lower the clockspeed to save some power on my project since it will be powered by a 3.7v Lithium battery.
My question is do I just go into the AVR Folder and under boards.txt and change "leonardo.build.f_cpu=16000000L" to "leonardo.build.f_cpu=8000000L"?
Do I also need to do something in the code to allow for the clock change so the timings are accurate? Sorry I am new to this board, my teensy just let me change it via the program.
Lowering the clock speed does not do much to save battery power, as computations take proportionally longer. It is much, much better to use sleep modes instead. Take a look at the Low Power libraries, and read up on sleep modes.
Alternatively, if your project allows it, you can use a power timer to power up the project at regular intervals to do some task, then shut it down again.
Is that how I would go about doing it though? I think it should cut the draw about 30%. I understand thats not as large as it could be but I dont actually need to run any operation other than a timer after the first hour of power up.
I need it to be idle but counting for 24 hours at a time. I need millis() to function if possible. every day it will have a 1 min function then it can go back to a sleep mode until then. I have looked at the low power library but need to read up on that. I would prefer to not use an external timer since the functions will change based on day.
Probably not. F_CPU normally reflects the hardware (crystal, fuses, etc) configuration, but doesn't do anything to actually CHANGE the clock frequency.
I don't know if you can change the crystal and still have USB uploads work properly.
You could presumably manually set "CLKPR – Clock Prescaler Register" in setup() to create a lower system clock speed, in which case changing the build.f_cpu variable would probably be the correct thing to do to let the rest of the Arduino core know that you've done so...
Hey, thanks for the response. I believe I had read that 8mhz is still usb uploadable. This would be my first time trying to attempt this.
I read in the Atmel AVR manual that clock divider is possible. I see that 0000 is standard and 0001 is divided by 2. I am unsure how to go about applying this in the setup... Have you done this before or know how to call it out?
Everything you need to know is in section 6 of the ATmega32U4 data sheet (System Clock and Clock Options).
However, if you change the clock divider without informing the Arduino IDE, UART serial communications, millis() and micros() will not function as expected, and there may be other consequences. Basically, any function that makes timing assumptions based on the preset F_CPU will be wrong.
I'm not familiar with your board. I don't think that it's you're intention to replace the crystal you need to be aware that if you replace the crystal, you will also need a different bootloader and a different core; the SparkFun AVR board package will give you that option.