Go Down

Topic: arduino with internal oscillator on 1Mhz (Read 48230 times) previous topic - next topic

ritzdank

was wondering if i could run arduino with internal oscillator on 1mhz? sure, i have to rewrite fuse-settings, but probably someone has tried it and can give some advise?

thanks

macsimski

I think that is the same procedure as for a arduino on 8Mhz. change the settings in the arduino settings file to the corresponding speed ie: change
Code: [Select]
build.f_cpu=16000000L

to
Code: [Select]
build.f_cpu=1000000L

and reprogram the fuses to make use of the internal clock of 1Mhz.

and of course be aware that the timing in the arduino code is totally wrong. everything will be 16x slower.
--
"We're all in this together..."

mellis

Well, not quite everything; that's why we have the build.f_cpu preference.  The serial, millis, and delay functions should work at the right speed.  Other things (like delayMicroseconds and pulseIn) will be at 1/16 speed.

The frequency the ATmega chip is running at, is hardcoded into the bootloader (ATmegaBOOT.c). While it is a configuration parameter in the Makefile, putting a bootloader on an Arduino-like board that does not run at 16.0MHz requires adjusting the Makefile and rebuilding the bootloader.
The best place to get Makefile and bootloader source for the ATMega8 is http://svn.berlios.de/viewcvs/arduino/trunk/bootloader/

The ATmega8's Makefile defines DEFS= -DF_CPU=16000000 -DBAUD_RATE=19200 which needs to be modified to DEFS= -DF_CPU=1000000 -DBAUD_RATE=19200

The last thing that needs to be done is adjusting the Arduino IDE preferences file: ~/Library/Arduino/preferences.txt on the Mac and C:\Documents and Settings\<USERNAME>\Application Data\Arduino\preferences.txt on Windows:
The build.f_cpu preference needs to be set to 1000000L

Check my complete post regarding using the ATmega8 and ATmega168 internal clock here:
http://wolfpaulus.com/journal/embedded/arduino3.html

--
Wolf Paulus

Hi,

there is a fuse calculator available in the Web:
http://palmavr.sourceforge.net/cgi-bin/fc.cgi

Best,
Sebastian

ecerulm

What about OSCCAL (oscillator calibration) register? Is it any way to set that register from an arduino sketch? or from the bootloader?

Or is the internal rc oscillator is good enough even without setting the OSCCAL? I was planning to use 9600 serial comms and it would be good to know if OSCCAL is needed and how to set it up.

bohne

The adc prescaler is set to 128, resulting in 16 MHz / 128 = 125 KHz on the Arduino. A 1MHz clock will result in 7,8kHz for the ADC...

And about OSCCAL: if you run the Arduino at 5V at 25 degree Celsius, then it should work with 9600baud. I tested it on attiny84 chips and only a few of them make problems. But if temperature changes or voltage drops, the internal clock might run too fast (or too slow) and then falling back to 4800baud should solve the problem.

http://www.dorkbot.de
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254
http://www.luminet.cc

Cross

Just to give you some numbers:
I changed the fuse to internal oscillator @8MHz without divider and clock output on pin 14. According to my scope the actual output is 8.1 MHz.

aballen

I want to run it at 1mhz not only to save power, but so the device will run at lower voltages and last longer on a battery.

I changed the fuses with a program called AVRFuses
CKDIV8=0 (divider at 8)
CKSEL=0010, SUT=10(internal 8mhz,

Then I added a new entry to /hardware/boards.txt

myboard.name=MyBoard w/ATmeag168@1MHz

myboard.upload.protocol=stk500
myboard.upload.maximum_size=14336
myboard.upload.speed=19200

myboard.bootloader.low_fuses=0xff
myboard.bootloader.high_fuses=0xdd
myboard.bootloader.extended_fuses=0x00
myboard.bootloader.path=atmega168
myboard.bootloader.file=ATmegaBOOT_168_diecimila.hex
myboard.bootloader.unlock_bits=0x3F
myboard.bootloader.lock_bits=0x0F

myboard.build.mcu=atmega168
myboard.build.f_cpu=1000000L
myboard.build.core=arduino

I reflashed the bootloader using the new board entry, but when I try to upload my program the board is not recognized... if I put a 16mhz crystal back in it programs.... what am I missing?

Mike Mc



technik3k

#11
May 21, 2009, 06:06 am Last Edit: May 21, 2009, 06:20 am by technik3k Reason: 1
If your main goal is to save power and be able to run at lower voltages then what you are looking for is "CLKPR - Clock Prescale Register" which determines System Clock Prescaler for dynamic frequency scaling. It is initialized during reset with value of CKDIV8 fuses, but you can change it anytime during runtime. No need to avoid external oscillator or reprogram fuses every time.

Here is the excerpt from the Atmel datasheet:
Quote

   The ATmega48P/88P/168P/328P has a system clock prescaler, and the system clock can be divided by setting the "CLKPR - Clock Prescale Register" on page 377. This feature can be used to decrease the system clock frequency and the power consumption when the requirement for processing power is low. This can be used with all clock source options, and it will affect the clock frequency of the CPU and all synchronous peripherals.


Code: [Select]

 CLKPR = (1<<CLKPCE);
 CLKPR = 0011b; // Divide by 8


Of course, as it was pointed out earlier, any code that assumes CPU speed will be affected.

You can start up at medium speed, measure your supply voltage, and then either drop down to a lower speed if you need to conserve power or ramp up to a higher speed if you are connected to a host and power is not an issue.

I am not an expert on Arduino bootloader, but I believe you can configure it for default communication and then drop your speed when your sketch starts running.

aballen

yeah, I just think I'm doing it wrong.  I think all the fuses are reset when you flash the bootloader, so maybe I'm just makeing changes in the incorrect order.

I think I should
1) change bootloader speeds F_CPU etc, flash bootloader
2) change fuses, for slower clockspeed
3) load my program

but somehow I seem to be meseeing it up, it never runs without a resonator in.  I have a pretty simple device created, I just need it to run at lower voltages, and the time to be reasonably correct.  I guess I'm stumped for now.

mungbean

#13
Sep 05, 2009, 05:19 pm Last Edit: Sep 05, 2009, 05:26 pm by mungbean Reason: 1
Thanks technik3k,

I'm just trying this out, and syntax for the arduino is actually:

Quote

 CLKPR = (1<<CLKPCE);
 CLKPR = B00000011;


I'm trying to get power consumption down on a project here, so I just ran some tests, including various boards I had lying around.

These were all tested running off 4 x AA NiMH cells, measured at 5.22V, using the code above in setup() and running an empty loop().


Arduino Pro Mini 3.3V/8MHz
(power connected to RAW pin)
default clock: 4.8mA
CLKPR mod:  1.85mA

Duemilanove w/ ATmega328
default clock: 12.7mA
CLKPR mod:  7.8mA

Diecimila w/ ATmega168
default clock: 13.3mA
CLKPR mod:  8.2mA

Freeduino v1.16 w/ ATmega168
default clock: 16.2mA
CLKPR mod:  10.mA

According to the datasheet I'm looking at here for the 48/88/168, the prescaler is actually 4 bits and can go up to 256... (B00001000).  

Setting it to B00000011  divides by 8, which would result in 1MHz on the Arduino Pro and 2MHz on all the other boards, right?

Divisors are (p38, bottom nybble)

0000 - 1
0001 - 2
0010 - 4
0011 - 8
0100 - 16
0101 - 32
0110 - 64
0111 - 128
1000 - 256

Spookyman166

Why reprogram the arduino when you can just buy a crystal for 2 bucks

Go Up