Understanding effect of clock speed on time functions

Hello,

i am playing with ATtiny85 and i found something intresting that i can't understand.

Up till now i though that delay(1000) means 1 second of delay if clock speed is set to 16 mhz and 2 seconds if speed is set to 8 mhz (because procesor runs half time slower). Is that correct? What about millis() if clock is set to 8 mhz? How are they counted?

First i set ATtiny85 to 8 mhz internal clock and use delay(500) for blink test, but led didn't blink in 1 second interval, it was more like 3 seconds interval. Than i set internal clock to 1 mhz and use delay(1000).. Blinking interval was correct, with 1 second delay. I am happy that it works but how is that possible? Why so?

In boards.txt there is a line where the clock speed is set.
I think if you have that set to match the hardware, then delay(1000); will result in 1 second delay.
You have to check that and the fuse settings when you are making tests like this.

Also the 84 will default to 1MHz operation unless you set the right fuses. I don't know if that's handled by avrdude/IDE or not.


Rob

luxy:
First i set ATtiny85 to 8 mhz internal clock and use delay(500) for blink test

No you didn't. You selected "8 mhz internal clock" from the menu but you didn't change the clock speed of the chip.

You have to do a "burn bootloader" for that.

fungus:
No you didn't. You selected "8 mhz internal clock" from the menu but you didn't change the clock speed of the chip.

You're right.. I forgot to hit "burn bootloader" button before.. Now i set clock speed to 8 mhz and it works ok.