Go Down

Topic: Request: bootloader options for brownout detection (Read 4895 times) previous topic - next topic


Aug 12, 2008, 03:52 am Last Edit: Aug 12, 2008, 01:43 pm by CosineKitty Reason: 1
I have been having problems with my ATMEGA8 program memory getting corrupted when I cycle the power on my experimental digital clock board:


I am using a 9V wall adapter, and apparently what was happening was that when I unplug it, it has a capacitor that gradually loses its charge, so the voltage it supplies to the voltage regulator gradually (meaning many, many milliseconds!) falls to zero.  I confirmed in the ATMEGA8 data sheet, and elsewhere, that this can cause the ATMEGA8 to execute instructions incorrectly, and thereby overwrite program memory.

I also found a fix:  for the ATMEGA8 only, you can change the low fuse byte from 0xdf to 0x1f.  This will NOT work on ATMEGA168; I have not yet read that microcontroller's data sheet to figure out the proper value.  Quit out of Arduino if you are running it, then edit the file hardware/boards.txt in your Arduino install and add the following lines at the front of the file:

Code: [Select]


atmega8bod.name=ATMEGA8 with brownout detection




Note that I just copied the "Arduino NG or older w/ ATmega8" configuration, renamed all the "atmega8" prefixes to "atmega8bod" (bod = Brown Out Detection), changed low_fuses from 0xdf to 0x1f, and the "name" field.  

After saving boards.txt, run Arduino, hook up your bootloader hardware (I use the do-it-yourself parallel port), and select Tools/Board.  Choose the "Custom ATMEGA8 with brownout detection" option (the one we just added to boards.txt).  Then choose Tools/Burn Bootloader, and then the appropriate hardware connection.

Afterward, you will need to hook up the serial port and reload whatever software you want to run on the chip, because the bootloader burn will have erased anything in there.

So far this seems to be working... my program memory is no longer corrupted, no matter how many times I unplug and replug my wall adapter.

My request to the Arduino developers is, can you provide options for all of these in the standard Arduino install?  If it would help, I can try to research what all the fuse bits should be for the other microcontrollers.  I will need somebody else to help me test in all the hardware configurations I do not own.




So what would be the fuse settings to use this technique on the ATMega168?
(I know about the fuse calculator - but I want to be sure.)

I've had similar problems as cosine. Sometimes I even lost the bootloader.
Perhaps other's do too - it seems to be a common occurrence.
People power the Arduino with all kinds of wall worts and batteries.

I also wonder, out of curiosity, why the BOD was disabled in the first place.
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll


same here. no more lost bootloaders or corrupt programs since enabling BOD on my 168's. i must say that i'm mostly running them from just 4 AA rechargables without a regulator. so lost bootloaders was a huge issue for me :-)

since this problem mostly appeared with my own creations, i believe BOD is disabled by default just because it's not needed in normal(PLUS) use, with a proper designed board. the only disadvantage of brownout detection i can imagine , would be unwanted resets in otherwise uncritical situations.


PS: i'm using avr studio on a friends PC to burn the bootloaders. so i can't tell about the correct fuse settings for the BOD levels on the AtMEGA128 now.


When reading the ATMEGA8 data sheet, the disadvantage they mention about brownout detection is that it consumes slightly more current from the power source.  However, this is a small price to pay for most applications.  I would think brownout detection should be the default, since most of us experimentalists have enough problems trying to get stuff to work!  However, disabling brownout detection should be an option for projects that are trying to be as power efficient as possible, and that have well-regulated power with auto-shutdown of the power supply when the voltage gets too low.


This might give some help with the ATMEGA168 fuse bits:


Also... we always have the multi-hundred-page confusingly written data sheets!!!  :)

- Don


Sep 11, 2008, 06:06 am Last Edit: Sep 11, 2008, 06:38 am by BroHogan Reason: 1
Did some poking around, and if I'm right, I found the following with respect to the 168:

The BOD fuses are already set for a 2.7V BO.
This is true in both rel. 0010 and 0011.
Boards.txt for the 168 has the Fuse High Byte set to 0xDD which gives b101 for BODLEVEL:2-0.
(per the datasheet p. 288 & 308)

This surprises me since I have read several times here that BOD is not set at all on the 168.

Now it could be that 2.7V is on the low side (the 168 chip runs between 2.7V - 5.5V and the 168V chip runs between 1.8V - 5.5V).

It appears that if you want to set the BOD to 4.3V, you need to change the Fuse High Byte to 0xDC.

Someone please correct me if I'm wrong. If not I'll try it and report back.

I'm also not sure what the diff is between the ATMega168 and ATMega168V, but I assume the "V" is the surface mount Lilypad type.

Here is what I will try in boards.txt . . .
Code: [Select]


diecimilabod.name=Diecimila w/ 4.3V Brownout




[edit]Well, it looks like the "V" is the low voltage version.  :-?[/edit]

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll


I hooked a variable power supply to the Arduino and did some tests on BOD.

The "standard" (Rel. 0010 & 0011) fuse settings do indeed trigger BOD at 2.7V.

Using the fuse settings above (high fuse = 0xdc) BOD is triggered at 4.3V.

I think some of the confusion as to whether or not the Arduino uses any BOD at all, comes from this tutorial, which is probably dated.

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll


BroHogan, thanks for confirming that!  I need to get one of those variable power supply thingies! :)

The problem with the 2.7V default is that the processor is already mis-executing instructions at this point, leading to unpredictable results, including corrupting program memory.  I was aware of this lower setting when I read the data sheet, but I probably did not make this clear.  It's pretty scary when your chip can do random stuff and corrupt memory before getting reset!  I was having to re-flash my ATMEGA8 every now and then before I made this fuse bit change on it.

- Don


Sep 15, 2008, 10:33 pm Last Edit: Sep 15, 2008, 10:34 pm by BroHogan Reason: 1
I agree, 2.7V seems to be too close to the edge.
I will be using a 4.3V bootloader on all my battery driven projects.

Since we're already paying the price in "increased current consumption in sleep mode" for the 2.7V BOD, why not? (Not that I really cared  anyway.)

Glad if this helped some of you.
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131