Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
clawson
PostPosted: May 01, 2011 - 07:46 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

A large proportion of the threads posted to this website are as a result of experiments with ISP and setting fuses that have gone wrong and left the chip in a state where it appears you can no longer do ISP any more.

The good news is that about 90% of the time you can easily recover from the situation you find yourself in, though there are some "dangerous fuses" on some models of AVR which can make recovery a bit more tricky (but never impossible).

The usual "damage" is simply that you have changed the state of the CKSEL fuse bits. When you first take an AVR out of the packet it's fuses are set so that when power is applied it will clock at about 1MHz from an internal RC oscillator (in some cases it is 1.2MHz if the main clock is 9.6MHz, rather than the more normal 8MHz). The advantage of the chips being supplied in this way is that ISP can only work when the CPU will clock with power applied, so with no external circuitry (apart from power) it's possible for your ISP programmer to connect to and program the chip. The "accident" most people have is to inadvertently change the CKSEL fuses to choose some form of external clock that isn't present. Now this could be that you really meant to use a crystal but you actually wrote a combination of CKSEL fuse bits to select "external oscillator" - that is NOT a crystal and just connecting a crystal and a couple of capacitors is not sufficient if "external oscillator" has been selected - the chip is waiting for a full-swing TTL square wave to be applied and a crystal won't do.

If you have had such a "clock accident" then recovery is fairly simple. The chip is just waiting for a clock to be applied - so apply one. Now you may say "but I don't have an external oscillator" but there are a number of things that can be done to provide the clock that the chip is waiting for. In all cases this involves applying a clock signal to the XTAL1 pin of the chip where CKSEL was mis-set. This will be enough to have a successful ISP session to change the CKSEL fuses back to something more sensible. Perhaps the most sensible choice (at least initially) is to put the fuses back to exactly the way they were when the chip first arrived. If you take any AVR datasheet and go to the chapter on "Memory Programming" there is a subsection "Fuse bits" which shows each of the fuse bytes and what their default value is.

One key thing to note is that ISP must always run at less than 1/4 of the clock frequency of the AVR. So if you apply a 1MHz clock signal to the XTAL1 pin then the ISP programmer must be set to run at 250kHz or less.

Possible source for such a clock signal (in no particular order) are:

1) an STK500. This has an on-board clock circuit. In AVR Studio, when you connect to the STK500, you can program this clock to some division of 3.6864MHz

2) an STK600 has a very similar clock circuit though its upper frequency limit is higher than the STK500

3) an NE555 can easily be wired up with a handful of components to generate about 1MHz

4) another AVR can be used if you load a program such as:
Code:
#include <avr/io.h>

int main(void) {
  DDRB = 0xFF;
  while(1) {
    PORTB ^= 0xFF;
  }
}

this will toggle all the pins on PORTB as fast as possible (OK, modern AVR have a better mechanism where you write to PINB - but I'll ignore that for the time being). Anyone of those PORTB pins (together with a common GND) can be connected to the AVR that needs to be recovered.

5) "modern" AVRs have both a fuse and a pin called CLKOUT. By activating the CLKOUT fuse (be careful this time!) the CLKOUT pin will produce full-swing signal at the CPU's clock frequency so even a brand new chip out of the packet can produce 1MHz this way simply by activating (setting to 0) one fuse bit and applying power.

6) Use a frequency generator set to square wave and something around the 1MHz mark (could be faster if you like)

7) <this list open to further suggestions Wink>

If it's just a CKSEL "accident" this should have allowed you to fix the situation.

