ESP32 programming a watchdog to disconnect battery in case of program hangs

Hi everybody,

I'm working on a battery-powered project with a 12V Lead-acid-battery and a DC-DC-step-down-regulator.

It is one of these cheap LM2596-step-down-modules.
The LM2560 itself draws 22 mA if the input is connected to 12V.

The regular case for shutting off is measuring the battery-voltage with a voltage-divider 1M/270 kOhm and if the battery voltage goes below 12.2V = ADC-input goes below 2,59V to switch off.

I have build some kind of a "self-hold-circuit" with a TTL-Gate-MOS-FET IRF3708.
There is a voltage-divider 1MOhm / 270 kOhm between +12V and GND. The middlepoint which has 2.55 V is connected to a "switch-on-button". If pressed the 2.55V get connected to the MOS-FET-Gate switching on the MOS-FET.
The MOS-FET powers up the DC-DC-step-down-regulator which is supplying the ESP32 with 5V on the Vin-Pin. I'm using the Vin-pin because I need 5V for a 8x8 WS2812-LED-matrix.

If the ESP32 is powered up an IO-pin is switched HIGH to continue switching on the MOS-FET.

I want to increase security against too-deep-discharging of the battery through some kind of a watch-dog that must be retriggered regularly to keep the MOS-FET-Gate-IO-Pin "HIGH"

I was thinking about adding a capacitor between ground and Gate in parallel to a discharging resistor.
The code would switch on the IO-pin for a short moment to load the capacitor through a 1kOhm-resistor and then the IO-pin switches off again. Capacitor starts discharging and if IO-pin does not switch to HIGH again the MOS-FET is switched off. Switching off everything except the 1M/270k-voltage-divider.

This approach has still the problem if the program hangs at MOSFET-Gate-IO-pin switched HIGH everything stays switched on discharging the battery too much.

So I would like to have something that switches the MOS-FET-Gate-IO-pin to low even in all cases if the program hangs at any line of code.

Does somebody know of such a possability?

The other approach is to not use the microcontroller for this but to use an external circuit that works on his own. If battery-voltage drops below 12.2V switch off. Does somebody know a simple circuit (= less than 10 parts) that can do this?

The approach with the MOS-FET reduces the current to 10 µA in the switched-off-state, because only the 1M/270k-voltage-divider stays connected to the battery.
everything else is switched off.

See schematic.

best regards Stefan

Hi Stefan,
I confess to not reading all your post but your schematic has a huge, glaring error: Just after the ESP32 IO pin goes low to turn off the MOSFET, what voltage do you think will be on the IO pin and why?

PS, love the 'lazy' MOSFET symbol, not much different to the one I use when I hand draw them because I am too lazy to draw the proper ones.

Hi Perry,
thank you fo answering.

As the capacitor is loaded to 3.3V if the IO-pin is switched to LOW = 0V
The capacitor will discharge through the 1k-resistor which is limiting the current to 3.3V / 1000 Ohm = 3.3 mA which should not damage the IO-pin.

Can you explain in detail where you see a problem in this?
best regards Stefan

You know my style by now, I don't always give simple answers, rather I give clues.

Read the question again, I am not asking about the capacitor or the resistor, I am asking about the pin: What voltage will be on the pin just after the MOSFET turns off?

1 Like

hm,

thoughts:
Do you think that the output of the DC-DC-converter jumps up to 12V feeding in 12V into Vin?

Do you think if the gate-voltage lowers the MOS-FET's Ron-resistance increases and this will produce too much heat overheating the MOS-FET?

I build up the circuit except for the connection to the ESP32.
I was simulating switching the IO-pin to 0V through a wire.
And I watched the voltage on my DSO. It did just jump down to 0V
nothing spectacular.

I still have no clue what the problem might be except maybe the overheating through too high R-on-resistance
best regards Stefan

Where did you connect the wire?

Over heating of anything is not the problem.

wire from left end of the 1k-resistor to ground
just like the IO-pin would be connected to the left end of the 1K-resistor

What are you calling ground?

What is the IO pin connected to inside the processor?

the line with the letters "GND"

I thought GND

Perry I'm really at the end of my knowledge at this point!
Is this some kind of bringing me into a similar situation like I use to bring other users by asking for more details???

I even measured the voltage difference between source and Drain 0,001V difference

Yes, of course, and you are getting closer to the answer.

Follow the circuit from inside the processor to ground (where you said) and tell me what the pin is connected to just after the MOSFET turns off.

Perry I'm really at the end of my knowledge at this point!

You're about to learn something new!

Follow the circuit from inside the processor to ground (where you said) and tell me

If you have read at least some of my postings you should have recognized that MY STYLE is to ASK for more details and then providing

VERY DETAILED ANSWERS

Sorry, I don't understand your last reply.

From what I have seen of you on here you are capable of working this out yourself and I think you'll kick yourself when you realise what I'm getting at.

no I don't!

If I have asked for more details maybe once or twice.
me personal I'm giving the direct answer!

And I would provide the inner schematic of processor as a picture.

You think that the IO pin is connected to ground I believe, yes?

How is it connected to ground? You don't need the inner schematic of the processor, you just need to know that the processor has a ground pin and realise that the only way the IO pin can be connected to ground is through that ground pin. How it get there through the inner workings of the processor are unimportant.

What is the ground pin of the processor connected to? Please don't say 'ground'. Look at your schematic, what is is connected to?

The groundpin of the processor is not included in the schematic.
So the answer with looking at my schematic is the GND-pin of the ESP32 is connected to "nowhere"

Well, OK, you got me there. I think it's connected to the output of the LM2596. You have it labelled as '5V' with the positive to Vin. You have not explicitly shown that the other line below the 5V is to the ground of the processor but I took that to be the case.

So, is my assumption correct? Or have I just wasted* half an hour of your time and my time because I didn't clarify that point?

Where do you think the processor's ground is connected?

*I don't really think it was wasted because something will be learnt from this whatever the outcome.

do me a favor and start explaining all variants what happends if the ESP32-GND is connected to a, b, or c

OK

A. For what I assumed, which is that the ESP (or any processor, it's not important) was connected with +5V and 0V from the LM2956 output as on the extreme right of your schematic, then as soon as the MOSFET turns off there is no 0V (ground) to the LM2956 so there is no 0V to the ESP, so the output on the IO pin cannot be 0V because there is no circuit from the pin to 0V. Most likely the output will be the 12V from the LM2956 as that is all that goes into it, so must be what comes out the other end, to the ESP and thus to the IO pin. If the IO pin has 12V on it, or indeed any voltage significantly above 0V then it turns the MOSFET right back on again.

B. If the ESP 0V is connected to where you labelled it GND then with the MOSFET off then I would expect the output of the LM2956 to be 12V or close so you now have a lot more than the desired 5V on the ESP, so expect smoke. In any case, even without smoke, you are supplying power to ESP, so it is not turned off, which is what I think you were hoping for.

C. What is C?

to quote you
"re-read the question and think about it and you will find the answer"

1 Like