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.

  • \$\begingroup\$ Did you even bother to look at the fuse section of the datasheet? \$\endgroup\$ – Matt Young Jan 21 '14 at 14:38
  • \$\begingroup\$ I have found in the datasheet that For Full swing crystal oscillator CKSEL=0111 - 0110. But I do not know where to configure it. \$\endgroup\$ – Rambo partyush Jan 21 '14 at 14:49
  • \$\begingroup\$ Do you use an IDE or command line only? Which programmer device? \$\endgroup\$ – alexan_e Jan 21 '14 at 15:32

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.

  • \$\begingroup\$ will try it and let you know @Subhankar \$\endgroup\$ – Rambo partyush Jan 22 '14 at 15:01
  • \$\begingroup\$ Yup what you suggested worked properly. @Subhankar Ganguly. \$\endgroup\$ – Rambo partyush Jan 24 '14 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.