0

atmega16 fuses
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

atmega16 fuses

by wireframewolf on Thu May 01, 2008 2:00 pm

Okay, so, I can successfully program an Atmega168 with Mac-AVR's tool chain now, along with XCode, and it seems to work fine. I used the fuse settings that the arduino's chip uses because I'm using an external 16 mhz crystal.

So now I want to program and Atmega16. The program uploads fine, as it is supposed to make a light on pin 4 of port d blink, which happens. The only problem is, it's supposed to blink on and off every 300 ms, and instead it takes ~5 seconds. Which I can only assume means that the fuse setting for the clock is wrong, but I'm not sure what it should be set to.

I used an online AVR calculator, and had the clock set to Ext. Crystal High Freq 16K CK + 64ms, but on that setting I get this issue. I even tried Mid Freq and Low Freq settings, but none of them solve the problem. Any ideas on what the fuse settings should be, or if something else could be amiss?

Your help is appreciated :)


*EDIT* Tried fuse setting for the internal clock at 8 mhz, got the same problem.
Last edited by wireframewolf on Thu May 01, 2008 5:38 pm, edited 1 time in total.
wireframewolf
 
Posts: 21
Joined: Wed Mar 05, 2008 10:04 pm

by The_Don125 on Thu May 01, 2008 5:37 pm

Check your code for a line that looks like:
Code: Select all | TOGGLE FULL SIZE
#define F_CPU 1000000UL         /* 1MHz crystal oscillator */


And change it to go along with your clock rate. So, for 16MHz, you'd want:
Code: Select all | TOGGLE FULL SIZE
#define F_CPU 16000000UL         /* 16MHz crystal oscillator */


Also, check if the fuse that divides the clock by 8 is turned on. That could be taking your 16MHz clock and turning it into 2MHz
The_Don125
 
Posts: 373
Joined: Tue Mar 06, 2007 11:51 pm
Location: Illinois

by wireframewolf on Thu May 01, 2008 5:43 pm

Well, in the make file you actually set it with a variable like:
CLOCK = 16000000

And when it's compiled, there are these lines that pass the variables into the C code somehow:
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

And it seemed to work great with the atmega168. I actually realized that I'm using 22pf caps instead of 20pf caps for the crystal (which is what the example is using) but since the internal clock also seems to be having this timing issue, I'm not convinced that is the problem. However, maybe I'll try changing around the make file and just defining F_CPU by myself, and see if that works.
wireframewolf
 
Posts: 21
Joined: Wed Mar 05, 2008 10:04 pm

by mtbf0 on Fri May 02, 2008 8:30 am

could it be your code?
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by mtbf0 on Fri May 02, 2008 8:43 am

could it be your code?
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by wireframewolf on Fri May 02, 2008 1:38 pm

I doubt it. I upload the same code to the atmega168, then the atmega16. However, where as the atmega168 seems to being running at the right time, the atmega16 does not:

Code: Select all | TOGGLE FULL SIZE
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
   DDRD = 1 << 4;
   /* make the LED pin an output */
   for(;;) {
      char i;
      for(i = 0; i < 10; i++) {
         _delay_ms(30);  /* max is 262.14 ms / F_CPU in MHz */
      }
      PORTD ^= 1 << 4;   /* toggle the LED */
   }
   return 0; /* never reached */
}


As I said before, F_CPU is defined by a variable in the make file, which looks like this:

Code: Select all | TOGGLE FULL SIZE
#This should use the atmega16's internal clock

DEVICE     = atmega16
#DEVICE     = atmega168
CLOCK      = 8000000
PROGRAMMER = -c usbtiny
OBJECTS    = main.o
FUSES      = -U hfuse:w:0x99:m -U lfuse:w:0xe4:m
#FUSES      = -U hfuse:w:0xdf:m -U lfuse:w:0xff:m -U efuse:w:0xf8:m

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
#more stuff
wireframewolf
 
Posts: 21
Joined: Wed Mar 05, 2008 10:04 pm

Please be positive and constructive with your questions and comments.