Newbie here. I have been playing with the ATTiny13 and ATTiny2313 and have some questions and comments on using the _delay_ms function.
I am using the code from the Ghetto Programming posting on the Instructables web site. The “Hello World” program contains this line:
#define F_CPU 100000UL // Sets up the default speed for delay.h
I’ve looked around a bit but I haven’t found a good explanation of why this is one-hundred-thousand and not one-million. I’m using the internal oscillator.
Using the code from the Instructables site, I tried to change the ‘led off’ portion to three seconds by changing the _delay_ms() value to 3000, but the led turned back on faster than it should have. This behavior made me wonder if the value was too high based on something I had read that the _delay_ms code would act funny if the value used was too high
“The maximal possible delay is 262.14 ms / F_CPU in MHz.”
If I change the F_CPU value to one million, then I can use _delay_MS(3000) and it seems to stay off for 3 seconds. This is just a casual observation - no test equipment was used to confirm the actual length of time.
In fact, if I use the original _delay_ms() values with the F_CPU value of one million, both ‘led on’ and ‘led off’ occur for much longer times.
Is the F_CPU value supposed to represent the speed of the AVR chip or is it the oscillator frequency?
I’m editing the code and programming the chips with Programmer’s Notepad and I don’t get any errors.
Thank you.