Push button On/Off circuit not working - Page 1
Forum section: electronics / projects

author: Twistx77
author_rank: Regular Contributor
timestamp: July 21, 2025, 11:56:41 am
content: Hi everyone,I've been puzzled by an issue in one of my boards. I've tried to implement a On/off switch using a push button and a D flip flop to have a bistable output.The idea is that every time I push the button the output (Pin 1 of J5) changes from high to low and low to high toggling its previous state. In simulation the circuit works but in the board it doesn't do what it is supposed to. The output seems to just follow the push button's state. BATT is a single cell LiPo battery which when I tested was around 3.9V. I've already tried shorting R60 and R59 to BATT and didn't seem to make any difference.Any ideas of what could be causing the issue? Also maybe for the future any suggestions of other types of circuits to achieve my goal? Maybe existing IC's for this?Thank you in advanceThank you.

author: Andy Watson
author_rank: Super Contributor
timestamp: July 21, 2025, 12:30:58 pm
content: Contact bounce. Button and switch contacts usually make multiple transitions for each mechanical actuation. This "bouncing" can last for several milliseconds - 1k and 0.1uF is insufficient time constant to cover that. The datasheet uses 10k and 1uF - I would also include 100in series with the button (to prevent current spikes.)There is also the problem of "rise time" of the clock input. The datasheet does not specify aminimumrisetime, but I would avoid putting a capacitor directly on the clock input. The datasheet shows an application (page 11) where the clock input is cleaned-up by a schmitt-input buffer.https://www.ti.com/lit/gpn/sn74lvc1g74Also, read the previous paragraph (9.1) about meeting the "hold time requirement of the D input".

author: Zero999
author_rank: Super Contributor
timestamp: July 21, 2025, 12:42:26 pm
content: How is C41 supposed to discharge? At the moment, its internal leakage and the tiny input current of the CMOS input discharge it very slowly and the latter isn't guaranteed, since it might be positive.Use the Nexperia brand 74LVC1G74, which has a schmitt trigger clock input.https://assets.nexperia.com/documents/data-sheet/74LVC1G74.pdf

author: xvr
author_rank: Frequent Contributor
timestamp: July 21, 2025, 01:05:58 pm
content: When the button is depressed, the C input of the D flip-flop becomes floating. The CMOS chip does not allow a floating input.

author: Andy Watson
author_rank: Super Contributor
timestamp: July 21, 2025, 01:18:26 pm
content: Quote from: Zero999 on July 21, 2025, 12:42:26 pmDoh! Yes, there's that as well

author: Twistx77
author_rank: Regular Contributor
timestamp: July 21, 2025, 02:34:59 pm
content: Hi,Thank you all for the inputs.I don't think the problem has anything to do with the bouncing of the switch, I had the attached circuit originally, and simplified it by disoldering components to see what was causing the issue, and I thought it was better to share the simplified circuit which, as pointed out by Zero999 has no discharging path for the capacitor other than any path through the Clock input. Still, I need to check why I see the voltage on the clock input following the button press as shown in the attached capture. Blue is the Clock input voltage and yellow is the Q voltage.In the original circuit I had some discharge path through the LED and 1K resistor. The idea was that it would charge "slowly" the capacitor and keep the voltage higher than the minimum logic voltage needed by the clock input thanks to the LED. Then, it would slowly discharge through the LED. This was done to delay the switching and that it would require some time (with big enough resistor or cap) about 2 seconds pressing the button to change the state. Of course, that would mean that after switching you would have to wait longer until the capacitor discharged below the threshold of the clock input but that is not a problem in my application.Quote from: Andy Watson on July 21, 2025, 12:30:58 pm

author: PGPG
author_rank: Frequent Contributor
timestamp: July 21, 2025, 02:54:23 pm
content: What current do you expect in LED5 now?

