Arduino Forum

Forum 2005-2010 (read only) => Hardware => Development => Topic started by: ritzdank on Nov 13, 2006, 12:50 pm

Title: arduino with internal oscillator on 1Mhz
Post by: ritzdank on Nov 13, 2006, 12:50 pm
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
Title: Re: arduino with internal oscillator on 1Mhz
Post by: macsimski on Dec 15, 2006, 10:05 pm
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.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mellis on Dec 18, 2006, 08:59 am
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.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: wolfpaulus on Dec 29, 2006, 12:46 am
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
Title: Re: arduino with internal oscillator on 1Mhz
Post by: macbastian on Feb 08, 2007, 12:50 pm
Hi,

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

Best,
Sebastian
Title: Re: arduino with internal oscillator on 1Mhz
Post by: ecerulm on Sep 02, 2008, 04:53 pm
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.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: bohne on Mar 10, 2009, 02:21 am
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.

Title: Re: arduino with internal oscillator on 1Mhz
Post by: Cross on Mar 12, 2009, 11:19 pm
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.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: aballen on Mar 21, 2009, 09:30 pm
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?
Title: Re: arduino with internal oscillator on 1Mhz
Post by: zooto68 on Apr 19, 2009, 11:29 pm
Did you have any success with this?
Title: Re: arduino with internal oscillator on 1Mhz
Post by: aballen on Apr 20, 2009, 12:46 am
no not really
Title: Re: arduino with internal oscillator on 1Mhz
Post by: technik3k on May 21, 2009, 06:06 am
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.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: aballen on May 21, 2009, 03:56 pm
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.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Sep 05, 2009, 05:19 pm
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
Title: Re: arduino with internal oscillator on 1Mhz
Post by: spookyman166 on Oct 02, 2009, 11:27 am
Why reprogram the arduino when you can just buy a crystal for 2 bucks
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Oct 02, 2009, 11:34 pm
because simply replacing the crystal won't do you any good -- the clock frequency is hard coded into the bootloader.

re-programming the clock frequency on the fly allows you to experiment with varying power consumption.

but then yes, ultimately you may wish to burn a new bootloader specific to requirements and use a new crystal.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: acgourley on Oct 06, 2009, 07:37 am
Hi! New to the boards... came here in seek of a way to run an arduino pro 3.3v (from sparkfun) on 2 AAs. This is important because I'm actually just stealing the power rail from a wireless xbox controller. The two batteries only give me 2.6-2.9 volts, which is only enough to boot the micro on a good day.

I tried running

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

in my setup loop but it still would not power on with 2 AAs. Are there additional steps or tricks I can try?
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Oct 06, 2009, 12:01 pm
we were discussing changing the clock frequency in software.

you can't change the voltage in this way.

here are a couple of options:

1. buy an arduino that will run on 3.3V (e.g. arduino pro mini)

2. build a circuit like the Adafruit minty boost that takes 2 x AA and gives you 5V.  This is useful if you also have other parts needing 5V anyway.  I did it myself very recently.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: acgourley on Oct 06, 2009, 06:14 pm
I do have the 3.3v arduino pro, it is not the mini however. http://www.sparkfun.com/commerce/product_info.php?products_id=9221

Someone had mentioned earlier in this thread that voltage was linked to clock frequency, so thats what I was going off.

I did find a 3.3 volt dc-dc converter circuit that is now in the mail. That should work for sure. I was hoping to keep power consumption as efficient as possible by using extremely low voltage and not needing the loss in a dc-dc conversion, but I'll explore saving power with watchdog/sleep instead.

Thanks.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Oct 06, 2009, 06:46 pm
Quote
Someone had mentioned earlier in this thread that voltage was linked to clock frequency, so thats what I was going off.


Couldn't spot that statement just now, but... looking at the datasheet for the ATmega328P it does say that it will run at:

1.8-5.5V for a clock of 0-4MHz,
2.7-5.5V for clock 0-10MHz and
4.5-5.5V for clock 0-20MHz

So running at 4MHz *in principle* should mean you can go down to 1.8V which would give you decent battery life on AAs I guess.

Trouble is that if you're using the clock tweaks described previously then you'll still need to boot up at full clock speed first.  Hmmm!

(You would probably need to connect Vcc on the pro direct to your supply as well, rather than going through U2, whatever that is - presumably a regulator.)

Sounds like it would be easier to reprogram a 4MHz bootloader into the 328, really.

I'd be interested to know how you get on.

