Soft Latching Switch

I'm attempting to make a soft latching circuit for my project. The goal is to have a 2 second press to turn power on and off. I've found many circuits online that use a quick press on and a long press to turn off but my main issue is that I want a long press to turn power on to prevent accidental presses draining the battery when in transport. I should also mention that I'm using JLCPCB to assemble the board so I am limited to components in their SMT assembly library.

Below is my current schematic. I'm not sure that I've got this laid out properly or not. I'm hoping someone could double check my work and answer a few questions/concerns. The basic layout is that the board is powered by a single cell lipo. The IC's in the schematic are connected directly to the lipo. The idea is that the first RC circuit will produce a delay of 2.2 seconds when the switch is pressed and then turn on the flip flop which will activate the boost converter which will produce 5V to run the AVR chip and the rest of the project. I'm only showing the switch and boost converter in the schematic below however.

(click on photo to see full size version) |500x225

I'm using the SN74LVC1G74DCUR as the flip flop, although it doesn't have an inbuilt schmitt trigger so I'm also using the NC7S14M5X I'm hoping that shouldn't be an issue?

The first RC timer (R5 & C3) should produce a delay of 2.2 seconds by my calculations, which would produce the desired long press to turn it on and off.

I want to avoid the board being activated when the user plugs into power to charge the battery. My understanding is that the CLR pin of the flip fop needs to be brought low or 0 so that the user will have to press the button to turn it on. I'm confused about how long the second RC timer on the CLR pin needs to be (R6 & C13), right now its set at 100 milliseconds with 100k*100nF. What should be the delay amount for this RC timer so that it produces the desired result?

My other concern is whether or not I've made the connections to the boost converter IC correctly. The FP6291LR-G1 has an enable pin and my understanding is I can use the Q output of the flip flop to drive this high or low turning the boost converter IC on or off. Thus the Vcc of the IC is connected to the 3.3V line directly. Is this set up correct?

Any help or feedback is very much appreciated, thank you for your time.

Your graphic is unreadable. You need to post a usable version before we can discuss it. :roll_eyes:

Why not do all this within the processor ( eg 328) , run it off the lower voltage ( may have to reduce the clock rate) and put to sleep when off . Save you a load of components and maybe power consumption .

  • interrupt to wake the processor , use millis to check the duration that button is pressed , less than this period send it back to sleep.

Paul__B:
Your graphic is unreadable. You need to post a usable version before we can discuss it. :roll_eyes:

Simply click on the photo to see the full size version.

hammy:
Why not do all this within the processor ( eg 328) , run it off the lower voltage ( may have to reduce the clock rate) and put to sleep when off . Save you a load of components and maybe power consumption .

  • interrupt to wake the processor , use millis to check the duration that button is pressed , less than this period send it back to sleep.

I need to run it off 5V. Would I be able to run it off of 3.3 V and have it switch to 5? I’ll look into it but I also may not have the space on the chip for the extra code. At the moment though I’d still like feedback on my current design.

The R/C setup on the flipflop's /CLR pin appears to be there only to make sure the flipflop always powers up in a known state. Otherwise it could come up in either state. But so long as it always comes up cleared, I don't see why you would need a longer time period on the /CLR pin.

When the battery is first connected, all the stuff over by the switch will start off at ground, assuming capacitor C3 is discharged. So A will be low and Y will be high. Then C3 will charge very quickly through D5, which will bring A high and Y low, but that only produces a falling edge on the CLK pin of the flipflop, not the rising edge needed to change state. The next rising edge will only come 2 seconds after you push the button. So it seems to me that your circuit should work ok. The flipflop will either come up cleared in the first place, or will be /CLRed very shortly thereafter, and it should stay that way until you press the button.

But I want to raise another issue similar to hammy's suggestion. Even if you need 5V for your MCU and other parts, all of that hardware between the push button and the enable pin of the boost converter could be replaced by a single 8-pin cheap microcontroller that could sleep very soundly until a button push wakes it up, then it could do whatever you want with respect to driving the enable pin. And it would remember its state. Sometimes we have to remind ourselves that this kind of solution exists now at a reasonable price, and that all those discretes and I/Cs may not be necessary. And I'll bet JLCPBC has some very low cost options. The downside would be the need to program it in circuit, so you'd need header pins.

