PDA

View Full Version : Using External Crystal for AVR MCU



ankitmutha
09-30-2008, 01:37 AM
Hi all,
I tried to search the forums here but i could not get an appropriate answer to my queries so im posting a new topic.
Sorry if it's been repeated.
-------------------------------------------------------------------

I'm new to AVR programming.
I had AtMega8-16PU.
I flashed some hex file to it successfully without touching the fuse bits.
I wanted to use 12Mhz ext crystal as clock source.
I change the fuse bits setting to:

HFUSE: 0xC9
LFUSE:0x9F

------------------------------------------------------------------------
Problem: My mcu has stopped responding. The programmer doesnt recognize it.
------------------------------------------------------------------------

Critical Info:
1. I used a not so standard Parallel Port Programmer AtProg built using the schematics here..http://www.speedy-bl.com/avr-prog-e.htm
2. The programmer uses serial downloading commands for setting fuse bits
So i gave commands:
;for LFUSE
AC A0 00 9F
;for HFUSE
AC A8 00 C9

refer to datasheet ATMega8.
3."IM NEW TO AVR PROGRAMMING" :wink:

--------------------------------------------------------------------------------

Some idea i gathered:
1. When fuse bits are set for using the ext crystal the mcu now depends on ext crystal for its working. so every time it is to be used we need to provide the ext crystal. even we have to program it. the programmer will not detect it unless the ext crystal is provided coz the mcu wont work without it.

So i put the same 12Mhz crystal in the board for which i intended to use the mcu. but still the programmer doesnt detect it i have no clue if its working or not.

2. I learnt that we can reset the fuse bits of the mcu using High Voltage Parallel Programming.
This option is available in STK500 kit but unfortunately i have no access to it.
One schematics i found on net which could do HVPP is here:http://elm-chan.org/works/avrx/report_e.html
But i'm not sure if it will work at all.
And moreover i'm looking for a alternate easy solution if there is any.

-------------------------------------------------------------------------------

Some very basic query:
IF i use PonyProg2000 and STK200/300 dongle to program the mcu and then try to change the fuse bits settings for using ext crystal.. will PonyProg also not detect the mcu??

I guess this is a very basic query and a problem faced by almost all newbie i assume.
HOW DO WE PROGRAM MCU SO THAT IT CAN USE EXT CRYSTAL????

Plz provide any information you have regrading this.. all replies appreciated. this will help any like newbie learn without screwing up the mcu.

vikas
09-30-2008, 04:50 AM
Dont mess with the fuses if you dont know what u doing :twisted: .

Anyhow u have set it to ext low frequency crystal. Not what u wanted to set it to.

It should have been this , i think

HFUSE: 0xC8
LFUSE:0x9F

If you cant find a low freq crystal , welcome to the bricked club :) . HV programmer is gonna be more exp than replacing a mega 8.

ashish_agarwal123456
09-30-2008, 11:30 AM
@ankitmutha
i am asking this for third time..... is your uC atmega8 or atmega8L. because most probably it would be megaL. its more popular nowadays because of low power and cost. if so maximum allowed frequency is 8MHz.

and for fuse bits . they are a mess.
according to me the settings for your case should be (making changes only to clock selection needs and keeping other things at default)
HFUSE: 0xC9
LFUSE: 0xEF
use two 27pF or less capacitors.

@both
why are you enabling the brown out detector??
there is a twist in SUT settings. with internal oscillator SUT1,0=10 means low frequency and with external crystal SUT1,0=10 means high frequency.

ankitmutha
09-30-2008, 02:47 PM
@ashish
i very clearly mentioned my mcu is ATMega8-16PU
This 16PU or sometimes 16PI means this mcu can work at max 16MHz..
Hope im clear.
As for the rest Actually i was programming this AtMega8 for USBasp firmware and the README.txt with it very said i needed to change the fusebit settings for ext crystal..
And wen i read it's makefile it was clearly mentioned the same fuse settings as i have done:

------------------------------------------------------------------------------------

# Fuse atmega8 high byte HFUSE:
# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
# | | | | | +-------- BOOTSZ1
# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
# | | | +-------------- CKOPT (full output swing)
# | | +---------------- SPIEN (allow serial programming)
# | +------------------ WDTON (WDT not always on)
# +-------------------- RSTDISBL (reset pin is enabled)
# Fuse atmega8 low byte LFUSE:
# 0x9f = 1 0 0 1 1 1 1 1
# ^ ^ \ / \--+--/
# | | | +------- CKSEL 3..0 (external >8M crystal)
# | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
# | +------------------ BODEN (BrownOut Detector enabled)
# +-------------------- BODLEVEL (2.7V)
--------------------------------------------------------------------------------------
And moreover i read the datasheet i found the CKSEL CKOPT SUT were okay.. rest i did not bother about.
So i have no idea of BrownOUt detector things.. i'l read about it and then post.

@vikas
don't get angry.. after all i lost a mcu not u :wink:
And u won't learn until u loose fear of failure.
It's Okay it was my first attempt after all