Another potential clock problem is where you attach a crystal (with caps), set the correct CKSEL fuses and it still will not oscillate - this may be caused by not setting the CKOPT fuse (if the AVR has this) or selecting "Full swing" when the crystal is 8MHz or more. This mode of operation uses more power (which is why it's not selected by default) but is required to get higher frequency crystals to resonate correctly. If the AVR is in this situation the foregoing technique should also recover it.

Now some chips (mainly the lower pin count ones) have some more "dangerous" fuses that can make it seriously more difficult to recover.

The chips that can be debugged with "debugWire" have a fuse called DWEN which is mutually exclusive with the SPIEN fuse (the one that allows ISP to operate). If DWEN is set then the _RESET pin on the chip can no longer be used to invoke ISP and can only be used for debugWire. When a chip is in this state you need a device that can do debugWire (Dragon, JTAGICEmkII, AVR One!) in order to recover - you need to start debugging using debugWire then (with all the ISP wires attached) use the bottom entry on the debug menu in AVR Studio 4 where there is an option to disable debugWire mode and this will reinstate ISP mode. If you don't have a suitable device either find a friend who does or accept that the $2-$3 that the chip cost is less than the $50 that a Dragon will cost and write this off to experience (it's a pretty fair bet you won't make this mistake again next time you program fuses!).

Perhaps the most insidious of all the fuses is the one found on low pin count AVRs called RSTDISBL. Because these AVRs have so few pins they can sacrifice the use of the _RESET pin to be used (usually) as another GPIO pin instead. The problem is that ISP works by holding the chip in reset and it does this by pulling the _RESET pin low. If that pin has now been disconnected from the internal _RESET signal in favour of using it as an I/O then you simply cannot start ISP ever again in order to recover the situation.

If it is RSTDISBL that has been set then there IS a way back but for this you are going to need a device that can do High Voltage programming. That basically means a Dragon, an STK500 or an STK600. For the very low pin count AVRs these can do HV Serial Programming, while for the larger ones HV Parallel Programming is used. HVSP isn't TOO bad as it doesn't use many more pins than ISP, but HVPP is a real problem as it uses the best part of 20 pins on the AVR. What's more both HVSP and HVPP actually work by applying +12 Volts to the _RESET pin of the chip. Most circuits that the AVR has been designed into will not tolerate having 12V applied in this way and could be damaged and if 20 pins are involved (often 20 out of 28 ) then it's very unlikely that the surrounding circuitry has been designed to allow the intrusion of an HVPP programmer. So if you have set RSTDISBL and the chip is not socketed so it can be lifted and placed in an HV programmer such as STK500/STK600 or even the small prototype area of a Dragon then accept the fact that your $2-$3 chip is lost. Desolder it from the board and write this off to experience - you'll be more careful programming fuses next time! Wink

BTW, when using AVR Studio (4) as a programming tool it's very difficult to have a "fuse accident" in the first place. Other programming tools make it less obvious what's actually being chosen so you may want to use this site:

http://www.engbedded.com/fusecalc/

which mimics the interface of AVR Studio to verify that you are selecting the right values. Note that fuses are ACTIVE LOW which means you enable them when the bit is 0 and disable when the bit is 1. Rather confusingly some programming software (PonyProg) even lets you switch whether a tick means "enabled" or "disabled". So be very cautious next time you set fuses. Measure twice, cut once as the old saying goes and when using ISP software to changes fuses always do a read first, determine only those bits that need to be changed, make that change then write back.

[this is just a "prototype" article - I welcome comments and feedback for improvements]

_________________


Last edited by clawson on Jun 11, 2011 - 08:43 PM; edited 2 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
kulu2002
PostPosted: May 04, 2011 - 01:20 PM
Rookie


Joined: Nov 30, 2010
Posts: 37




Last edited by kulu2002 on May 05, 2011 - 05:21 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: May 04, 2011 - 11:33 PM
10k+ Postman


Joined: Mar 28, 2001
Posts: 22238
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

So should the thread be now locked as discussed elsewhere before we get 2 million posts and we won't be able to see the forest for the trees? Smile

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: May 06, 2011 - 11:00 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

What did I miss while I was away?

Anyway, I'm still open for suggestions/changes/improvements - but this thread should not be used for anything else - such as discussing specific instances of "lockout"

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
meslomp
PostPosted: May 06, 2011 - 11:13 AM
Raving lunatic


Joined: May 02, 2007
Posts: 3712
Location: Nieuwegein, Netherlands

Code:
POTB ^= 0xFF;


I think you made a typo there.
should be PORTB

[thanks - corrected now - it's this new PC - where the keyboard cannot seem to cope with fast typing PORT Sad]

_________________
1)Datasheet and application notes checked?
2)tutorial forum
3)Newbie start here
 
 View user's profile Send private message  
