P-channel MOSFET as a GPIO controlled high-side switch - Page 1
Forum section: electronics / projects

author: pini.grigio
author_rank: Contributor
timestamp: January 08, 2024, 09:01:18 pm
content: Hi,For my current project I need to switch on and off a secondary 12V power supply from a Raspberry Pi GPIO.I'd also like to integrate an LED for showing the current status of the secondary rail, as well as be able to monitor it from another GPIO pin.I came up with the following circuit and prototyped it using an IRF5305 P-channel mosfet and a couple of 2n7000s.I'm looking for some feedback and improvement suggestions:https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACgAlWvKtPbqmBo0oomoJSiqMBGwAyIFoRCZJTYstVSQAMwCGAGwDODapDY7wYSX3DEb+ENnphoSHmwDudyWEKD7HyhOK19rUO5tcXBJaSg3NgAnCNYw339RMHg2PzTwDNSVR0kAEwZ9AFcDABcmAwYS8G0YSHZkpRUMSWwbLsy4CydevK0e8Dd4yBQvCNtClARlcwBzWbx+Qucl4OSUaJQ9lWjcESoaNlW9qhOj6+xt828wQIORK5VD80txXkOaHg+IjGriQLWmq3+1zwIkhtEIpx2Aic9yR2GhomcAy4z3SAUkGiiEmaCWSP0BtDgQziWXg5lJAPesJ61NpMyZaFRKPMAFlURz-PxmaIUAlvO9XhTfqc2ZShezpGwAB4qQg2QhIbBgJBEfhvERyAD2ehKbCAAThanks!

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 08, 2024, 09:06:11 pm
content: A npn will work better with low voltages like those in GPIOs.Then yeah, the p-fet will do fine.100K pullup for the p-get gate should be more than enough for simple on/off switching, unless you're using high frequency pwm.Also 100K should be good for driving the base of the npn controlling the p-fet, any general purpose npn like 2n2222A, bc547... should do the job.

author: Zero999
author_rank: Super Contributor
timestamp: January 08, 2024, 10:04:45 pm
content: Yes use a BJT. This circuit will work with 12V for V1 with no modification.Use a potential divider for the GPIO monitoring.https://en.wikipedia.org/wiki/Voltage_divider?useskin=vectorUsing the calculator below gives the following values:https://www.random-science-tools.com/electronics/divider.htmR1 = 47kR2 = 33k

author: Ian.M
author_rank: Super Contributor
timestamp: January 08, 2024, 10:07:03 pm
content: +1Your Falstad circuit is not good.The LED in series with the gate pullup may give problems turning the P MOSFET off - depending on its color and the min. Vgs_threshold, the MOSFET may even turn on if its exposed to strong illumination!Fix: drive the LED from the switched 12V rail.Also, the rail sensing circuit doesn't inspire confidence. It may fail to reach a valid logic 1 level for the GPIO input.Fix: A simple potential divider, 300K upper and 100K lower resistors might do better, as that guarantees >2.0V and <3.3V at the input from 8V up to 13.2V and is unlikely to do damage below 15V, but a voltage supervisor IC (i.e. a comparator with a built-in reference) to drive the GPIO input would be a better choice.

author: pini.grigio
author_rank: Contributor
timestamp: January 09, 2024, 03:03:25 pm
content: Thanks for the feedback everyone.A few questions -1. If Im using a BJT, does it matter how I bias it? Is a base resistor needed here? I included a gate resistor previously for any transient shorts in the FET.2. Regarding my divider network - I don't need another FET/BJT to sample the rail here? I was worried about my load having an effect on the sensing node. I'll make the values larger anyway.How's this?https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACgAZEFwkTFbsV78o4EADMAhgBsAzg2qQ248GAFo84Yuvwhs9MNCR4lAdy0CwhKmG0WobAEqrLal7U1UqNGwK9QjNgAnd1ZXHU9keDYrAWwEOOxeeLi8Gj4QABMGKQBXaQAXJmkGTLF-GEh2EJ4+DDj1etEwODZzML5dDpQEXiUAc3d9Xg7sNNElEJQfPmm+Gdx07zZB6apF+fWkibb7FDm12aWneysbOyEJ2l8rmAQ2AFlaQnSNhDsNqhRA80P914SRwcAA8+IR1IQkNgwEgiJp0nMOAB7SSZNgFPSNcJ1PxiJjfQhgPDEViEYnEAiYYgBBAYGj7Ko0PDxbAobTkFpUbJ5Qq7FJ6bb8z4rPSAsYAgQ0Kw7EL8-6iuKQJZRMwKoE0F5AybPBFzDWvJXNeCtEL6vSGs3i0T6aKDS3jM1SvoOELdPCaUbbGzGthAA

