P MOSFET and button bounce - Page 1
Forum section: electronics / beginners

author: jwny_
author_rank: Contributor
timestamp: March 18, 2024, 02:45:19 pm
content: Hello!First time poster here and very much a beginner... seeking beginner advice. I've the following single button latch that seems to be rather ubiquitous on the internet. I've built it in MultisimLive, pulled what I could out of the manufactures PSpice model and configured the MOSFETs accordingly (I believe, at least), and things work as expected, however, there's no way that I know of to simulate button bounce.As I've a 3.3V boost regulator downstream from the MOSFET, I can only imagine that it would be rather unhappy with bounce at the MOSFETs gate - which would in turn propagate to all of the other components on the PCB. Is this a correct assumption? Would just placing a simple RC de-bounce circuit around the button do the trick?Thank you!

author: Ian.M
author_rank: Super Contributor
timestamp: March 18, 2024, 03:00:28 pm
content: Bounce is alleviated by the C1, R2 time constant of 10 ms. Hopefully that gives long enough for the MCU to power-up and run code to turn on the N-MOSFET and latch the circuit on, at which point it's the MCU's responsibility to do software debouncing.A bigger concern is the peak current through the switch due to C1 charging. There is nothing to limit this other than the supply impedance, D4 slope resistance and switch on resistance, and to avoid a possible large negative transient (from the capacitor ringing with the loop inductance) on the GPIO pin which could latchup the MCU, you may need to add a resistor in series with C1 , typically a few tens to maybe a hundred ohms or so.

