Using the 8MHz Internal Clock and the XTAL Pins as I/O...

ATmega devices are supplied from new with their internal 8MHz clock selected and a "Divide by 8" fuse set so, the actual running frequency of the device is 1MHz. The ATmega328P used in the Arduino Uno for example uses a 16MHz external crystal to control the device's clock and has different fuses set to make this happen.

Pros and Cons of using an 8MHz internal clock:

Pros...

  1. No external crystal or capacitors
  2. You gain 2 additional input/output pins (PB6 & PB7)
  3. Suitable for most applications where timing accuracy and speed are not essential
  4. Power consumption is reduced by using a slower clock

Cons...

  1. The 8MHz oscillator will vary more with temperature and device supply voltage
  2. Accurate timing will be affected (The clock frequency can be adjusted or "tuned" using a register within the device)
  3. High speed processing is not possible

Never alter the fuses unless you know what you are doing and have fully understood the "Memory Programming" section of the device datasheet!

To change the default (factory shipped settings) we need to change the fuses and this suggested "boards.txt" profile will do the job:

atmega328.name=ATmega328 (INT 8MHz Clock ArduinoISP)
atmega328.upload.using=arduino:arduinoisp
atmega328.upload.maximum_size=30720
atmega328.bootloader.low_fuses=0xE2
atmega328.bootloader.high_fuses=0xDA
atmega328.bootloader.extended_fuses=0x05
atmega328.bootloader.path=arduino:atmega
atmega328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F
atmega328.build.mcu=atmega328p
atmega328.build.f_cpu=8000000L
atmega328.build.core=arduino:arduino
atmega328.build.variant=arduino:standard (change to "atmega328_8mhz" if you install the new variants file - see below)

After "Burn Bootloader" on the device it will be running at 8MHZ and will not require an external crystal or capacitors. To return the device to 16MHz crystal operation simply use the Uno profile with "Burn Bootloader" and attach the crystal and capacitors. You will also need to use the 8MHz output from the Arduino ISP.

uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino uno.build.variant=standard

Once the device is programmed for 8MHz internal oscillator the pins that were originally used for the external crystal become available as follows:

PORTB bit Arduino Uno pin Atmega328x pin Current use 8MHz internal clock use
0 8 14 ICP ICP
1 9 15 OC1 OC1
2 10 16 SS SS
3 11 17 MOSI MOSI
4 12 18 MISO MISO
5 13 19 SCK SCK
6 20* 9 XTAL1 input/output PB6
7 21* 10 XTAL2 input/output PB7

* Pin assignments only apply when using the "atmega328_8mhz" variant file downloadable below! (I have modified the "standard" Arduino pin definition file to include pins 20 & 21)

Alternatively you can control/access the new pins by directly accessing the DDRB & PORTB registers.

Did you know that Arduino Pins "A0 - A6" can also be referred to within sketches as Arduino Pins "14 - 19"?

Variants file for ATmega328 devices using 8MHz internal clock to give Arduino pins 20 & 21

Chapter 12: ATtiny devices>>>