author: Ian.M
author_rank: Super Contributor
timestamp: January 09, 2024, 03:24:45 pm
content: That only gives you 2.7V of gate drive (swing), and if the MOSFET gate oxide fails, it will take out the NPN transistor and probably the GPIO. Put a 1K resistor between the gate and the collector to pullup junction, and that gets rid of the nasty cascade failure mode. Get rid of the emitter resistor and make the base resistor 10K and you'll get a little under 12V gate drive. OTOH if the MOSFET is low Vgs threshold with a max. Vgs under 12V, make the emitter resistor 2K7 for approx 1mA drive current and make the pullup 4K7 for ~4.7V gate drive (in the 'ballpark' for a max. 8V Vgs MOSFET), or whatever resistance you like at 1K per V for the drive voltage you want (up to approx. (+V -3.5) V, so ~8.5 V for 12V supply).

author: dobsonr741
author_rank: Frequent Contributor
timestamp: January 09, 2024, 04:11:31 pm
content: Why such a low (2.2K) value for R1? It would only beneficial if switching time matters, where I think it is not.

author: Ian.M
author_rank: Super Contributor
timestamp: January 09, 2024, 05:17:45 pm
content: Quote from: dobsonr741 on January 09, 2024, 04:11:31 pmI assume we are discussing Zero999's circuit, though mine is very similar.2.7 mA for the driver (because 3.3V logic and 1K emitter resistor)) isn't unreasonable, as even a Pi Zero uses 80mA or more at idle. R1 of 2.2K then gives ~6V gate swing, which is about right for driving an 8V max. Vgs MOSFET as hard as you safely can.You *could* scale R1 and R2 up by an order of magnitude or more, but depending on the load's inrush current and the MOSFET gate charge and SOA, ignoring switching time may not be wise, so you'd need to do the math and probably sim it to check it wont be pushing the single pulse limits too closely.

author: Zero999
author_rank: Super Contributor
timestamp: January 09, 2024, 06:16:22 pm
content: Quote from: Ian.M on January 09, 2024, 03:24:45 pmWhy would it take out the NPN transistor? The BJT will only ever see 12V, if the gate goes bad and the emitter resistor will limit the current nicely. It's far more likely to pop, if there's no emitter resistor, because the hFEis the only thing which will limit the current.Heck, I've never bothered because whenever I've designed anything like this. The philosophy was to always throw out the whole board if it fails, so it makes no difference whether the whole thing is toast or not.

author: Ian.M
author_rank: Super Contributor
timestamp: January 09, 2024, 11:44:52 pm
content: Gate oxide failure cant pop our current sink level shifters due to the large emitter resistor limiting the collector current. However if using a common emitter level shifter because 12V gate swing is required, a series gate resistor may be advisable to limit the carnage (by avoiding gate oxide failure applying a stiff 12V direct to the collector), and possibly in normal operation to control the turn-on speed, for EMI or inrush current mitigation.However, unless the high side MOSFET is abused, gate oxide failure is vanishingly unlikely, so your viewpoint of the whole board being disposable (and possibly the Pi as well if unlucky) is probably justifiable vs the cost of an extra resistor for a large production run.

