Continuing the work I have been doing on the open-source charge controller project, I needed to ensure that the microcontroller reset correctly when the supply voltage drops.

The charge controller is powered from the renewable energy source and so the input voltage will vary (for example on a solar PV module at night the voltage will drop and during the day the voltage will rise).

I had noticed that when the supply voltage dipped but then returned to a stable value, the micro-controller (an ATTiny85) sometimes froze or did not act correctly. I needed to ensure that the device reset correctly when the voltage dipped below the working voltage range of the micro-controller. This was implemented using the brown-out detect facility of the microcontroller.

Update 26/7/2022 – This post was written in 2013 and is now a bit out of date! The Brown Out detection settings for the ATTiny85 are now included within the Arduino IDE via the “Tools” drop down menu.

I typically use the ATTinyCore installed via boards manager, which includes these options (https://github.com/SpenceKonde/ATTinyCore).

Research

As always the Internet offered some people who had already encountered this problem and who have offered up their experiences (one of the main reasons I write these posts is for others in a similar situation).

The main guide I used included a you-tube video and a detailled write up.

Within most microcontroller there is a facility called brown-out detection. A brown-out is a term used to describe a dip or drop in voltage supply. A black-out is when there is a total loss of voltage, but a brown-out could just be a dip below the voltage range of the micro-controller.

By default the brown-out detection (BOD) is usually not enabled. In order to enable it you must change some of the fuse settings.

This is detailed very well in the guide above, but here are my notes:

You will need to burn the fuses within the micro-controller to enable the brown-out detection.

The first thing to do was find out what values to set the fuses to. This can be done by reading the data-sheet (which is always a good idea), or you could use an on-line calculator such as this one. I set the ‘Brown-out detection level Vcc=4.3V’.

I also ticked ‘Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]‘. (This was only found later, after having loads of problems with my EEPROM calibration routine. It turned out that the EEPROM was being erased every time!).

This gave me the three fuse settings I needed: Low: 0xE2, High: 0xD4 and Extended: 0xFF.

You will need to alter the “boards.txt” within the ‘sketchbook/hardware/attiny’ directory. This has a list of all the various types of board that can be implemented. I used the ‘ATTiny85@8MHz’ section as a template. I created a new board as shown here:

###########################################################################

attiny85at8b.name=ATtiny85 @ 8 MHz  (internal oscillator; BOD enabled 4.3V)

# The following do NOT work...
# attiny85at8b.upload.using=avrispv2
# attiny85at8b.upload.using=Pololu USB AVR Programmer

# The following DO work (pick one)...
attiny85at8b.upload.using=arduino:arduinoisp
# attiny85at8b.upload.protocol=avrispv2
# attiny85at8b.upload.using=pololu

attiny85at8.upload.maximum_size=8192

# Default clock (slowly rising power; long delay to clock; 8 MHz internal)
# Int. RC Osc. 8 MHz; Start-up time PWRDWN/RESET: 6 CK/14 CK + 64 ms; [CKSEL=0010 SUT=10]; default value
# Brown-out detection enabled; [BODLEVEL=111]
# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]

attiny85at8b.bootloader.low_fuses=0xE2
attiny85at8b.bootloader.high_fuses=0xD4
attiny85at8b.bootloader.extended_fuses=0xFF
attiny85at8b.bootloader.path=empty
attiny85at8b.bootloader.file=empty85at8.hex

attiny85at8b.build.mcu=attiny85
attiny85at8b.build.f_cpu=8000000L
attiny85at8b.build.core=tiny
 
###########################################################################

I saved the updated ‘boards.txt’ file.

You must always close the Arduino IDE every time you change ‘boards.txt’ as it is only loaded at start-up.

I then needed to burn the bootloader to the ATTiny85, via the Arduino IDE. This set the correct fuses to implement BOD.

I used the instructions given in the write up above to double check the fuse values (via a command-line function).

I then uploaded my code and check to see if the device reset when the voltage dropped.

It then worked great. When the voltage dropped the device just reset and started again. There were no issues with freezing or any weird errors, so I am much happier with the function of the device.

6 responses to “Enable Brown-out Detect on ATTiny

    1. Hi John, just getting my head around fuses, so no expert … but the CKDIV8 fuse gives you the default 1mhz from the internal 8mhz oscillator (this is the default low fuse of 0x62) see page 30 in the spec sheet 6.2.7 default clock source

      Pete

  1. Turns out you don’t have to go through these hoops (that I could never figure out) to set the brownout detector ON. It’s one of the parameters in the “Tools” drop-down list if the Arduino IDE.

    1. Good point! It’s all better included in the Arduino IDE now: Please just use the “Tools” and set the BOD to the voltage you would like.

  2. Of ALL pages on the internet regarding ATtiny operation/mis-operation THIS page is GOLD. It took me more than a week to resolve a problem that just wasn’t making any sense. It was indeed just like the chip ‘FROZE’ midstream and somewhat randomly. Setting the B.O.D. level to 4.3V, 100% resolved this erratic behavior.

    Thank you so much for the write up.

    My problem days are over 😉

Leave a Reply

Your email address will not be published. Required fields are marked *