Mosfet + SR transistors power latching circuit - Page 1
Forum section: electronics / beginners

author: VEGETA
author_rank: Super Contributor
timestamp: February 05, 2025, 12:14:35 pm
content: Hello,I wanted to make a power latching circuit which has 2 control signals coming from ESP32; one for powering on and another for powering off. I found SR type circuit suitable and made the suggested circuit in attachment.my requirements:1- robust, no false action, no errors like shorting\invalid status.2- main power is 12v but control from esp32 is 3.3v. if a separate 5v for mosfet gate is absolutely necessary, i can manage it.3- has to have 2 dedicated inputs, not one. esp command is a positive pulse.4- the initial status is to be off. i believe this is achievable via the resistors R7, R3, R8, and R4?5- readily and cheaply available parts from LCSC.the original design i am trying to replace uses a dual coil latching relay which are extremely expensive for my purpose.esp32 will have independent 3.3v power (same used for transistors), so no problem there.do you think it can work?any suggested improvement?is there any better IC or circuit available?Right now, I selected TPS259241DRCR as power switch. "Q" from this circuit is connected to "EN" pin of TPS259261DRCR. EN pin is pulled down too, to ensure stable performance.thanks!

author: ledtester
author_rank: Super Contributor
timestamp: February 05, 2025, 07:42:03 pm
content: Do you need some sort of power on reset circuitry to ensure that the flip-flop starts up in a certain state?

author: PGPG
author_rank: Frequent Contributor
timestamp: February 05, 2025, 08:24:38 pm
content: I don't understand why you need to add to ESP32 externally 1 bit latch while ESP32 is full of such latches.

author: Ian.M
author_rank: Super Contributor
timestamp: February 05, 2025, 09:23:20 pm
content: That's conceptually simple but over-complex with too high a part count when you build it, and a power hog. Why not simply use a single74LVC2G02dual NOR IC wired as the classicSR latchcircuit?(simply link the '2G02's middle pins on each side)That replaces ten parts with a single 'jellybean' IC. Forcing a state at powerup does add back a little complexity, but as ESP32 GPIOs are Hi-Z during and immediately after Reset, provided Vcc rises fast enough, a few tens of pF capacitance from Vcc to the SR flipflop SET input should do the job.Also if you are using a high side MOSFET, you *WILL* need a MOSFET driver or level shifter. For low to medium current loads switched by a high side P-MOSFET that could be a simple N-MOSFET with adequate max. Vds for the supply voltage and a gate threshold voltage << 3.3V, + a pullup. For high current loads a real gate driver IC, or a protected high side power switch IC with ground referenced logic level input and status output(s) would be a better choice.

author: ledtester
author_rank: Super Contributor
timestamp: February 06, 2025, 12:01:11 am
content: If part availability is an issue, perhaps try using the flip-flop inside a 555 -- i.e. its bi-stable mode:Replace the trigger and reset buttons with MOSFETs controlled by the ESP32.I believe a small cap across the reset button will ensure that the 555 powers up in the reset state (output is LOW).You can use a CMOS 555 timer to lower power consumption and the required voltage - although you could also power the 555 from your main power 12V rail since you driving the inputs with MOSFETs.Besides the output pin you have the discharge pin to play with -- basically an open collector/drain output which tracks the output pin.Quote from: PGPG on February 05, 2025, 08:24:38 pmMy assumption is that the ESP32 firmware can't be modified.

author: VEGETA
author_rank: Super Contributor
timestamp: February 06, 2025, 08:39:38 am
content: Quotethe external circuit is esp32 which has a fixed firmware, I only need to make mine go along with its requirements.QuoteI will look into it for sure. this came up in my research about this as it is what the sr latch made of.Quotewhy not just adding pulldown resistors on both set and reset pins? this way they won't be triggered.could also be added to the output itself if needed.Quotei won't focus too much on this now.however as mentioned, TPS259241DRCR part seems very good for the job and won't require any sort of driver.the output of our circuit goes to its enable pin, which is pulled down by default. once the circuit outputs 5v or 3.3v to EN pin, TPS259241 will be activated. it is an efuse which is a plus to do more protection.Quotewill check this. now it is this or the above suggestion of nor gate as sr latch.Quotecheap N-mosfets can be used here, maybe also npns... correct?Quotecan you explain why?also is it necessary to put a pulldown resistor to the output? if using the eFuse mentioned above, adding the pulldown to its EN pin (which is the same output pin of 555) is needed for stable operation.Quotepower consumption is not very important to me, but still if there is a better 555 chip then i will be using it. maybe a schmitt one too?