author: pini.grigio
author_rank: Contributor
timestamp: January 10, 2024, 02:07:51 pm
content: Very cool. Thank you.Could you elaborate a little about choosing the correct gate drive setup?The PFET Im using is +-20V Vgs max but its also fairly low Vgs threshold (max -4V), so Im leaning towards the first option you suggested, but lets say I wanted to switch to a less beefy FET in the future - then I would just need to adjust my collector and emitter resistors to lower the gate drive?i.e.:https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACgAZEFsFETPi2J8BUcCABmAQwA2AZwYhs0epDYTwvfvnDDteJfRog8agO66+YQlTB67fNQCVwhTVbc0DVKjVuOxGAQ2ACdXd3C0b1oMODZrPmwEROw3JMS8Yz4AEwZpAFcZABcmGQZs8R8oWHYLa31IhDc1AHNw1IN6mnqfUP4-fhQsgdxjWzY2oapR-unUwLY6vRQh2cGxthcHV1s9YmaxAa0qoLYAWVpCYxmEPRmqFGhgiyn1pWS3tQAPfib+LCUkGI-FMtH6IA4AHspNk2EVuFd-h4kWIIEwaNAUGQEHgksQEHYaJhmk9iDQiaY8PtCIRUvUwHAQLkCsVFu8UmkPvcJuylJled0Dmowuk3qL7sg4hZRStjDREbKoH15VlVirAWNJfBlYiZursPy5tq2vr+erBQswjwRBhBArbaj4MLIjp9g1bNqLG6ohEfeZInhOml5s76th5mHCNFMHEgAThanks again, Im learning a lot here

author: Zero999
author_rank: Super Contributor
timestamp: January 10, 2024, 10:55:45 pm
content: What's the MCU PSU voltage? The Falstad simulations all show 5V, but 3.3V has been mentioned by some in the thread.To achieve a low on resistance, the MOSFET needs to have a much higher gate-source voltage, than the threshold, which is the bare minimum required to turn it on, allowing a tiny current to pass.How fast is the MOSFET switching? Is it PWM or just static on/off? The circuits posted here so far are very slow and only good for switching a static load, not PWM.

author: pini.grigio
author_rank: Contributor
timestamp: January 11, 2024, 12:02:48 pm
content: It's 3.3V. and I'm just switching a static loadIn the last Falstad simulation I made I was using the values Ian.M suggested for 4.7V gate drive but I would probably aim for around 8V in the actual application.Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: January 11, 2024, 01:44:36 pm
content: A reasonable rule of thumb is you need gate drive swing of at least double the max. gate threshold voltage to turn on a MOSFET hard enough to switch a real load. Detailed study of the specific datasheet is still required to check the Rds_on will be low enough for the application, but the rule of thumb aids in quickly ruling out unsuitable parts.The NPN + emitter resistor current sink driver is only beneficial when it is necessary to limit the gate drive to accommodate a P-MOSFET with abs. max. Vgs less than the supply voltage it is switching. This is *NOT* the case for a 12V supply and a 20V Vgs_max MOSFET, I would expect its optimum Vgs for a high load switching application to be in the 10V - 15V range, so driving it with a gate swing of close to the full 12V supply voltage using a common emitter NPN operating as a switch (i.e. no emitter resistor), will be appropriate for medium power applications not requiring fast PWM.Note that Falstad is *not* a SPICE based simulator and some of its quirks can be misleading. In this case, its generic MOSFET model does not model gate charge, so is useless for assessing switching speed or peak dissipation during switching. Falstad is good for sharing circuit ideas, but not so much for deciding if they are actually workable.

author: Zero999
author_rank: Super Contributor
timestamp: January 11, 2024, 06:33:59 pm
content: How about a MOSFET driver IC such as the TC426, MCP14A0303, MIC4429 etc.? It might be a little overkill, but easier.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: January 12, 2024, 02:54:37 pm
content: Why keeping the emitter resistor? No need to linearize when switching, not having the emitter resistor allows faster evacuation of the gate charge, for the speed concerned ones.

author: Zero999
author_rank: Super Contributor
timestamp: January 12, 2024, 07:10:46 pm
content: Quote from: dobsonr741 on January 12, 2024, 02:54:37 pmThe main reason for the emitter resistor when the supply voltage is higher than the gate-source voltage, but you're right, it's not needed in this case. The only reason for it would be to protect the BJT, if the gate oxide blows, but it's cheap enough to replace.Quote from: pini.grigio on January 11, 2024, 12:02:48 pmHow many channels? Is it just the one? If it's many, then makes more sense to use an IC. For example the CD4504B level shifter gives six channels and will be faster than a BJT, but a much slower than a gate drive IC.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: January 13, 2024, 09:35:15 pm
content: This is what I've just built and tested. Works like a charm, switching power for a 20W class D amplifier.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 13, 2024, 11:59:01 pm
content: Yep sure, I don't see why it wouldn't. Classic and simple.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 14, 2024, 12:53:03 am
content: Why the second 12K resistor? It's making a voltage divider, powering the gate with 6V. Just pull it to gnd, will switch much better at 12V while saving a resistor.And why 12K resistors? 100K will do the job consuming less current.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 14, 2024, 03:07:47 am
content: Quote from: DavidAlfa on January 14, 2024, 12:53:03 amA series gate R does 2 thingsit slows the rise time, avoiding very fast turn on.it gives some protection against spikes on the 12V - with hard switching, a very short 12V spike over 20V can damage the mosfet

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 14, 2024, 03:57:55 am
content: Just a note about that: the Si4511 (shown on the schematic) seems obsolete, couldn't find a datasheet on the official website, but on alldatasheet.com. ( dobsonr741 may have had a few spare in a drawer, but I'd suggest going for some other ref. if this is going to be produced - Vishay have a lot of alternatives.)But to the point: while the Si4511 is a 20V max VDS for both P & N devices, it's only +/-12V VGS max for the P device, which is much too close to the power rail to my liking, and that of dobsonr741 most likely, so a divider here is not useless nor extreme caution either. TLDR; read datasheets.

