Home

Setting the ATtiny85 Clock Speed

2023-11-11

Background

The clock speed of the ATtiny85 can be set using one of several internal clock sources, or an external one (like a crystal oscillator) for full flexibility.

The default setting utilizes the internal 8 MHz oscillator combined with a clock divider of 8, resulting in a 1 MHz clock speed. This clock divider can be disabled to run at the native 8 MHz. Additionally, there's another clock source called the Phase-Locked Loop (PLL), which doubles the internal frequency to achieve a 16 MHz clock speed.

When getting started with the ATtiny85 the most common choices are running the internal clock source at either 1 or 8 MHz. Selecting the appropriate clock speed is very important, especially for time-sensitive code, and some libraries require a specific speed to function correctly.

Once you've moved into more complex projects, there are also ways of adjusting the clock speed at run-time using code, but that's a story for another day.

Setting the speed

To set the clock speed of the ATtiny in the Arduino IDE, first ensure you have installed a suitable board definition for ATtiny support. You also need access to an Arduino or a dedicated programmer for flashing it.

Begin by selecting the correct board in the Tools > Board menu. Then look in the Tools > Clock menu and select Internal 1, 8, or 16 MHz. Do not select an external clock source unless you have one properly set up, as it could make flashing the chip again impossible without the use of a high voltage programmer.

After selecting the correct board and clock speed, ensure the appropriate programmer is chosen in the Tools > Programmer menu. Connect the ATtiny to the programmer and select Burn Bootloader from the Tools menu. The operation only takes a second, then you should be good to go.

Under the hood

Despite its name, the Burn Bootloader command actually doesn't burn a bootloader into the ATtiny; it just changes the value of certain fuses to match the chosen clock configuration. Fuses are a common way of storing essential configuration parameters in microcontrollers. They are typically stored in non-volitile memory and remains set even if new content is flashed into the program memory. I've written an introduction to ATtiny85 fuses that explains this in more detail, as well as listing all the different configuration bits that can be set.

Happy tinkering!