author: Zero999
author_rank: Super Contributor
timestamp: February 06, 2025, 10:13:22 pm
content: The plain old 555 timer is not specified to work at 3.3V. You might be lucky and get it to work, but I wouldn't bet on it.There are plenty of CMOS variants which will work off 3.3V: 7555, TS555, TLC551 etc. but note the output typically can't source much current, especially with a 3.3V supply.Alternatively use some gates. Refer to the thread linked below. Go with 74HC00 or 74AC00, rather than the old CMOS 4011.https://www.eevblog.com/forum/beginners/cant-get-ltspice-to-simulate-a-flip-flop/msg5800945/#msg5800945

author: VEGETA
author_rank: Super Contributor
timestamp: February 06, 2025, 11:36:42 pm
content: Quote from: Zero999 on February 06, 2025, 10:13:22 pmif using esp32 outputs as mentioned to control mosfet\npn gate\base, then no need for 555 to be 3.3v as it can be 5v. then delivered output to the mentioned eFuse can be 5v easily.the efuse EN pin won't need much current, mere signal.I found this part from TI:https://www.lcsc.com/product-detail/Timers-Counters_Texas-Instruments-NE555DR_C7593.htmllooks like it can handle 200 mA which is way more than needed.i used 3.3v for it since it is used in esp32. now if i need 5v, i can make the 5v psu circuit via buck regulator and use a 3.3v ldo for esp which won't be hot. esp32 won't handle more than 200-300 mA.what do you think now?

author: David Hess
author_rank: Super Contributor
timestamp: February 07, 2025, 12:26:15 am
content: A quad 2-input NAND or NOR gate can be configured as a set-reset latch. I prefer to use a 4013 or 74HC74 dual D positive edge triggered flip-flop which has asynchronous set and reset inputs. The data and clock inputs can be configured to set the output state on power up.

author: VEGETA
author_rank: Super Contributor
timestamp: February 07, 2025, 01:05:28 am
content: Quote from: David Hess on February 07, 2025, 12:26:15 amwell, does it support having an initial state of OFF?how does it compare to above 555 suggestion? and the dual NOR IC suggestion in first posts?

author: David Hess
author_rank: Super Contributor
timestamp: February 07, 2025, 02:00:59 am
content: Quote from: VEGETA on February 07, 2025, 01:05:28 amThe data and clock inputs can be configured to set the initial state, and it has both Q and -Q outputs.QuoteThe dual NOR or NAND only has the set and reset inputs. The 555 can do almost everything, but lacks a complimentary output and draws a lot more power. The 74HC74 and 4013 draw almost no power so can retain state on battery or even capacitor power.I preferred the 74C74 because it used the 7474 pinout, but the high voltage CMOS versions of 74 series TTL are gone now.

author: ledtester
author_rank: Super Contributor
timestamp: February 07, 2025, 02:32:02 am
content: Quote from: David Hess on February 07, 2025, 02:00:59 amYou should also be able to set the initial state via the /PRE and /CLR inputs which don't require a clock signal - just a standard R-C power-on reset circuit, e.g.:https://electronics.stackexchange.com/questions/630155/question-about-capacitor-and-resistor-in-power-on-reset-circuitQuoteHonestly - I only suggested using the 555 if there was an availability issue - like you needed to put this circuit together right now and couldn't wait.

author: David Hess
author_rank: Super Contributor
timestamp: February 07, 2025, 11:28:11 am
content: Quote from: ledtester on February 07, 2025, 02:32:02 amYou can, but I assume the OP wants to leave the set and reset inputs free for his application.