author: Peabody
author_rank: Super Contributor
timestamp: January 14, 2024, 04:47:11 am
content: But why 12K resistors?

author: dobsonr741
author_rank: Frequent Contributor
timestamp: January 14, 2024, 05:17:47 am
content: QuoteFirst I wanted to use 10K, then realized my parts box was low on 10K 1/8W but had much more 12K, so I used that. And yes, I have a whole lot of Si4511.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 14, 2024, 06:34:50 am
content: Since the min RDSon for the PMOS is given for -4.5V, a divider by 2 as dobsonr741 did here seems reasonable (6V), no need to get higher. Some may add a zener diode between gate and source (if the +12V rail may accidentally go beyond 24V), but that's probably overkill here and that would be beyond the max VDS too. So you could add a zener diode between the +12V and GND instead (and a fuse in series) in case this power rail could be provided by the user.After that, sure you could increase those values if you want a bit less static current, although I bet that it's negligible compared to the current the load draws. So, that's fine.

author: Zero999
author_rank: Super Contributor
timestamp: January 14, 2024, 09:38:25 am
content: Quote from: Peabody on January 14, 2024, 04:47:11 amBut why not 12k resistors?To optimise production, supply and storage costs. it make sense to minimise the number of different parts on the BoM. If another part of the circuit, say a voltage regulator or amplifier feedback network, needs 12k, then it's sensible to use 12k for other resistors, rather than another value such as 10k.

author: Peabody
author_rank: Super Contributor
timestamp: January 14, 2024, 03:53:40 pm
content: I was just referring to @DavidAlfa's point that 100K would work as well and use less current. Is there a specific need to use low-value resistors? It's a simple power switch, so I wouldn't think speed matters.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: January 14, 2024, 04:12:41 pm
content: Choosing 1.2K is artistic freedom.It's a convention from the days when MOSFETs were not wide spread, and BJT would have been used. A 1K was a conventional value back then for this purpose. I still like the lower impedance, when environmental issues, like improper cleaning on my breadboard can cause borderline issues when a high impedance driving would have been used. It's not making any power consumption impact.The 2x 12Ks on the other hand is optimal for not wasting much power, and also not much risk of of the high impedance driving, just like above. I have no supply chain, as it's a box for my own personal use and I only built two.

author: pini.grigio
author_rank: Contributor
timestamp: January 15, 2024, 03:31:52 pm
content: Thanks everyone.Following up with another question on this topic - I decided to integrate a USB-PD sink into my project, such that the RPi I was using to enable the secondary 12V rail will now be itself powered by the USB Vbus, through a buck converter good for 4.5V - 28V input voltage, which will generate 5V for the Pi.In addition, I'll be using a STUSB4500 to negotiate 12V on the Vbus line and drive the PFET load switch.I'm using this schematic as an example:https://raw.githubusercontent.com/oxplot/fpx/master/board/schematics.svgAs I understand the VBUS_EN_SNK line is Hi-Z until the power negotiation is completed successfully and is then pulled low.What is the purpose of the series 100R and 100n cap in this above application?

author: Ian.M
author_rank: Super Contributor
timestamp: January 15, 2024, 03:57:23 pm
content: Quote from: pini.grigio on January 15, 2024, 03:31:52 pmAC negative feedback for slew rate control and thus inrush limiting.