ESP32-S2: need to adjust Brown Out Level at runtime

MicroController
Posts: 1736
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32-S2: need to adjust Brown Out Level at runtime

Postby MicroController » Sat Feb 10, 2024 10:49 am

FiwiDev wrote:
Fri Feb 09, 2024 11:52 pm
MicroController wrote:
Fri Feb 09, 2024 9:05 pm
Another potential option: "5V" ultracap (2x 2.5V in series) hooked up directly to 3V3
That doesn't solve the problem of the ESP32 brown-out module being effectively useless.
I can't find data on any hysteresis of the BOD either. You may look into implementing it it software: Start up and set the BOD to, say, 3.0V; when the BOD triggers (interrupt), do your shutdown/cleanup routine, then set BOD to 3.3V to reset the chip and hold it there until power comes back.
(Also worth noting that boost converter ICs are significantly cheaper than ultracaps: TPS61023 with true disconnect functionality is ~$0.23 + associated parts, and the 3.0v 20F ELDC low-ESR ultracap I am utilizing comes in at ~$1/ea.)
20F?! What are you trying to do? Aren't we talking about buying a few tens/hundred ms to cleanly shut down?
Edit: "after running shutdown tasks comprising several seconds.." - Nope, we're not :D
Another thing to keep in mind is that "directly to 3V3" will put a considerable load on the 3.3v rail when the capacitors are completely empty. (That of course is assuming that the ultracaps have a low ESR--which they have to be in order to be able to power the ESP32 without causing random crashing due to chip brownout. The EDLC ultracap I have is rated 50mOhm [0.05 ohms], and Ohm's Law states 3.3v across 50mOhm will pull a cool 66 amps!)
Inrush current - nothing that can't be fixed with a diode/FET and a single resistor :)
Also, the ESPs tend to draw maximum power (500mA or so) only in short spikes during RF activity, so you may not actually need 20F of low ESR to get down to the impedance required.

FiwiDev
Posts: 22
Joined: Wed Jan 22, 2020 12:32 am

Re: ESP32-S2: need to adjust Brown Out Level at runtime

Postby FiwiDev » Sat Feb 10, 2024 2:24 pm

MicroController wrote: Start up and set the BOD to, say, 3.0V; when the BOD triggers (interrupt), do your shutdown/cleanup routine, then set BOD to 3.3V to reset the chip and hold it there until power comes back.
If only the brown-out peripheral worked that way, I'd be in tall cotton. It's how I hoped/expected it to work.

But some very simple tests showed otherwise (as @boarchuz suggested): if you set the BOD to ~3.19v (max setting), and power the chip on 2.8v, it will enter an infinite reboot loop (~1/2 sec intervals).
Which is why I commented that the brown-out peripheral is effectively useless. Because in addition to the failure of BOD to hold the chip in reset, it also fails to reset the ESP32 if VDD is taken below 1.8v and then slowly brought back up (as I mentioned in a previous post).

After some thought, my best bet (aside from adding an external 2.5v voltage supervisor to the ESP32 as @boarchuz suggested) may be to pull the ULP coprocessor into play (watch for the BOD output to fall -> chip reset). My first thought was to put the ESP32-S2 into deep sleep, and use the BOD interrupt to wake it--but said interrupt will fire when the voltage FALLS (and the internal signal goes HIGH). I need it to fire when the voltage RISES above the BOD threshold. I'll dig into the technical reference manual further and see if there happens to be an interrupt signal polarity invert bit...but at the current rate, I'll be a bit surprised.

MicroController wrote: Inrush current - nothing that can't be fixed with a diode/FET and a single resistor :)
Diode = 0.6v drop at any significant current, and suddenly 3.3v - 0.6v = 2.7v...barely above the chip-functional-failure level of ~2.4v--and that's pre-ESR losses and otherwise. (Yes, I know, "schottky diode", but those have a significant reverse leakage--easily up to 15mA at high operating temperatures--and often will reach similar voltage drops at any significant current flow.) FET...as I mentioned earlier, even a logic level FET has difficulty with on resistance at low gate drive voltages--which will result in a similar problem with voltage drop. There just isn't the voltage headroom to do much of anything.

MicroController wrote: so you may not actually need 20F of low ESR to get down to the impedance required.
So you're right that I don't need the 20 farad rating...it's just that any smaller EDLC supercaps have too high of an ESR in order to be functionally usable.

Let me explain:
In my project, said EDLC supercap ALSO has to power a cellular modem...which "conveniently" runs at 3.8v (and can pull bursts of 2A). This is also why the shutdown tasks can comprise several seconds (sending power loss message & safely shutting down the modem)--and largely why the EDLC must have a low ESR. A 4-amp boost converter (MT3608) cannot "start" the whole board (inrush and losses result in the boost chip browning out at its own 1.98v UVLO threshold), though it can "sustain" it if power is lost. 4 amps @ 0.050 ohm ESR = 0.2v drop, so with ESR losses alone--not including inductor losses or internal boost FET losses--I'm already at 3.0v - 0.2v = 2.8v input to the boost converter. And the lower the input voltage, the higher the amperage must go in order to sustain the same output wattage--which very quickly becomes a death spiral.

I keep stressing "low ESR" supercaps--because you can EASILY find multifarad supercaps that were intended for powering an RTC. Said supercaps often have an ESR exceeding one ohm...which renders them totally useless for backup power systems of a main processor (much less the entire board).

FiwiDev
Posts: 22
Joined: Wed Jan 22, 2020 12:32 am

Re: ESP32-S2: need to adjust Brown Out Level at runtime

Postby FiwiDev » Sat Feb 10, 2024 8:44 pm

@
MicroController wrote: Another potential option: "5V" ultracap (2x 2.5V in series) hooked up directly to 3V3
It is worth thinking about two 2.7v/3.0v ultracaps in series...that is, on the 5v rail, not the 3.3v rail. As 2x 5F capacitors are about the same cost as 1x 20F capacitor, that would be a win on the BOM level (i.e. no boost converter needed). As the ESP32 and cell modem are both powered from the 5v rail (via buck converters), the power draw on the 5v rail would be significantly less (i.e. buck converter instead of linear regulator). The available voltage headroom would also be higher (5v to 3.3v/3.8v)...and both of those together (lower current + more voltage headroom) would result in being able to utilize an EDLC with significantly higher ESR.

(5 farad 3.0v cap has an ESR of ~0.130R, whereas the 20 farad 3.0v cap has an ESR of ~0.050R.)
Funny that a dedicated "5.5v 5F" ultracapacitor "module" costs 2-8x that of two discrete 2.7v 5F ultracaps though.

Gotta really watch the ESR on ultracaps...some coin-style 5.5v 4F ones have an ESR in excess of 10 OHMS. Can't pull much power from those!


Still doesn't fix the broken brown-out detect peripheral on the ESP32 silicon though!

MicroController
Posts: 1736
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32-S2: need to adjust Brown Out Level at runtime

Postby MicroController » Sun Feb 11, 2024 12:08 am

(5 farad 3.0v cap has an ESR of ~0.130R, whereas the 20 farad 3.0v cap has an ESR of ~0.050R.)
Funny that a dedicated "5.5v 5F" ultracapacitor "module" costs 2-8x that of two discrete 2.7v 5F ultracaps though.
Don't forget that 2x 5F, 0.13 Ohms in series is 2.5F, 0.26 Ohms. And you'd want to implement some kind of balancing.

FiwiDev
Posts: 22
Joined: Wed Jan 22, 2020 12:32 am

Re: ESP32-S2: need to adjust Brown Out Level at runtime

Postby FiwiDev » Sun Feb 11, 2024 2:32 am

MicroController wrote:
Sun Feb 11, 2024 12:08 am
(5 farad 3.0v cap has an ESR of ~0.130R, whereas the 20 farad 3.0v cap has an ESR of ~0.050R.)
Funny that a dedicated "5.5v 5F" ultracapacitor "module" costs 2-8x that of two discrete 2.7v 5F ultracaps though.
Don't forget that 2x 5F, 0.13 Ohms in series is 2.5F, 0.26 Ohms. And you'd want to implement some kind of balancing.
I was aware of the increased ESR, but completely forgot about the capacitance halving...which would explain the higher cost of a 5.5v 5F module (= 2x 2.7v 10F EDLCs). Similar mathematically in storage to a single 3.0v 20F EDLC, but significantly higher in cost.

There goes any shred of cost savings with 2x 2.7v EDLCs. Oh well, it was a grand idea while it lasted...

FiwiDev
Posts: 22
Joined: Wed Jan 22, 2020 12:32 am

Re: ESP32-S2: need to adjust Brown Out Level at runtime

Postby FiwiDev » Mon Feb 12, 2024 12:23 am

Just for those who might want to tinker with the brown-out detector on their own, here is my sloppy test code for the ESP32-S2. LIKELY WILL NEED CHANGED IF YOU ARE USING A DIFFERENT ESP32 VARIANT!

Code: Select all

#include <Arduino.h>
#include "hal/brownout_hal.h"		// for adjusting brownout level
#include "soc/rtc_cntl_struct.h"    // for reading brownout status
#include <rom/rtc.h>

#define pin_LED_1           34
#define pin_LED_2           45

void setup() {
  // put your setup code here, to run once:
  pinMode(pin_LED_1, OUTPUT);
  pinMode(pin_LED_2, OUTPUT);
  
  //ESP32-S2 only has 1 core...
  //Uncomment the following to set LED state based on whether the reset was a brown-out reset
  //Obviously, you will need to comment out the LED state code in LOOP() for this to be persistent
/*  
  if (rtc_get_reset_reason(0) == RTCWDT_BROWN_OUT_RESET) {
    digitalWrite(pin_LED_1, 1);
    digitalWrite(pin_LED_2, 0);
  } else {
    digitalWrite(pin_LED_1, 0);
    digitalWrite(pin_LED_2, 1);
  }*/

  
  Serial.begin(115200);

  //Use the following to change the brown-out detect config.
  // ".threshold" values can be found in the ESP32-S2 Technical Reference Manual
  // section 9.3.4.4.  (Page 273 in TRM v1.1)
  brownout_hal_config_t cfg = {
    .threshold = 2,			// 3.19v
    .enabled = true,
    .reset_enabled = false,		// if you want to use ".det" as a software signal, you must disable all brown-out shutdowns
    .flash_power_down = false,
    .rf_power_down = false,
  };
  brownout_hal_config(&cfg);
}

void loop() {
  // Sets LED state to the output of the brown-out detector
  if (RTCCNTL.brown_out.det) {
    digitalWrite(pin_LED_1, 1);
    digitalWrite(pin_LED_2, 0);
  } else {
    digitalWrite(pin_LED_1, 0);
    digitalWrite(pin_LED_2, 1);
  }

  Serial.println("Alive");
  delay(50);
}
The one thing the brown-out detector is good for, is determining the VDD of the ESP32. That's really about it, unfortunately.

Who is online

Users browsing this forum: Bing [Bot] and 165 guests