Reply with quote Back to top
meslomp
PostPosted: May 06, 2011 - 11:19 AM
Raving lunatic


Joined: May 02, 2007
Posts: 3712
Location: Nieuwegein, Netherlands

Another one is that a large number of AVR's has a CLK/8 fuse.
when this fuse is set the actual CPU frequency is 1/8th of the frequency applied to the XTAL1 pin.

So when one is not sure if this fuse is set or not then also take this into account.

example when applying 8MHz to the XTAl1 pin, the actual core frequency is only 1MHz as you need to be below 1/4th of that the maximum programming speed is 250KHz. Keeping in mind that the actual frequency could be below that so better be safe and take the programming speed that is lower then the 250KHz ( the actual choice depends on the programmer used).

regards

[good point - though I mentioned 250kHz I forgot to emphasise that this should be tried first if things aren't "talking" - OTOH a "lockout" tends to suggest a chip that was working but has lost contact after a "fuse accident" so that kind of implies they started out with ISP using working settings?]

_________________
1)Datasheet and application notes checked?
2)tutorial forum
3)Newbie start here
 
 View user's profile Send private message  
Reply with quote Back to top
kulu2002
PostPosted: May 06, 2011 - 01:00 PM
Rookie


Joined: Nov 30, 2010
Posts: 37


Nice tutorial Cliff,
It would be nice, if you could throw some light on number of options that are displayed in dropdown list while setting the SUT_CKSEL fuse from AVR studio in the form <clock source, freq in MHz>; Start-up time: <abc> CK + <xyz> ms
for instance;Int. RC Osc. 1 MHz; Start-up time: 6 CK + 64 ms
In mentioned above what does the Start-up time indicate? How to determine which option to select?


P.S. If this is irrelevant please delete the post[/b]
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 06, 2011 - 01:57 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

kulu,

I don't think I'll go there as this is specifically how to recover from "lockout" though I guess if you have a crystal with a stupidly low SUT time that could be an issue so I may mention that.

Most AVR datasheet have a good section on clock options that explains the options in such a droplist.

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: May 06, 2011 - 02:32 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21408
Location: Lund, Sweden

And, to add to Cliff's latest post: Unless you have compelling reasons to do otherwise, stay with the longest possible SUT. It's there for dealing e.g. with power supplies that take a (relatively) long time to start up.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: May 06, 2011 - 02:37 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

It's there for dealing e.g. with power supplies that take a (relatively) long time to start up

I thought it was for crystals that took a long time to start resonating?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: May 06, 2011 - 08:48 PM
10k+ Postman


Joined: Mar 28, 2001
Posts: 22238
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
this thread should not be used for anything else
Neither should the other tutorial threads.. Smile oh did you break your rule above? Wink

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
RickB
PostPosted: May 07, 2011 - 05:17 AM
Resident


Joined: Jan 30, 2005
Posts: 976
Location: Junction City, OR USA

Once again I'll say it. We need a sandbox for tutorials. When it's whipped into shape, it, minus the irrelevant post like this one can be moved to the tutorial forum.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 07, 2011 - 12:06 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

Rick,

What John and I have been toying with is the idea of allowing a tutorial to be posted - maybe a discussion for a month or two until it "solidifies" then locking the thread to protect against "noise" and that process may even involve the removal of the change/fix comments from that first month.

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
valusoft
PostPosted: May 07, 2011 - 01:29 PM
Raving lunatic


Joined: Jul 02, 2005
Posts: 7161
Location: Melbourne, Australia

Good suggestion.

_________________
Ross McKenzie
ValuSoft
Melbourne Australia
 
 View user's profile Send private message  
Reply with quote Back to top
westfw
PostPosted: Aug 14, 2011 - 12:37 AM
Posting Freak


Joined: Jun 19, 2002
Posts: 1331
Location: SF Bay area

