Brownout detection

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Brownout detection

#1 Post by rayE » 15 Nov 2019, 11:11

Hi All,
Please correct me if im wrong on this, but an 8266 module has NO non volatile RAM? rather you can write to the RTC memory or general purpose flash memory?

What i want to do is log the RTC time when there is a power failure and log the time when the power was restored. To accomplish this im thinking on using the following method.

1. I have a BOD circuit (brown out detection) that feeds a D/I pin on the ESP8266 module (maybe an interrupt).
2. I have a small super cap that is charged from 5V and feeds the I/P to a 3V3 regulator that powers the ESP module.
3. If the 5V I/P to the regulator fails (brownout) then the super cap powers the ESP module for a couple of seconds.
4. I turn off the WiFi on BOD (to conserve power) OR put the module into a light sleep?, and write a time stamp to flash memory OR RTC memory.
5. Put the module into deep sleep.
6. Once the power i back i write the BOD time stamp AND the power normal time stamp to IOT database, this will then log BOD.

Any thoughts on this is appreciated.

TIA
Ray

TD-er
Core team member
Posts: 1922
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Brownout detection

#2 Post by TD-er » 15 Nov 2019, 11:33

Instead of such an elaborate setup, wouldn't it be easier to have support for I2C FRAM, which could act as RTC, but then keeping the values when power is lost.

You can also run a script at boot, where you can detect the last boot cause (not sure if that's already present in the code as a system variable) and if it is a cold boot, then you know the device was without power (or the reset was intentional pressed)

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#3 Post by rayE » 15 Nov 2019, 11:35

No its extra expense, reduced cost of the end product is essential.

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#4 Post by rayE » 15 Nov 2019, 11:36

Does the last boot cause have a timestamp?

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#5 Post by rayE » 15 Nov 2019, 11:38

Actually, and more important, how is the last boot cause stored?

TD-er
Core team member
Posts: 1922
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Brownout detection

#6 Post by TD-er » 15 Nov 2019, 11:44

rayE wrote:
15 Nov 2019, 11:38
Actually, and more important, how is the last boot cause stored?
If not initialized, then it was a cold boot.
Otherwise it will store the last boot cause in RTC. (a single byte)

We can read it, but I can add a system variable for it to be able to use it in rules, which can be useful for a lot of other use cases too.
The timestamp is not kept anywhere if the power is lost.
And writing to flash in case of an "emergency" may be a nice feature, but I'm afraid we may corrupt things if the power left for saving is just not enough.
There is an EPROM section in the flash, which we do not yet use and I was thinking of using it for special purposes like OTA definitions etc.
It could be used also for these kind of things, but not sure how to structure such an emergency shutdown procedure.
Should it be a plugin (it has to use a GPIO pin)?

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#7 Post by rayE » 15 Nov 2019, 11:48

There is an EPROM section in the flash, which we do not yet use and I was thinking of using it for special purposes like OTA definitions etc.
Now THAT would be a real sexy/useful feature to have, i take it this is NON volatile? how many bytes are available? AND as you say a method of keeping the module alive is required, although this is a relatively simple implementation in HW using a super cap, a diode and a resistor, should keep things moving for a few seconds, enough time to write to EPROM?
Last edited by rayE on 15 Nov 2019, 11:59, edited 1 time in total.

TD-er
Core team member
Posts: 1922
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Brownout detection

#8 Post by TD-er » 15 Nov 2019, 11:55

It is non-volatile, since it is part of the flash layout.
Not sure of the size, but a few kByte I guess.
The erase size for flash is about 4k, so I guess it is something like that.
Also the EPROM part does not have a specific structure, so we can do what we like with it. (as far as I know)

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#9 Post by rayE » 15 Nov 2019, 12:01

This really does sound pretty cool. I have seen lots of posts regarding "states" after a reboot...................problem solved?

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#10 Post by rayE » 15 Nov 2019, 12:11

Simple HW implementation...............The AT tiny dotted stuff is the 3V3 regualator if using a ESP module without a regulator.

attachment=0]download.jpg[/attachment]

Loose the LED, wasted power. Also from the data sheet the flash memory has a write limitation of 10K, after this that part of flash can become "worn"!
Attachments
download.jpg
download.jpg (7.42 KiB) Viewed 951 times

TD-er
Core team member
Posts: 1922
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Brownout detection

#11 Post by TD-er » 15 Nov 2019, 12:55

rayE wrote:
15 Nov 2019, 12:01
This really does sound pretty cool. I have seen lots of posts regarding "states" after a reboot...................problem solved?
Not really, the values will only be saved when the emergency exit procedure can be executed.
That won't be when the unit crashes.
So that's why I still would like to implement the FRAM idea I have in mind, since that can be written in the order of 10^14 times (or more) and quite fast also.
Those FRAM chips can be had in sizes of a few kB to 256 kB (or even more?), although they are rather expensive per kB storage.
But they do add a lot of flexibility.

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#12 Post by rayE » 15 Nov 2019, 13:26

Understood, iv used FRAM many years back on a PIC application. Cheaper today BUT overkill for my application, If it's just a few bytes you need to store once in a while on a certain trigger.

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#13 Post by rayE » 15 Nov 2019, 13:34

I should have added, the simple circuit i attached will also have a BOD before the diode and attached to a D/I pin on the esp through a potential divider. This will alert the ESP that the main supply has gone down and to enter emergency save to flash mode.

In my location we have a brown out once a day that lasts for maybe 2 hours max, so if the ESP can enter deep sleep after the write to flash, and stay alive for a few hours on the super cap in sleep mode (~200uA) then all is well. Ill give it a try and report back.

10,000 writes to flash/365 (once a day write) = 27.3 years of usage :-) more than enough without extra HW

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#14 Post by rayE » 15 Nov 2019, 13:52

Is writing to very top of Flash safe? so if i have 4M, 1M spiffs where would i write to safely? Or i just write to a dummy var?

TD-er
Core team member
Posts: 1922
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Brownout detection

#15 Post by TD-er » 15 Nov 2019, 14:12

It is not yet implemented.
But the area for EPROM section is already present on the flash.
See here for the flash layout.

rayE
Normal user
Posts: 136
Joined: 12 Oct 2017, 12:53
Location: Philippines

Re: Brownout detection

#16 Post by rayE » 16 Nov 2019, 04:46

Thanks TD-r. Ill report back on this with my chosen solution, it could be handy for others.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests