I have 2 microcontrollers (Atmega 168PA-PU). So far I have run the following program in one of them (say mc1). Now when I run the same code in the other one it gives erroneous results. Someone suggested that the inbuilt RC oscillators give +/- 10% error in system frequency and that is enough to throw the device out of balance. So I have decided to use external 12MHz oscillator crystal and connect them to XTAL1 (pin 9) and XTAL2(pin 10) with 22pF capacitors (ceramic). I burn my programs with avrdude. What is the appropriate fuse setting I should use? The AVR fuse calculator confused me even further.
PS: I am a newbie so i am sharing whatever i have learned, if there is any mistake please let me know so that in future i can rectify myself.
Yeah you are right internal RC oscillator is not perfect...The clock varies with temperature and the power supply voltage.So it is better to use external crystal oscillator that won't drift with the temperature and if you want to use 12Mhz crystal then you should go for full swing crystal option.
Clocks sources usually need a little bit of time to warm up and start giving us a reliable signal when the micro controller is turned on. This is called the start-up time. To play it safe,you should go for the maximum start-up time to give the clock as much time as it needs to get up to speed. Actually, the max start-up time is only a few milliseconds anyway! So to be safe you should go for a Start-up Time of 16K CK and an Additional Delay of 65ms.
If you are using avrdude then i found it most helpful to use AVR fuse calculator for avrdude commands and the link is-- http://www.engbedded.com/fusecalc/ .Whatever argument is generated in the AVR fuse calculator you should copy and paste after this argument(iff you are using USBASP device with avrdude otherwise you have to use commands according to your device)...
avrdude -c usbasp -p m168
e.g. for your case you may use this command...
avrdude -c usbasp -p m168 -U lfuse:w:0xf7:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m
In case of any problem with the efuse you can omit that and write only
avrdude -c usbasp -p m168 -U lfuse:w:0xf7:m -U hfuse:w:0xdf:m
You may find this tutorial helpful..http://www.ladyada.net/learn/avr/fuses.html and also go through Clock section of your micro-controller's datasheet.
Let me know if there is any more doubt.