ATTiny85 clock speed?

i have sketch:

digitalWrite(led_pin,1); delay(100); digitalWrite(led_pin,0);

i'have uploaded same sketch on same tiny but with different clock speed, and realized that as higher clock speed - as higher real delay.

1MHz - fastest (minimal delay)

16MHz - slowest ( with delay(100) LED lit about 2 sec)

am i missing something? i thought that with higher clock speed delay might be shorter, not longer. why?

Hi maia

It is because your ATTiny85 is running at the default 1MHz clock as they ship from factory.

When the clock speed on the target board you specify in the Arduino IDE is matched, the delay will be accurate. So your ATtiny85 running at 1MHz runs slower than expected when a sketch compiled with an 16MHz target is loaded because the clock it is using is that much slower than the code internally expects.

To change the clock, select the 16MHz target and use the 'burn bootloader' option in the Arduino IDE. This will set the internal fuses in the microcontroller. Then use that clock speed as your target for uploading the program and everything will work as advertised.

Use 8MHz code on 1MHz pocessor your 100mS delay becomes 800mS. Use 16MHz code on that 1MHz microcontroller and 100mS becomes 1.6seconds. That's what you're seeing.

Hope this helps, Geoff