author: tooki
author_rank: Super Contributor
timestamp: July 21, 2025, 04:56:50 pm
content: Quote from: xvr on July 21, 2025, 01:05:58 pmI think you mean “When the button is not pressed, the C input is floating.”“Depress” is one of those weird words in English (like “flammable” and “inflammable”) that sounds like it should be the opposite of the word without the prefix (like “press”), but actually means the same thing: to “depress” a button means to press it.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 21, 2025, 08:04:22 pm
content: QuoteThat’s a real lottery.Usually you use a properSchmitt DFF(#2] and handle debounce using CinIf you want a recovery time, do that properly with a diode and two resistors, do not rely on LED leakage and cmos thresholds variances.

author: Zero999
author_rank: Super Contributor
timestamp: July 21, 2025, 08:10:25 pm
content: Quote from: Twistx77 on July 21, 2025, 02:34:59 pmNo, that won't work. 100k and 1k form a potential divider, which will prevent the capacitor from charging enough.Add a Schmitt trigger, or use the Nexpria part with a Schmitt trigger input.Put 100k across the capacitor and change R58 to 100R.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 22, 2025, 12:45:21 am
content: Quote from: Twistx77 on July 21, 2025, 11:56:41 amDo you need this to power-up in a defined state ?As drawn, power-up is random, but you can add a POR reset signal to a /CLR or use a RC POR on parts with schmitt trigger pins.Schmitt trigger on all pins are Nexperia 74LVC1G74 parts and Nexperia and TI 74AUP1G74 (lower voltage)Another part to consider is the SN74HCS74DYYR in SOT-23-14, that has 2 DFF so you can add some more duration smarts to your PB, if needed.

author: Twistx77
author_rank: Regular Contributor
timestamp: July 22, 2025, 09:15:04 am
content: Quote from: Zero999 on July 21, 2025, 08:10:25 pmI don't care if the recovery time is stable or repeatable withing a big range. This is only for a device that won't be a product and as long as it allows me to turn on and off my device with a push button it is fine. Still, how would you do it properly with a diode and two resistors? I'm not that familiar with analog timing circuits.Regarding the power-up state, I don't care about, I care more for space needed to implement the solution. At the end the power up only happens when I connect the LiPo to the device and never again unless the battery is, greatly discharged, replaced or damaged.I will try the Schmitt trigger part you suggest from Nexperia, thank you!For now I only put a 50 ohm resistor on R58, removed C41 and put a 10K on its place. This allows the circuit to work even though it is not 100% reliable probably because of the bouncing, it works 90% of the time which is good enough for the intended purpose. If I use a 1K in R58 instead of the 50Ohms it doesn't work and that I still don't understand why.Thank you very much anyway for all the support

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 22, 2025, 10:31:56 am
content: Quote from: Twistx77 on July 22, 2025, 09:15:04 amIf you want small, and do not need POR, the Nexperia 74lvc1g80 DFF comes in SOT363 with schmitt on all pins.If you do not care about recovery times, a simple RC into the CLK should be fine, with a pull down on the PB.The time constant needs to be long enough to constrain the bounce within the hysteresis band ~300mV,Experiment with 100-500ms ballparks.

author: Ian.M
author_rank: Super Contributor
timestamp: July 22, 2025, 11:41:48 am
content: https://www.ganssle.com/debouncing.htmis a must read for anyone without years of experience debouncing switch inputs reliably.However, unless constrained by the need to ground one side of the button, I'd probably choose to use the two inverter toggle latch circuit.It has inherent debouncing, and will continue to function reliably as the switch degrades. Seehttps://www.eevblog.com/forum/beginners/help-on-how-to-choose-an-ic-for-a-project/where eblc1388 presents this circuit, and I provide simulation support.

author: Twistx77
author_rank: Regular Contributor
timestamp: July 22, 2025, 12:07:29 pm
content: Quote from: PCB.Wiz on July 22, 2025, 10:31:56 amThank you, I still think that for the next revision I will go for the two inverter toggle latch circuit proposed by Ian.M. Still I though than RC should work for the clock input but at least without the schmitt DFF it doesn't seem to work. As soon as I put a Cap in the CLK pin it doesn't work even though the voltage reaches basically VBAT when I push the button, that is what I don't get.Quote from: Ian.M on July 22, 2025, 11:41:48 amAwesome, I thought of using inverters for it but at the moment I was designing a solution we wanted to get a board manufactured quickly and didn't put the time to think of a solution with inverters.Thank you!

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 22, 2025, 07:47:29 pm
content: Quote from: Ian.M on July 22, 2025, 11:41:48 amOne detail the OP may add, is better ESD support.The specific button controllers from ADI & TI etc have ESD specs on the button pin of 15-25kVA series r into the first gate helps ESD protection, otherwise the button connects directly to a CMOS ip pin.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 22, 2025, 07:52:28 pm
content: Quote from: Twistx77 on July 22, 2025, 12:07:29 pmif you have a fast scope, you could see what happens.With no hysteresis, multiple clocks can be seen inside the device, due to threshold oscillation and parasitic inductance.

author: Ian.M
author_rank: Super Contributor
timestamp: July 22, 2025, 10:01:47 pm
content: Quote from: PCB.Wiz on July 22, 2025, 07:47:29 pmYes, adding 10K or so of resistance in series with the first gate input will make it a lot more robust.