ShermanP: The R/C setup on the flipflop's /CLR pin appears to be there only to make sure the flipflop always powers up in a known state. Otherwise it could come up in either state. But so long as it always comes up cleared, I don't see why you would need a longer time period on the /CLR pin.

When the battery is first connected, all the stuff over by the switch will start off at ground, assuming capacitor C3 is discharged. So A will be low and Y will be high. Then C3 will charge very quickly through D5, which will bring A high and Y low, but that only produces a falling edge on the CLK pin of the flipflop, not the rising edge needed to change state. The next rising edge will only come 2 seconds after you push the button. So it seems to me that your circuit should work ok. The flipflop will either come up cleared in the first place, or will be /CLRed very shortly thereafter, and it should stay that way until you press the button.

But I want to raise another issue similar to hammy's suggestion. Even if you need 5V for your MCU and other parts, all of that hardware between the push button and the enable pin of the boost converter could be replaced by a single 8-pin cheap microcontroller that could sleep very soundly until a button push wakes it up, then it could do whatever you want with respect to driving the enable pin. And it would remember its state. Sometimes we have to remind ourselves that this kind of solution exists now at a reasonable price, and that all those discretes and I/Cs may not be necessary. And I'll bet JLCPBC has some very low cost options. The downside would be the need to program it in circuit, so you'd need header pins.

Thank you for your feedback! I was considering the option of a cheap MCU but the issue is that, like you said, id have to program it in circuit. I'm already doing ISP with the atmega328p. I suppose I should spend some more time looking at the MCU's on their site to see if I can find a cheap one. This MCU https://lcsc.com/product-detail/Interface-Specialized_Maxim-Integrated-MAX16054AZT-T_C79401.html was suggested elsewhere but it's not exactly cheap, expensive actually at 1.60 a unit, vs the 0.45 cents total cost of both units in my schematic. The other thing is that while yes there are a lot of components here, they're cheap, don't require me to program anything, and because they're being assembled for me I'm not concerned with the component count. It ends up being cheaper/easier than using a MCU in this particular case.

Kuusou: Simply click on the photo to see the full size version.

Ah, well, you should have put the full size image in the image tag, not the thumbnail!

The forum software automatically displays the image at a size to match the thread proper, so that might be somewhat more visible (and easily expanded). |500x224 You do realise of course, that your circuit does not actually turn off the power to the target circuit, but only switches between 3 V and 5 V?

Paul__B: Ah, well, you should have put the full size image in the image tag, not the thumbnail!

The forum software automatically displays the image at a size to match the thread proper, so that might be somewhat more visible (and easily expanded). |500x224 You do realise of course, that your circuit does not actually turn off the power to the target circuit, but only switches between 3 V and 5 V?

No I didn't realize that! I thought turning the EN pin off would prevent the boost converter from giving any power to the rest of the board. What am I missing then?

Kuusou: What am I missing then?

Well, that is a good question. :grinning:

Trace the path through the switchmode boost (note that detail,) converter - the inductor and the Schottky. :sunglasses:

Paul__B: Well, that is a good question. :grinning:

Trace the path through the switchmode boost (note that detail,) converter - the inductor and the Schottky. :sunglasses:

Ok I think I see what you're getting at. I've got the 3.3V going to Vcc AND the inductor so it can do either. So I'm thinking would the solution be to put the inductor inline with the LX (power output) trace just before the diode?

Like this? |500x239

I don't think that will work. I think the normal function of LX is to switch to ground periodically. I don't think there's any connection from Vcc to LX. But Paul__B will know best.

If you can't find a boost converter with an enable that actually switches off the power, then you may have to use a mosfet to switch power going into the converter, and switch its gate with the flipflop.

ShermanP: I don't think that will work. I think the normal function of LX is to switch to ground periodically. I don't think there's any connection from Vcc to LX. But Paul__B will know best.

If you can't find a boost converter with an enable that actually switches off the power, then you may have to use a mosfet to switch power going into the converter, and switch its gate with the flipflop.

I believe you're correct. It appears that instead of connecting the Q pin of the flip flop to the EN pin of the boost converter IC I'll need to instead use the Q pin of the flip flop to control a MOSFET switch of some sort to shut off power to the entire boost converter circuit, otherwise I'll just have Vin on the Vout pin. I'm not exactly sure how to accomplish that just yet though