Title: Re: arduino with internal oscillator on 1Mhz
Post by: acgourley on Oct 06, 2009, 07:16 pm
Hmm, interesting. I don't have any special hardware to burn a bootloader so I guess this project will have to go on hold. Something I'll circle back to as I am interested in revising this project to be low power.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: MarvinMartian on Dec 02, 2009, 01:54 pm
I've got a stand alone battery prowered 328 project that runs off 3 AAs - it "works ok" but reading here is sounds like I'm on the edge of it running successfully at 16MHz.

I was considering dropping the crystal down to 8MHz to give me a wider power margin - Comms is not an issue as I'm programming the 328 in an Arduino then taking it out and dropping it in my PCB.

But it sounds like just changing the crystal won't work either and it will require a software tweak too - is that correct?

Cheers
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Dec 02, 2009, 02:52 pm
As I understand it, clock speed is hard-coded into the bootloader, so changing the crystal isn't enough to change the speed.  You would need to program a new bootloader in as well.

Given what we've been discussing about clock dividers above, it would seem that changing the crystal isn't actually necessary - a bootloader that sets the clock divider would suffice.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: MarvinMartian on Dec 02, 2009, 06:17 pm
But without the capability to reprogram the bootloader that's going to be a bit awkward. Ho hum.

Cheers
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Dec 02, 2009, 06:31 pm
If you have a windows machine and can solder a 4-way header onto your standard-format arduino (diecimila, duemilanova etc) then you can reprogram the bootloader:

http://www.geocities.jp/arduino_diecimila/bootloader/bitbang_w_ide_en.html

When I last tried with a mac (July 09) it wasn't possible using the mac's FTDI driver.  Instead I used Windows running under parallels.

See also this post/thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1258854659/7#7
Title: Re: arduino with internal oscillator on 1Mhz
Post by: TBAr on Dec 02, 2009, 11:39 pm
Marvin Martian, why do you think you would need to reprogram the bootloader?

You also said
Quote
Comms is not an issue as I'm programming the 328 in an Arduino then taking it out and dropping it in my PCB.

So when you want to reprogram the sketch on the 328, pull it out of your PCB, replace the 328 in your Arduino (which still has the 16MHz crystal) and re-program the sketch there.

[edit]I know there are timing issues with some of the libraries when they are used with a crystal other than the 16MHz one. But it still seems that is separate from the bootloader issue. If the logic in the sketch cannot be adjusted for a lower crystal speed, there is no point in changing the bootloader anyway. If the logic can be adjusted or does not need to be adjusted, the procedure I outline above should still be valid without needing to reprogram another bootloader onto the 328. At power-on, the standard Arduino bootloader may take a little longer (at the reduced crystal speed) to recognize that there is no data coming in on the serial port, but it should eventually time out and start the sketch anyway, right?[/edit]
Title: Re: arduino with internal oscillator on 1Mhz
Post by: MarvinMartian on Dec 03, 2009, 10:52 am
Quote
Marvin Martian, why do you think you would need to reprogram the bootloader?


Because of what mungbean said earlier:
Quote
As I understand it, clock speed is hard-coded into the bootloader, so changing the crystal isn't enough to change the speed.  You would need to program a new bootloader in as well.


So I'm still confused as to whether this is or is not necessary  :-/

Title: Re: arduino with internal oscillator on 1Mhz
Post by: tytower on Dec 03, 2009, 01:46 pm
Spookyman166
Quote
Why reprogram the arduino when you can just buy a crystal for 2 bucks


Personaly I have a box full of old crystals I'd like to use up. As I am presently at a river mouth  about to head  to sea I would have to allow two days to tie up ,catch a cab 40Ks to the parts shop, buy my crystal and catch a cab back.

I  find it cheaper to reprogram it.
Its all a matter of your own circumstances and then how narrow or broad your vision is.

Marvin I am using a 14.890MHz crystal in an ATMega8 because of the above . To get the chip to run I have to change the Makefile and recompile the bootloader allowing for this crystal speed . I also have to create a board in "boards.txt" to get an entry for my board

If I program the chip with a sketch in a standard duelmilanov board with a 16MHz crystal and put a standard bootloader on the chip first it will all go off OK. When I put it back in my experimental board with the slower crystal the sketch will run just a little slower but not that I can notice ,however I cannot upload another sketch to it unless I put it back in the standard board


Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Dec 03, 2009, 07:58 pm
Marvin Martian -- if all you want to do is reduce power consumption, then you can change the clock speed once you've booted (in your setup function), as described above.