author: jwny_
author_rank: Contributor
timestamp: March 18, 2024, 04:38:08 pm
content: Thank you for your reply!Quote from: Ian.M on March 18, 2024, 03:00:28 pmThis is a lot to digest, but I now have a lot of items to look up, read and learn. Thank you.If I understand correctly, the capacitor is acting like a short and drawing a lot of current without a limiting resistor. With a, say 100 ohm resistor, the peak current at 3.0V will be limited to 30 mA when the battery is at full voltage and about 18 mA when nearly drained at 1.8V. Without said resistor, there could be a theoretical peak current of 18.75A, but realistically much less with alkalines. (The datasheet for a Duracell AA battery states, "Impedance 80 m-ohm @ 1 kHz") Is this generally correct?Please forgive my understanding, or lack there-of, but as far as I do understand, the two resistors (R1, R6) are now in parallel. I've attached what I believe to be what you suggested, but wouldn't this drop the overall resistance to just under 100 ohms total? Or will this only occur for a very brief moment (the 5RC time constant's worth?) as once C1 is charged, it's resistance will essentially become "infinite" (I know this is not quite correct, just not entirely sure of the correct terminology) and the overall resistance will return to the resistance of R1 or 100Kohm?

author: jwet
author_rank: Frequent Contributor
timestamp: March 18, 2024, 04:50:30 pm
content: +1 for the last poster's tip on C1's ability to burn up the lower FET. I've experienced this. Also bounce won't be an issue, you're sinking current to turn on the PFET and there is no fast path to discharge it- you've debounced it.I don't know how size constrained you are, but there are dual FET's with a big PFET and a little NFET for this function in an SC-70 for about a dime. Example is NTJD1155L. This and FDG6323 (now obsolete) data sheet has a good apps section that goes through the app pretty nicely and puts values and explanations on all the R's and C's around the part. One thing they do in their standard circuit is to put a resistor in the source to ground connection of the lower FET for soft start and to alleviate the C1 issue.Note that if you use a bidirectional pin for the uP hold up pin or get clever, you can poll it to sense the state of the switch during operation. Its common to have a short press to be a backlight function and a long press to be power off. You have to hang in a loop on power down so the device doesn't power up again.

author: jwny_
author_rank: Contributor
timestamp: March 18, 2024, 05:39:56 pm
content: Thank you for the information.I've downloaded and snipped the relevant diagrams and explanations from both datasheets; very helpful. Thus far, I think I've learned more about MOSFETs here than I have reading various, "MOSFETs as a switch" type tutorials. I don't think I've ever come across one that spoke of slew-rate control; perhaps I've just been visiting the wrong tutorial sites.And yep, I was planning on initially having the GPIO set up as an input with its internal pull-up enabled to detect button presses, although only to prevent short presses from turning everything off.

author: jwet
author_rank: Frequent Contributor
timestamp: March 18, 2024, 07:20:18 pm
content: There is one other note that is interesting and a bit surprising for these circuits that I've discovered over the years. Though they are almost universally designed with high side PFET's, in some cases, a bipolar is better believe it or not.The drop of a bipolar is Vce sat, the drop of a FET is IR. There is a cross over at fractions of an amp where Vce sat can be lower than IR and more cost effective- bipolars singles are really cheap. The PFET parts that I've used are .5 ohms max, at an amp- this would be .5V. You can get bipolars with high beta (>100) that can have Vce sats of < 0.1v. The digikey search engine will let you sort on any of these paramaters. Zetex and Nexperia (BISS) have line of transistors that have unusually low Vce sats.The other potential win is very low threshold FET's the are fully enhanced at 1.8v (two near dead Alkaline cells in your circuit) don't have great leakage specs especially over temp- this turns into dead batteries over long storage times. Also, if you want to do one cell, you'd require an ultra low Vgs PFET that could get expensive.You do waste the base current but if you can keep beta greater than 50, its only 2% and its only used when on. Betas for deeply saturated transistors can be bad- though. Worth playing with some parts.Just more to round out your education...

author: jwny_
author_rank: Contributor
timestamp: March 18, 2024, 08:07:58 pm
content: This is really great information, jwet; and I very much appreciate your time and knowledge.Very timely as well; this current project is employing a TPS61322 to generate the boards 3.3V power and at some future point, I was hoping to see how it would do with only a single AA battery. I had not considered that which you wrote about; MOSFETs that would work down at these voltages, the expense and viability in replacing the switches with BJT's.I'll definitely take a look on digikey and snag a few of the suggested BJT's from the listed manufacturers and finally start building these on a breadboard and see how things go. Should be fun!

author: jwet
author_rank: Frequent Contributor
timestamp: March 20, 2024, 02:57:50 am
content: It all depends on your average and peak power demands. An alkaline AA cell has a 2 A-Hr capacity at a nominal C/10 discharge rate, AAA's are 1/2 this. So an AA can support 200 mA and AAA can do 100 mA nominally without much sweat. They can do more and peaks up to C/5 don't affect life much. Peaks like C/2 start to shorten life- this is the photo flash application.You can work backwards away from your 3.3 V, say 85% efficiency and average cell of 1.3v which would give you a C/10 average load of 70 mA for AA and 35 mA for AAA at 3.3v. The cells will be loaded as above. This is a light load these days. Of course, its only the average, you could have sleep and wake and pulse modes that could average to this. Single cell operation is pretty nice but it doesn't fit a lot of applications. This is why so much stuff runs on LiIon's with a 4v average working voltage and a 3 A-Hr of capacity or better. This is about 4x of an AA.I'm long retired but worked as an FAE and strategic apps guy for Maxim for many years and can do these kind of calcs in my sleep. I really enjoy those little power up circuits- I had several customers that were into them too- Glucose Meter Guys and Handheld GPS. I think there should be a law that everything should be auto off.Good luck.jwet

author: Peabody
author_rank: Super Contributor
timestamp: March 20, 2024, 02:36:11 pm
content: My memory is that C1 is only there to prevent the circuit from turning on automatically when the batteries are first connected, and really serves no purpose after that. If so, it could be much smaller, or even eliminated.Also, I don't remember seeing any switch bounce problems even with C1 absent. If the first contact discharges the gate capacitance enough to turn on the mosfet, then any interruption from bouncing would bring the gate back high only through the resistor, which would take some time. So you have some RC going on even without C1. And you also have all the bypass capacitance throughout the circuit smoothing things out. Anyway, I just don't remember switch bounce being a problem with this circuit, without C1.

author: jwny_
author_rank: Contributor
timestamp: March 21, 2024, 02:57:03 pm
content: Thanks again for the info - all of this stuff I'm copying, tagging and filing in my notes folder. This is great.I had considered LiIon, but I honestly don't know enough about how to properly handle, charge and protect them at all. Sure, I could just buy modules and throw it together with what I am putting together, but it feels like cheating. I'd much rather go through the design process and learn what I can and build it myself; much like what I'm doing with this thread and this little project -- but without the dangers of screwing something up with LiIon and potentially having bigger, and much more flammable, issues.Not to mention the fact that I'm building this for my son, who's almost 8, and giving him something designed and built by someone who's just learning this himself... it's probably bad news. Heh. I'll get there eventually, but I'm definitely not there yet.---So, I've modified the previous circuit utilizing the datasheets that you had suggested (image 1, image 2 is from the datasheet) with R1 10X the value of R9, C3 at 1000pF and C2 at 1uF. However, I'd imagine that I'd need to also simulate the anticipated load to adequately simulate the inrush current and nail down more specific component values; this is probably a really dumb question, but do I just add up the series capacitance in the rest of the circuit (bypass caps, etc.) and just place a single equivalent capacitor in the sim to ground? I've attached the rest of the schematic for reference (image 3).I've been reading of why inrush current limiting is a good thing and such, but what never occurred to me is, "exactly how much inrush current is acceptable and what do we actually design for?" Of course, I understand I don't want to blow up the MOSFET, so keeping the inrush current well below the DC drain current would be ideal, but what other considerations should I be taking into account?

author: jwny_
author_rank: Contributor
timestamp: March 21, 2024, 03:16:01 pm
content: Thank you for your reply, Peabody.The inclusion of this capacitor was due to Dave's video on the "World's Simplest Soft Latching Power Switch Circuit", so I felt it was prudent to include it. Once I have this nailed down in the sim and get this built, I will definitely see how this functions for real with and without C1. It'll be interesting to see what, if anything, changes.

author: jwet
author_rank: Frequent Contributor
timestamp: March 21, 2024, 04:15:49 pm
content: I'm not a big fan of LiIon's either for similar reasons really. I also like disposables better, seems like charageables are always dead when I need them.One final input on this stuff is shutdown pins on DC-DC's. You can put similar little or'ing button circuits around them to do power on an off. A simple boost converter has a path through the part with the inductor and the diode and can't be turned off. Fancier boost converters that use an active switch as the output rectifier can be turned off. Check the specs carefully for sleep current, input threshold on shdn pin and if there is a diode across the active rectifier, etc.That's quite a spice model! I do mostly back of the envelope and prototyping and bench testing.Good luck with your project and raising your son. I like the fact that you thank those that contribute, this is very motivating and is the right way to be.John

author: Peabody
author_rank: Super Contributor
timestamp: March 22, 2024, 02:18:11 am
content: You may find this video interesting:I think your circuit is the third one convered in the video, originally from @Ian.M here. Notice that C1 in that circuit is 10nF.And here's the thread the video was based on:https://www.eevblog.com/forum/beginners/push-button-power-circuit-for-arduino-trying-to-modify-it-for-12v-input/

author: jwny_
author_rank: Contributor
timestamp: March 22, 2024, 11:30:15 am
content: Wow, thank you for the video link and the link to the EEVBlog thread; I'm going to have to go through that much more carefully today. I find it really interesting to see the evolution of things, and the how's and why's, during the lifetime of a thread like that.I originally found the circuit I went with over at:https://circuitcellar.com/resources/quickbits/soft-latching-power-circuits/...and went with it for much the same reason as each of the included circuits was largely based on the one prior and it seemed to have good descriptions of how the circuit functioned. I find seeing iterative design like this is really helpful for learning.Thanks again!

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2024, 12:16:50 pm
content: I cant have been the first to use a dual diode to allow the button to both apply power and be sensed by a GPIO pin on a different supply rail, and I *KNOW* I wasn't the first to use a single GPIO for both switch control and sensing, so yes, these circuits have definately evolved over the years. I suspect that the pre-condition that made single pin controlled soft latching power switches possible was the introduction of MCUs with individually controllable weak pullups, which IIRC was circa 1997. Give it a few years and the hobby community of PIC microcontroller users circa 2000-2005 are probably where most of the development happened. Then in 2005, along came Arduino, and the crapification began!N.B. the GPIO pulldown diode needs to be Schottky to meet the TTL logic low input threshold limit for 5V logic, or to have enough margin on that threshold for 3.3V CMOS logic. With 5V CMOS threshold logic, there's sufficient margin even with silicon diodes, which are preferable if you need to minimise high temperature off-state leakage current.

author: jwny_
author_rank: Contributor
timestamp: March 22, 2024, 01:46:46 pm
content: Circuits are hard; and trying to learn this stuff properly, even on a basic level, feels even harder when trying to do this solo. At my level of inexperience, it's very difficult to determine when something found online is even marginally correct... and it's this which drives me down the rabbit hole to try and fully (to the best of my ability) understand how and why it will, or will not, work. I don't want to create something that's just marginal, I want to create something that is functionally correct as best as I can.Thank you Ian, Jwet, and Peabody for your help to get me where I am with this. Not only do I feel a lot more comfortable with the understanding of this circuit, but I've been introduced to a lot of other considerations that I didn't even know about (slew rate control, inrush limiting, etc.) You guys are great.Regarding the diode, I've selected Onsemi's BAT54XV2; 0.35 V forward voltage @ 10mA. I should be will within the logic low input signal level.I also recently ordered and received, "Practical Electronics for Inventors"; seems like a good book to start with and learn from.Thanks again!

author: Peabody
author_rank: Super Contributor
timestamp: March 22, 2024, 02:28:49 pm
content: Actually, I don't know anything about slew rate control or inrush current limiting either. And for the circuits I do (low current), it doesn't seem to matter.I still wonder if Ian.M's 10nF for C1 couldn't be even smaller, which means you wouldn't need the resistor. Of course it depends on the mosfet, but I wouldn't be surprised if something in the pF range still works.

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2024, 02:48:19 pm
content: IIRC, I picked 10nF as an order of magnitude greater than the worst case P-MOSFET gate capacitance, to guarantee that no matter what it would power up in the off state, and also so its time constant with the 100K gate pullup would be at least an order of magnitude greater than the time it took to charge the N-MOFET gate via the GPIO weak pullup when the button switch was released, so the P-MOSFET would stay on for certain during the transition. It also kept the stored energy low enough for the switch to handle.

author: jwet
author_rank: Frequent Contributor
timestamp: March 22, 2024, 02:55:16 pm
content: Last words, I promise-Your diode is a good pick and I wouldn't change if you've got your board done. There are tons of versions of the BAT54- the BAT54CLT3G is a dual with common cathode. They are also in a SOT-23 which is important if you're getting boards assembled by others- keep the number of unique package types to a minimum- reduce setup charges. They're about as cheap as the singles in any volumes, can't be inserted backwards and you'll be surprised how often you need a little OR gate. One gotcha with Schottky's is reverse leakage at temp especially. Reverse leakage and sub threshold forward leakage can approach 1 mA at hot hot but is ok at room to 85C where they cross 10 uA typ. See graphs in datasheet- they don't hide this but they don't make it easy either. This really matters for flea powered stuff that runs a year on a coin cell."Practical Electronics for Inventors" is a great book for someone who just wants to make stuff that works and gets into just enough detail to explain why- good pick. Come back for more recommendations once you've digested that.