Is there a way that an ISP programmer can tell whether an external clock source is connected, so that it could issue dire warnings before setting the "external crystal" or "external oscillator" fuses? Assume that I'm willing to burn a short test program if that will help.

For instance, assume that I have something called OptiLoader, designed to load a new bootloader onto ATmega8/168/328 for clueless but cheap Arduino users. I can read the signature and determine which chip is there; I can read the fuses - if they are already set for a 16MHz crystal, that's great; I can probably assume that there really is one. But if they say that I am using the 8MHz internal oscillator with the divisor (factory default), I'd like to be able to tell the difference between "this is a brand new chip in a circuit with a 16MHz crystal" and "this is brand new chip in a breadboard that someone wants to make run without a crystal." Or at least I can avoid "lock out"...
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Aug 14, 2011 - 11:29 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

westfw, well this article is really about when a non-existent clock has been selected but in your case if ISP can read the signature then surely the CKSEL and possibly CKDIV8 fuses can be read to determine which clock source is active (it obviously IS active otherwise you couldn't read the signature).

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
darsie
PostPosted: Sep 20, 2011 - 07:18 PM
Rookie


Joined: May 11, 2007
Posts: 43


A clock can be made with a NOT, NOR, NAND gate feeding its output via a resistor back to the input that has a capacitor to ground.

Building an astable multivibrator with 2 transistors, 4 resistors and 2 capacitors is also not hard, but I don't know if the edges are steep enough.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Sep 20, 2011 - 07:22 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

It'd be great if you could post a schematic of that.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
darsie
PostPosted: Sep 20, 2011 - 10:09 PM
Rookie


Joined: May 11, 2007
Posts: 43


Multivibrator from http://en.wikipedia.org/wiki/Multivibrator



Oscillator and uC ground (negative supply) must be connected. For the multivibrator the clock output would be taken from the collector (top leg) of one of the transistors.

Any general purpose / small signal amplifier NPN transistor such as BC546 should be ok.

R1=R4=1K
R2=R3=15K (=R)

C1=C2 (=C): the smaller the higher the frequency. Maybe 1 nF is suitable.

f=0.721/(R*C)

So with R=15K and C=1nF that would be about 48kHz.

R2/3 may need to be bigger than R1/4. So if you scale each by 1/10 you should get 480 kHz.

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

The circuits with the NOT, NAND and NOR gates require Schmitt trigger inputs, indicated by the hysteresis symbol in the gate symbol. The schematics are only visible when you are logged in.

Probably best are some CMOS types (e.g. 74HC14). You can search digikey for suitable ICs (category "Logic - Gates and Inverters"). They don't have to be very fast, but the rise/fall time of the clock edges should meet the uC specifications (datasheet section Electrical Characteristics/Clock Characteristics). Always put decoupling capacitors across the GND/- and VCC/VDD/+ pins of your ICs, something like 22 uF electrolytic and 100 nF ceramic as close as possible to the GND/VDD pins. This will help keep the rise/fall time short.
For more details see this thread: http://forum.allaboutcircuits.com/showthread.php?t=45583

Smaller timing resistors/capacitors (not the decoupling capacitors) increase frequency. You can put the output of the gate through another gate (as shown in the NOT oscillator circuit) to get a stronger, sharper signal. There are usually several gates in an IC anyways.

100 Ohm and 1 nF might be a good starting point. The extreme case would be no capacitor and a short circuit instead of a resistor, but that may be too fast and not yield a nice square wave.

You can verify the basic operation of your circuit by using big caps and resistors so you get an audible/visible frequency and hook up a piezo speaker or LED.

I have not used these circuits as clock before, so there's no warranty Smile.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Dec 22, 2011 - 10:31 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69452
Location: (using avr-gcc in) Finchingfield, Essex, England

If all else fails there's a fuse recovery design here:

http://www.radiolocman.com/shem/schemat ... l?di=65084

It uses HVPP.

Also this:

http://www.mtcnet.net/~henryvm/4AvrFuseBuster

_________________


Last edited by clawson on Jan 05, 2012 - 12:01 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits