Clock speed arduino ide

Hello everyone, I am trying to make my arduino as fast as possible. I am using a 8 bit 16MHz 328p. I am also using 16MHz externall oscilator. Does arduino IDE divide the clock signal by 8 on default? If it is the case, how can I make it divide by 1? Or what happens if I use 80MHz crystal oscilator. I am a complete beginner, please keep in mind when answering my question. Thanks a lot.

When you use the term "my Arduino" and the later description of a AT328 chip and 16MHz external oscillator it's not clear if you are talking about a purchased complete board, or something you you have configured from individual parts.

Can you please clarify what you have.

There are fuse settings which determine how the AT328 is clocked.
http://www.martyncurrey.com/arduino-atmega-328p-fuse-settings/
An unprogrammed purchased AT328 with default settings will be different then when it is set up in an Arduino board product.

Does arduino IDE divide the clock signal by 8 on default?

No.
Why do you think this might be the case?

The ATmega328P can not run at 80MHz, it is all in the datasheet.
This is the manufacturer's page of the ATmega328P: https://www.microchip.com/en-us/product/ATmega328P
The document on the top is the "automotive" version, you need the "ATmega48A/PA/88A/PA/168A/PA/328/P Data Sheet".

A Arduino Uno or Nano runs at full speed. The ATmega328P is optimized for fast input and output with the digital pins. You can not make it faster, but you can write code that makes better use of the possibilities of the chip.

If you want to do a lot of mathematical calculations, then there are faster Arduino boards and fast Arduino-compatible boards. Some have a hardware floating point unit.

We sometimes see this question by new users who have a lot of delay() in the sketch. In that case, a faster Arduino board will not make it faster.

Can you tell more about your project ? Why do you want it to be faster ?

Let us know if you try it! According to its datasheet, the 328P is rated for running at up to 20MHz. Whether it would survive being overclocked at 80MHz and for how long is probably anyone's guess. I have read about someone overclocking one to 50MHz but I wouldn't recommend it. Datasheets specify what the manufacturer deems to be "safe" and stable operating limits. Although these would generally allow some margin for manufacturing tolerances, there are no guarantees beyond that. I would also imagine overclocking it would probably impact timing routines such as millis() and delay().

The IDE simply needs to know the clock speed so the timing functions, millis() etc, are compiled to run correctly. If you have an Uno and you select "Uno", it knows exactly what to do and everything works.

The bootloader has to know the clock frequency in order for USB programming to work. (The serial communication has to run at a known baud rate.)

Every Arduino runs at a known clock speed. It's part of the standardization that makes everything "easy".

When you start messing-around you no longer have an "Arduino".

Once you have a programmed chip, if you're not using serial communications or anything timing related, clock speed is not so important. But if you overclock it, it might get glitchy or fail completely.

If you need speed, buy a faster Arduino. The Arduino compatible Teensy 4.x runs at over 600 MHz.

First of all, thank you for your reply. I know that 328p can not run at 80MHz. My question was "While programming my 328P with arduino IDE, does IDE automatically divides the clock signal by 8?" I guess it has something to do with CLKDIV8 fuse. @cattledog replied that it does not. So then, how can I divide the clock frequency while coding the 328P on arduino IDE?

Because, I have read that atmega divides the clock signal in order to save power under some circumstances. Thus, I would like to check if it is the case by default.

I want to design a flight controller for a quadcopter (drone). And it has to be fast in order to get the sensor readings and act accordingly without blowing up. Or should I say blowing down. (Sorry guys)

No, you read that wrong. Even if you write code to lower the clock signal, then it is still trivial.

The best tutorial for low power a ATmeg328P is this: https://www.gammon.com.au/power.

So you need to run the ATmega328P all the time at 16MHz, that is what it does :smiley: all the time at 16MHz.

1 Like

Thank you for your reply. That was the question.:slight_smile:

The CLKDIV8 fuse controls whether the clock is divided by 8 at startup. The arduino IDE will normally ensure that this fuse is NOT set, so the clock runs at full speed (8MHz internal or 16MHz external.) After that the clock speed is left alone, since various other arduino functions assume that the clock speed is (millis(), micros(), assorted serial clocks, etc.)

If you're willing to ignore or correct the arduino core function that relay on the clockrate, you can reset the clock divisor using the CLKPR regsiter, to divide the master clock from 1 to 256 (the various powers of 2) Unlike the fuses, the CLKPR regsiter can be set by sketch code, and MIGHT have some use for certain low-power applications.
The core IDE and libraries do not change the divisor.

Some newer chips and boards do allow the clock rate to be changed on the fly. I'm not sure if it works in conjunction with Arduino SW, but the rp2040 sdk has a clock configuration command that people have used to overclock the board.

1 Like

The IDE has absolutely no control over the clock speed of what it is programming. That is determined by the hardware alone.

While the top speed of an Arduino is 20MHz, the Arduino project decided to use 16MHz as the standard speed.

It might have something to do with the wide range of serial Baud rates it can run at from simple binary division provided by the pre scaler circuitry.

If you are interested in using the ATmega328P with a 20 MHz clock, I recomment the excellent MiniCore:

MiniCore has support for 20 MHz clock, including a bootloader compiled for that clock speed.

After installing MiniCore, you will need to select Tools > Board > MiniCore > ATmega328 from the Arduino IDE menus, then Tools > Clock External 20 MHz. After that, connect an ISP programmer to your ATmega328P and do a Tools > Burn Bootloader operation. This will set the appropriate fuses on the microcontroller for that clock speed and flash the 20 MHz bootloader that will allow you to do normal uploads over the USB to serial adapter.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.