I think I've figured out how to cut off power to the entire boost converter circuit using the schematic below.

|500x263

I'm using a BJT which has its base connected to the Q pin of the flip flop. Which has its collector attached to the gate of a P-Channel MOSFET which acts as a switch for the main power going into the boost converter circuit. Please let me know if you believe this will work, any feedback is very much appreciated.

As I replied to your post on the other forum, if you use the NPN you’ll need to add a base resistor to limit base current, and a pullup resistor on the mosfet gate to bring the gate back high when the NPN is turned off.

A better alternative is to just drive the mosfet gate directly from the /Q output of the flipflop. I don’t think that requires any resistors, although some would say you need a series resistor of about 100 ohms to the gate. You don’t need the gate pullup because the /Q output is totem pole, and will always be active high or active low if the flipflop is powered at all.

ShermanP: As I replied to your post on the other forum, if you use the NPN you'll need to add a base resistor to limit base current, and a pullup resistor on the mosfet gate to bring the gate back high when the NPN is turned off.

A better alternative is to just drive the mosfet gate directly from the /Q output of the flipflop. I don't think that requires any resistors, although some would say you need a series resistor of about 100 ohms to the gate. You don't need the gate pullup because the /Q output is totem pole, and will always be active high or active low if the flipflop is powered at all.

Thank you so much for your response on both forums, I guess its a small world haha.

I'm confused as to why /Q works but Q doesn't? I'm sorry for being a noob with this stuff, I was hoping you could try to explain? My understanding is that the pulse sent to the flip flop becomes inverted by attaching /Q to the data input pin. So the pulse leading edge hits the IC, it says turn on but because /Q is inverted and is attached to the data pin it stays off until the low end of the pulse hits which is not until the end of a 2 second delay due to the rc timer circuit and hence I get my long press to turn on the power. If I use /Q to drive the gate instead of Q wouldn't that completely ignore the delayed start I'm looking for?

Looking at this more closely I think I'm seeing another issue. The flip flop doesn't remember states, I want to make sure that the board isn't powered on when plugged into power to charge the battery. I've got an RC circuit on the CLR pin (R6 & C6) I'm just insure of whether this circuit is pulling the pin low or high. I believe its pulling it low but I want to be sure.

In a D flipflop, except for the /PRE and /CLR pins, which can cause a change at any time, neither of the outputs ever changes except on the rising edge of CLK. Nothing happens on the falling edge. And the /Q output is always the inverse of the Q output. So while the /Q to D connection is what causes the flipflop to change to the opposite state on each rising edge of the clock, /Q also happens to be in the right state to turn off the mosfet when everything powers up (the R/C on /CLR causes Q to power up low, and /Q to power up high).

But if it will make you feel better, you can move the R/C to the /PRE pin, then connect Q directly to the mosfet gate. That will cause the flipflop to power up with Q high, which turns off the mosfet.

None of this makes any difference to the delay function. When you first connect power, the big capacitor will be discharged, so the input to the inverter will be low and the output high. This may cause a rising edge at the flipflop, but it won't matter because the R/C on /CLR or /PRE will determine the output state. Then when the big capacitor charges up, the inverter will switch to a low output, which is a falling edge at the flipflop, which has no effect on anything. Then when someone presses the button for two seconds, that's when you get a rising edge, which turns on the power.

Anyway, my point was that the NPN transistor is nothing more than an inverter for Q, and you already have such a circuit inside the flipflop, the output of which is /Q. So you just don't need the NPN. But if you do use it, you'll need to add a base resistor as well as a pullup resistor for the mosfet gate.

Not sure if this helps but I always use LM555 timers for one shots or delays

I would use a small cheap MCU (i.e. ATTiny13A) to do this. It would be in a deep sleep consuming <1uA while the button is not pressed. This way you can also implement more cleverness into it. Such as rejecting too long button press, auto power off after some time etc.

Smajdalf:
I would use a small cheap MCU (i.e. ATTiny13A) to do this. It would be in a deep sleep consuming <1uA while the button is not pressed. This way you can also implement more cleverness into it. Such as rejecting too long button press, auto power off after some time etc.

Already discussed. See #5. He prefers to use more of the cheapest parts and more board space. :grinning:

I would use an ATTiny85.