I posted some test figures earlier in the thread, showing the reduction in current for various clock speeds.  If it's possible to put the arduino to sleep for longish periods of time when it's not doing anything, then this will save power further.

If you want to run on a LOWER VOLTAGE, then you may need to reprogram the bootloader to get the arduino to bootup on that lower voltage, depending on how low you want to go.

I'm basing this assumption on what we found in the ATmega328 datasheet, again mentioned earlier in the thread.

I'm beginning to think it would be GREAT to have a slightly modified bootloader that selected clock frequency based on some jumpers on the board. Anyone fancy giving us an early christmas present...? ;-)

Title: Re: arduino with internal oscillator on 1Mhz
Post by: tytower on Dec 14, 2009, 11:27 am
Back on page 1 wolfpaulus said
Quote

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


I see that on Linux "preferences.txt " is in the library directory and I could find no mention of "build.f_cpu".

Is this now obsolete ?
Title: Re: arduino with internal oscillator on 1Mhz
Post by: captnKrunch on Mar 28, 2010, 06:40 pm
because changing the crystal will stop the downloader from working unless you reprogram and reflash it.
Title: Re: arduino with internal oscillator on 1Mhz
Post by: FrankRadio on May 17, 2010, 03:53 pm
I'm working at a similar issue.
What i want to do is use a 3.579545 TXCO as external clock source.
Now i do all the things i found.

My list is:
1) Change at makefile, Xtal value, BPS value for that who have less error, for this case is 9600BPS (I use AVR calculator to analize this)
2) Change all the fuse bits to use an external clock source (H fuse = d0)
3) Rebuild the .HEX file
4) Include a new CPU at boards.txt, in that change all again, xtal freq, buse bits, serial speed.

But i can download a scketch file to the CPU, in fact i never see the E0 when de CPU runs loading the scketch HEX file. :P

I was doing the maths about this:
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8;       // set baud rate
 UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
 UCSRB = (1<<RXEN)|(1<<TXEN);  // enable Rx & Tx
 UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);  // config USART; 8N1

But it's OK and the maths of this and the obtained from the AVR calculator are the same, in fact the error at 3.579545 in 9600BPS is less that 0.2%.

Ideasssssss??? I'm stuck here  :-[

Best Regards
Frank
Title: Re: arduino with internal oscillator on 1Mhz
Post by: FrankRadio on May 18, 2010, 04:24 am
is DONE!

Cheq this:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1273962209  :o
Title: Re: arduino with internal oscillator on 1Mhz
Post by: mungbean on Jul 26, 2010, 11:35 am
This may be of interest to some who've been following this thread -- Peter Knight has written a library called Narcoleptic:

http://code.google.com/p/narcoleptic/


Library implementing sleep modes, allowing extremely low power consumption on Arduino based projects.

Narcoleptic uses the sleep functionality of the AVR microcontroller to almost completely shut down the entire CPU, just leaving a low power timer running to trigger the wake up.

Extract the download, and install in your Arduino Libraries directory. Restart Arduino and you will see the Narcoleptic library appear in the menus.

Syntax:

Narcoleptic.delay( time in milliseconds )

Note that Narcoleptic timings are only accurate to a few percent. Whilst sleeping, everything is stopped - including PWM outputs, the millis() timer, serial ports - everything. So code with this in mind.


Title: Re: arduino with internal oscillator on 1Mhz
Post by: zachwiej on Aug 15, 2010, 09:13 pm
Hi

is there a way to run narcoleptic on atmega8?
Title: Re: arduino with internal oscillator on 1Mhz
Post by: herctrap on Jan 09, 2011, 08:59 pm
i just read 5-6 topics on how to use the internal oscilator

but i am also stuck in something

i can reprogram the fuses with avrdude and a usbtinyisp programmer
so the atmega will run on 8Mhz of the internal or 1Mhz

so far so good

now when get the hex from the blink code and upload it to arduino(without the bootloade)

and the 1sec is actualy 2sec (on 8Mhz) or 16(on 1Mhz)

ok i was expecting that

now i am changing olny that from the boards.txt file

atmega328.build.f_cpu=16000000L
to
atmega328.build.f_cpu=8000000L  or  atmega328.build.f_cpu=1000000L

then i remake the hex and upload it again to arduino

and the led blinks normanly in 1sec

but when i am changing the

delay(1000) in the code with the
delayMicroseconds (1000000)

it dosent work

so how can we fix that?

thanks a lot

*i dont care for bootloader - i dont use it anymore