author: VEGETA
author_rank: Super Contributor
timestamp: February 07, 2025, 12:55:10 pm
content: Quotepower consumption is not an issue. I mean does the 555 timer consume like 10-20 mA? not a problem. the system i am trying to make and put this mini circuit in does have an ac-dc power module which outputs 12v, thus not a battery or something limited.Quotewell, i want the 2 states to be controlled by external esp32 commands at any time, but the initial state is off.what i need is a very simple application, just outputs 3.3v/5v or 0v for on and off while being off is default. right now 555 sr-latch circuit seems nice, but want to discuss comparing it with dual nor circuit in terms of delivering the output and the initial state specs. please check.the efuse chosen solves the issue of needing to get mosfet driver while doubling as a fuse function.

author: ledtester
author_rank: Super Contributor
timestamp: February 07, 2025, 01:14:31 pm
content: Quote from: David Hess on February 07, 2025, 11:28:11 amWould this arrangement work? The ESP32 signals have to be inverted anyway as they are positive going pulses.(see attachment)

author: David Hess
author_rank: Super Contributor
timestamp: February 07, 2025, 05:38:24 pm
content: Quote from: ledtester on February 07, 2025, 01:14:31 pmThat will work, but a diode should be placed across the resistor to discharge the capacitor quickly in the event of power loss so that a "power glitch" will not leave the latch in an undefined state.Using either a NOR or NAND based latch should remove the need for the inverting MOSFET. Or replace the MOSFET with a diode.I wonder if there is a latch or flip-flip with active high inputs. Looks like everything TTL was active low, like it should be. Ah, the 4000 series CMOS flip-flops are active high, so use a 4013 instead of a 74HC74.

author: VEGETA
author_rank: Super Contributor
timestamp: February 07, 2025, 07:56:37 pm
content: Quote from: ledtester on February 07, 2025, 01:14:31 pmare you talking about 555 circuit or gate-based circuit? if 555, then the switches are replaced with mosfets as you suggest. you mean the reset mosfet to have a cap across it to ground? would 10uF work or something like 100nF is enough?your thought of this is that the pin to be kept at 0v until capacitor fully charges? thus effectively making it output 0v = off.i don't know how the pin's voltage will be 0v during cap charging as it is not connected to ground.also, you deliver the output to /clr pin... if i assume 555 timer one, then i guess it should be delivered to pin 4 (/reset) right?in 555 timer circuit above, pin2 is active high while pin 4 is active low but both are used as active low. is that correct?Quotedo you have a complete suggested circuit with off state being by default?

author: ledtester
author_rank: Super Contributor
timestamp: February 07, 2025, 08:30:38 pm
content: Quote from: VEGETA on February 07, 2025, 07:56:37 pmBoth solutions require the cap on the input which will define the start-up state of the flip-flop.The time the pin will spend LOW is roughly on the product R*C where R is the pull-up resistor.R = 10K and C = 10 nano gives a time of 100 microsecondsR = 10K and C = 100 nano gives a time of 1 millisecondR = 10K and C = 10 micro gives a time of 100 milliseconds = 1/10 secondI think around 1 millisecond should be fine.QuoteIf you want the 555 to start up with the output pin LOW, then you want /RESET to be LOW for a little while when power is applied.QuoteI wouldn't call pin 2 an active high input. I think it is best to just analyze what happens in the 555 when the TRIG input is brought LOW:https://www.circuitbasics.com/555-timer-basics-bistable-mode/

author: David Hess
author_rank: Super Contributor
timestamp: February 07, 2025, 10:56:23 pm
content: Quote from: VEGETA on February 07, 2025, 07:56:37 pmAs discussed, I would do it with a 7474 flip-flop, and use either the clock and D inputs or a set/reset input to force the output into a known state.

