I have a ATMEGA8A-PU with a 8Mhz crystal oscillator (T8.000 is 8Mhz isn't it?) and the following C code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRC = 0b00100000;
while(1) {
PORTC ^= 1 << PORTC5;
_delay_ms(1000);
}
return 0;
}
So, just a simple code, that switches the LED on and off every second.
But when I write this program to the controller, the LED switches on/off after about 8 seconds. When I replace F_CPU to 1000000UL, it switches nearly every second.
So I thought, it's a problem with the fuse bits, but they are set to F1 (low) and D9 (high) which looks good to me.
Anyone who has an idea how I get the full 8Mhz?
Best Answer
That should give you a clue: the CPU is running at 1MHz and not 8MHz
Your lfuse settings are wrong.
This selects the internal RC Oscillator (see sec. 8.2 "Clock Sources" in the Datasheet), and SUT is set to a value that is not allowed for this value of CKSEL (Table 8-9)
To have it run off the 8MHz ext. crystal, you need these settings:
From Table 8-3:
From Table 8-4:
This gives lfuse = 0xFF
Don't forget the 22pF capacitors!