# Need guidance for latching output of op amp (N-channel mosfet)

There are a lot of schematics online for high side switch latching using a p-channel mosfet or PNP transistor, (I) couldn't find any for low-side so I tried to design my own:

simulate this circuit – Schematic created using CircuitLab

I want to when output of op amp goes high mosfet stay "on" even when the op amp output goes low until SW3 is pressed. the circuit kinda/sorta works in a crude simulator but there are two problems:

First; When op amp output goes low from high, mosfet gate voltage reduces to ~2.5V even if I disconnect Q1 emitter from Q2 collector and connect 12V supply to Q2 collector. obviously because the base is at 2.5V...

Second; I want to use a normally open push button instead of normally closed.

Note: I know adding a diode from op amp output to the non-inverting input of op amp can keep the output of op amp latched but that will disturb/change the voltage at non-inverting input which is not desirable.

How can I solve the described problems? is there a better approach to do this?

• Do you have a reason to not just use a digital chip such as a D flip-flop (with reset) or an S-R latch? And why are you using an op-amp in this application instead of a comparator? Dec 19, 2020 at 17:28
• @ThePhoton To reduce the part count and PCB size, op amp have lower input offset voltage compared to common cheap comparators and speed really doesn't matter that much. Dec 19, 2020 at 17:32
• If your input is really a switch connected to 2 and 0 V, then offset voltage below 1 mV is irrelevant. And using a comparator with open-collector output will eliminate the need for the diode, reducing part count. Dec 19, 2020 at 17:42

## 3 Answers

simulate this circuit – Schematic created using CircuitLab

Presumably your 100nF cap is intended to force it to an 'ON' condition when power is applied. You can add that back, but it would be good to add a 1N4148 diode to prevent breaking down Q1 E-B.

Since there is only 2.5V swing at the drain of M1, R6/R8 are used to establish a 2.0V voltage at the base of Q2. When M1 is "off" thus Q2 is also off.

When the emitter is pulled down to close to 0V, then Q2 conducts, turning Q1 on and thus M1, positive feedback.

Pressing SW1 turns Q1 off so that the feedback loop is broken, and the output state depends only on the comparator state. If you want SW1 to turn M1 off regardless of the comparator you would do it a bit differently.

Edit: To have the switch override the comparator you could add a series resistor such as 10K to the gate of M1 and short the gate to ground through the switch.

A couple of folks have suggested using logic functions. To make the decision whether you can use a standard logic function such as a flip-flop or a cross-coupled pair of gates there are a few considerations:

• Will the FF safely operate from +12? If not, a regulator and associated capacitors are necessary, and some resistors to keep input voltages within spec. If so, then probably a small single-gate package is not possible for a flip-flop.

• What is the power-on state of the FF? If random then some circuitry might have to be added. Maybe even an additional gate package and another chip again if you want to use logic functions and bulletproof supervisory chips.

• When both S & R are asserted , what is the output state? You might be able to get it to do what you want by inverting the function and adding an inverter to the output, but that's additional parts.

Either way it's certainly possible, just with different trade-offs.

• The voltage after R1 is 2.5V because of the zener (LM336), that's triggering the Q1 base no matter what. Dec 19, 2020 at 17:47
• @ElectronSurf Ah, okay. Won't work with that in there. Dec 19, 2020 at 17:50
• Fixed.......... Dec 19, 2020 at 18:03
• Thanks, R6 and R8 values are so high that breaks the 2.5V reference to ~1.7V. I tried reducing them but then circuit had the same problem as before... Dec 19, 2020 at 18:06
• Note that R1 2.2K is still in there. Dec 19, 2020 at 18:08

You can save yourself a lot of headache by using digital chips for digital functions. You can use an SR latch here, or a D flip-flop with a RESET input.

Also using a comparator with open-collector output in place of the op-amp allows you to eliminate the diode from your design. It also eliminates the need for a negative power supply (assuming the actual input voltage range is 0 - 2 V as shown in your schematic)

With an SR-latch it looks like this:

simulate this circuit – Schematic created using CircuitLab

Practically you might find it easier to source an $$\\bar{S}\bar{R}\$$ latch (i.e. with inverted inputs) --- then you'll have to swap around some connections to make things work.

• Thanks, but can't it be done with discrete components? Dec 19, 2020 at 17:52
• @ElectronSurf, the point of my answer is that it's generally easier to not do that. The digital logic designer has done the work of figuring out the time constants, making sure the input thresholds and output levels are correct, checking the set up and hold times, etc., so you don't have to. And basic digital chips typically cost no more, consume less power, and take less board space than a solution requiring a couple transistors and a couple of passives. Dec 19, 2020 at 18:02
• I agree with the @ThePhoton. But, if you insist on doing it with discrete transistors, just look up the design of the comparator and SR latch, as they are both constructed using transistors and diodes and such. Dec 19, 2020 at 19:23

The really old school way of latching, using relays and predating modern electronics, was called a "seal-in circuit". look that up. you can use the same principles with transistors. Very little benefit to this however, since you can often get standard logic gate latch chips, in logic families that work at higher voltages already available in your system.