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.

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:

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.

Leave a Reply

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