author: VEGETA
author_rank: Super Contributor
timestamp: February 08, 2025, 04:56:00 am
content: Quote from: David Hess on February 07, 2025, 10:56:23 pmi found this part:https://www.lcsc.com/product-detail/Flip-Flops_Texas-Instruments-SN74HC74DR_C6762.htmllooks the one you mentioned.however, where would i hook my power on and power off signals? these will be sent as pulses when needed, but still would need the device to be in off state when it starts by default without any signal or intervention.the truth table requires independent clock, then single D signal to control the output.Quotewell, 100nF cap seems ok.Quoteyes, the 100nF we spoke of is to be connected there.Quoteyes you are correct.i read the datasheet and they mentioned reset to be active low but not trigger. in our bistable circuit it is definitely active low since when it is high it is not active and when button pressed it gets activated.

author: David Hess
author_rank: Super Contributor
timestamp: February 08, 2025, 11:20:25 am
content: Quote from: VEGETA on February 08, 2025, 04:56:00 amThe separate power on and off signals go to the -preset and -clear inputs, which are active low.To force the output into a known state, the D input is connected to either power or ground, depending on what the output should be, and an RC delay connects to the clock input with the capacitor going to ground. During power up, the clock input slowly rises and triggers copying the D input to the Q output.If the power on and off signals need to be active high instead of active low, then use a 4013 instead which has active high preset and clear inputs.

author: VEGETA
author_rank: Super Contributor
timestamp: February 09, 2025, 09:59:50 am
content: Quote from: David Hess on February 08, 2025, 11:20:25 amI've got this part after searching:https://www.lcsc.com/product-detail/Flip-Flops_Texas-Instruments-CD4013BM96_C13527.htmlit has 2 d flip flops despite we need only one.i attached my attempt to design the circuit based on your advice. Please check.the part which i feel tricky is how the clock is now getting constant 3.3v, and the circuit will keep working as intended by giving power on and power off commands. is it guaranteed to work? like powering it on and off repeatedly without an issue?compared to 555 timer circuit, this has the benefit of not having to do inverting from active high to active low via mosfets, plus the power consumption (which is not important to me). still, it has 3 d flip flops which one is not used. Ti has other parts which has a single one but set and reset are active low.what do you think now?

author: ledtester
author_rank: Super Contributor
timestamp: February 09, 2025, 12:26:53 pm
content: Quote from: VEGETA on February 09, 2025, 09:59:50 amWhen Set and Reset are LOW the flip-flop will only change state when the clock goes from LOW to HIGH.This is shown in Table 1 of the datasheet (table attached below):https://www.ti.com/lit/ds/symlink/cd4013b.pdfIf the clock stays LOW or stays HIGH the only way the output can change is via the Set and Reset inputs.QuoteMake sure you tie the unused input pins of the second flip-flip to either GND or Vcc:https://electronics.stackexchange.com/questions/730077/best-practice-for-unused-pins

author: xvr
author_rank: Frequent Contributor
timestamp: February 09, 2025, 02:21:02 pm
content: 555 has additional benefit - it has quite large output current and can drive N-Channel MOSFET gate directly, no additional MOSFET driver required.

author: VEGETA
author_rank: Super Contributor
timestamp: February 09, 2025, 05:53:48 pm
content: Quoteso you confirm my circuit to be correct? after revising datasheet and your post, i think it is. however, more confirmation is better.Quoteah yes for sure, i do this all the time when similar stuff exist in my circuits.Quoteanother benefit is the slightly cheaper price but not by much. cd4013b is also very cheap from lcsc. cd4013b is about 0.25$ while 555 is 0.1$ or so.the high output current might not be useful for me since i will be delivering the output to the EN pin ofTPS259241DRCR.probably micro amps needed, just a voltage signal.maybe the benefit of cd4013b is the direct inputs from esp32 without the need of inversion via mosfets or so + the ability to work off 3.3v directly. the 555 on the other hand is smaller in size (and cheaper a bit) but it needs 5v.if you guys were in my place which solution will you select?

author: VEGETA
author_rank: Super Contributor
timestamp: August 03, 2025, 05:24:56 pm
content: HelloI finished the design, please check the attached images.the "latch" is for 4013 circuit for on off, while the other one is for an ideal diode mosfet circuit (+ reverse blocking + activation) which takes the activation signal from latch.any tips?