Speed confusion


Greeting to you all.

I’m a newbie so don’t shout too loud.

I’ve a question too all you experienced Arduino experts concerning the speed of the Arduino Duemilanove.

If I read the datasheets its states that the default speed is 8Mhz from the internal RC sources divided by a prescaler of 8 giving me 1Mhz?

Now if i run a simple program that consist of a FOR loop repeating a Direct Port Access command to the PORTD turning the bit on and then off again then what I’m seeing on my scope doesn’t match with what the datasheet is saying.

The scope is showing a pulse happening with a 120-130ns period at a frequency of 1.446Mhz which would seem to imply that the FOR loop is taking aprox 9 cycles at 62.5ns. (130ns + (9*62.5) = 692.5ns which corresponds with the frequency I’m seeing of 1.446Mhz.

Now if I’m running at 1Mhz as the datasheet implies then I’ve got a processor that’s defying the laws of Physics. Even at 8Mhz I’m getting port access happening in half a cycle, but at 16Mhz the sums seem to add up as shown above.

After reading many of the post on the subject I’m none the wiser so decided the only way to get to the bottom of this is ask the question - What speed is this AD running at out of the box. Is the fact that it came from RS something to do with it, do they replace the bootloader and as such the fuse settings to use the external 16M crystal as standard?

I’m confused and need someone with more knowledge of the ardinuo to straighten me out. Now before you all go crazy and start calling all the names under sun you must realise I haven’t been near anything electronic for 20 years (although it was my first love) other than putting ticks in check boxes for Mr Microsoft so take it easy please. lol. :slight_smile:

And if someone can tell me in simplest way possible to get it running at its max speed then I’d really appreciate that. Remember I’m new to this so need things explained as if your talking to your child. :slight_smile:

Many thanks in advance.


The Arduino Duemilanove runs out of the box at 16MHz, it says so on the crystal. The crystal determines the speed. Simple as that.

Grumpy_Mike, Thanks for responding so fast.

The sums seemed to point to the fact that it was running on the external crystal but with datasheets were saying one thing and page after page of contradicting and confusing forum chatter it had me questioning what the scope was showing me. And my sanity came in question in the early hours yesterday as well.

Anyway that solves that particular problems and saves me having to mess with all the fuse settings. :-/

I really need to stop reading datasheets!

Now I just need to figure out that Timer1/Timer2 fiddle in the 5940 library and I'll be happy camper.

Thanks again.

P.S Solder is elctrical glue. Sweet. ;D

I really need to stop reading datasheets!

No you need to understand them more. A data sheet shows everything the device can do. Any one implementation, like an Arduino, is only a sub set of it's possibilities.

Yeah I agree in theory but when the datasheet is telling you one thing and the scope another you kinda question the validity of the rest of information, and hence my call for help on here.

But like you say the Arduino is only subset of the AVR_328 processors so I'm sure I'll be dipping into the datasheet again in the future but I'll be taking everything with a pinch of salt, or at least trying it out and scoping it to see if fact and fiction actually agree.

Anyway you've put my mind at rest about the speed issue so I wont be wasting any more time trying to get it to run any faster, pity I can't say the same about my code.

Cheers. DH.

but with datasheets were saying one thing and page after page of contradicting and confusing forum chatter it had me questioning what the scope was showing me.

The datasheet says that the default clock configuration of the ATmega328 chip uses the 8MHz internal oscillator and the 8x divisor. However, the Arduino is a "turnkey" product with circuitry and a pre-programmed chip (bootloader + fuses + etc) that is set up to run with an external 16Mhz crystal and no additional divisor.



That's where I went wrong, assumming the ATM328 and Arduino are the one and same thing. When in fact the Arduino is an imlementation of the ATM328 meaning the datasheet doesn't account for the custom options implemented used in the Arduino configuration.

Like they say you live and learn.

Anyway guys thanks for your prompt responses, I'm glad there are people out there will to help.

Regards DH

Also, there's a description of the various board settings here: http://arduino.cc/en/Guide/Environment#boards