run arduino mega 2560 at lower speed

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not sure if I am at the right forums, but sine it's a atmega2560, I post my question here.

Say if I write some code in Arduino IDE, and set the CPU_F to say 1MHz in the Arduino IDE, and upload the code to Arduino Mega 2560 with a programmer(wipe out the bootloader), will I still get the right time? eg delay and URAT com. etc...

My goal is to run the chip in just enough speed to save energy.

Zhuhua Wu - Electronic Engineering Student

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An Arduino has a crystal. Usually it is 16MHz. The chip has the CKSEL fuses to enable the crystal as the clock source. as such the CPu will always run at 16MHz. Just setting some symbol called F_CPU to some other value does not magically change the CPU speed.

There IS one way to change the clock speed however and that is to note that the chip has a register called CLKPR. You can use this to divide the input clock frequency by your choice from 1,2,4,8,16,32,64,128,256. By default (unless the CKDIV8 fuse is active) it is set to /1. If CKDIV8 is active it is set to /8.

By changing CLKPR you can therefore change the CPU speed to be:

16MHz/2 = 8MHz
16MHz/4 = 4MHz
16MHz/8 = 2MHz
16MHz/16 = 1MHz
16MHz/32 = 0.5MHz
16MHz/64 = 0.25MHz
16MHz/128 = 0.125MHz
16MHz/256 = 0.0625MHz

Only once you have added the code to set one of these division factors should you then also set F_CPU to match what the new CPU speed is. It will then be correctly used to set delay times and UART baud rates or whatever else uses F_CPU to calculate a value.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bug13avr wrote:
Say if I write some code in Arduino IDE, and set the CPU_F to say 1MHz in the Arduino IDE, and upload the code to Arduino Mega 2560 with a programmer(wipe out the bootloader), will I still get the right time? eg delay and URAT com. etc...

You won't get anywhere until you improve your spelling !

Yes. You can use to change your clock.

You could also send your AVR to sleep if you want.

I expect that the FTDI chip will probably take a significant amount of power. Unless you have access to 'sending it to sleep' or 'chip-disable' too.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks guys

Zhuhua Wu - Electronic Engineering Student