And i cant understand how do u think changing the HFUSE(that too BOOTRST to 0) could possibly affect the ext clock settings????
Except that there's no difference between wat u mentioned and wat i have done.
And how do u say i set it to low frequency crystal..??
I referred the data sheet and it clearly says..


Device Clocking Option CKSEL3..0

External Crystal/Ceramic Resonator 1111 - 1010
External Low-frequency Crystal 1001
External RC Oscillator 1000 - 0101
Calibrated Internal RC Oscillator 0100 - 0001
External Clock 0000

AND


CKOPT CKSEL3..1 FrequencyRange(MHz)
1 101(1) 0.4 - 0.9
1 110 0.9 - 3.0
1 111 3.0 - 8.0
0 101, 110, 111 1.0 ≤

@all
What's done is done
Plz tell me how to set the fuses for ext crystal.
plz help out

vikas
09-30-2008, 03:09 PM
im just teasing ;) ... not angry

Anyway here is a calculator for you

http://www.engbedded.com/cgi-bin/fc.cgi/?P_PREV=ATmega8&P=ATmega8&V_LOW=C1&V_HIGH=99&M_LOW_0x3F=0x08&M_LOW_0x80=0x80&M_HIGH_0x06=0x00&M_HIGH_0x20=0x00&M_HIGH_0x40=0x00&B_WTDON=P&B_SUT1=P&B_SPIEN=P&B_SUT0=P&B_CKSEL3=P&B_CKSEL2=P&B_BOOTSZ1=P&B_CKSEL1=P&B_BOOTSZ0=P

ankitmutha
09-30-2008, 03:51 PM
@vikas
thanks a great link...
but did u read this thing given below???

"Unreviewed original XML backend database from Atmel. Possibly buggy!"

ha ha ha :lol:

vikas
09-30-2008, 03:55 PM
I know that , Most things have conditions attached :) .

ashish_agarwal123456
09-30-2008, 06:01 PM
@vikas
really great link......

@ankitmutha
ah, i didnt knew about that 16PU thing..... thanks for sharing.

well, the calculator show that all three of us are right in selecting clock, the only difference is in other settings and i think they wont affect the working here.

ankitmutha
09-30-2008, 07:02 PM
@ashish
okay... we agree at something atleast.
So where's the problem??
If fuse settings are okay.. y doesnt the mcu work??

can u ppl share ur experiences of using ext crystal??
how did u do it?? wat programmer did u use to set fuse?? plz help out.

ashish_agarwal123456
09-30-2008, 09:36 PM
here in my city only 'L' version is available (and i also prefer them because of low cost). so never used more than 8MHZ crystal. i used a 4MHz crystal just to try and i faced no problem. i cant say which programmer it was. actually i used avrdude and changed the config file according to me. so that was not some standard programmer.

ashish_agarwal123456
10-01-2008, 11:45 AM
have you tried decreasing the speed of atprog?

ankitmutha
10-02-2008, 01:57 AM
yes.. i tried that.. nothing works..
now im building a new ponyprog serial progrmmer. i'l try with that.
and well i gotta know this the circuit that is given for At-Prog is nothing but a simple bsd programmer.

Nivedita
10-02-2008, 08:14 PM
Use HandyProg for programming, its user interface is simple for fuse bit settings.
[/img]

ankitmutha
10-02-2008, 08:53 PM
HandyProg??
I thought of using PnoyProg... infact im done with the hardware interface of PonyPorg.( but the thing keep saying "Device Missing or Unknown Device(-24) I'l have to fix that.)

ankitmutha
10-02-2008, 08:59 PM
Anyways C'on ppl u all must have used ext crystal with one of the avr mcus.. plz tell me wat programmer did u use and did it work..? after setting the fuse bits mine's stopped working did the same happen to u..??

vikas
10-02-2008, 11:45 PM
Ive used pony prog a lot ( my fav AVR ISP programmer ) ... and i always use external crystals.

Just set the fuses right :) ... works just fine.

avinash_g
10-06-2008, 07:40 PM
Hi,

I am giving a tested fuse setting. I have used them on more than 30 ATmega8 MCUs

FUSE LOW = 0xFF
FUSE HIGH = 0xC9

@ashish_agarwal123456 It is not like ATmega8L-8PU won't work with a 12MHz crystal I have successfully overclocked ATmega8-8PU upto 16MHz !!!

It u provide 5V to the "L" they will happily work over 8MHz

ashish_agarwal123456
10-06-2008, 09:01 PM
@avinash_g
hey!!! i didn't knew that.... will give it a try...

ankitmutha
10-22-2008, 03:38 AM
@all
thank u all for showing such enthusiasm and helping me out.

Problem Solved!


I used some programmer in which i had to give commands for setting the fuses and i dont know how but i made mistakes and messed up with the lock bits and so it was not responding.

In fact vikas, ashish,... u all were right. its about getting the fuses right!!

Lesson: for everyone who starts out with Atmega fuse settings i would suggest to use some good programmer with GUI so that u never mess up.
Use Ponyprog or AVRstudio.

I use avr studio and now i never mess it up wen setting fuses.. it jus works fine each time.