N-Channel MOSFET as a switch - Page 1
Forum section: electronics / beginners

author: Chillance
author_rank: Contributor
timestamp: April 02, 2020, 09:03:10 pm
content: Hi!So, I've extracted part of a bigger schematic in the attached image. 3.3V_OUT is coming from a 3.3V regulator (which is USB 5V turned into 3.3V).My simple understanding has been that Gain being 0, nothing would happen on source. Then Gain > Source, we would essentially have 3.3V_OUT coming through to give us 3.3V at the Source. This is what it also looked like using the falstad simulator.The idea with the switch would be, when OFF, there would be no 3.3V on pin 2, source. And then switch being on, 3.3V_OUT would go through and out as 3.3V on pin 2 in Q302. Same idea with Q301, but would only give 3.3V_USB when V_USB had some voltage. Essentially enable 3.3V_USB ONLY when V_USB is there (that is, only when USB is connected, as 3.3V_OUT could also be from a battery).(The switch for LED is just so one can turn it off to not drain battery when power is on)However, I'm guessing this is flawed and I actually got some hardware with this setup, and noticed that I would still get 3.3V on pin 2 (source) there on Q302 even if there was no voltage on pin 4 from the switch.Could someone be so kind and let me know how to make this work properly? Possibly explain why it doesn't work as I thought it would.I also read somewhere that maybe I should have some pull-down resistor (10k or so) to GND on the gate, which might be what I'm missing here.. ? Or maybe this doesn't work because source isn't connected to GND in any direct way? This is more of a load output, and thus that is why this won't work as I thought? Or I should I switch around source and drain?Thanks!

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: April 02, 2020, 10:26:10 pm
content: You're doing what is call high side switching.in your circuit the n-fet wont turn on properly, as the moment it turns on the source voltage increases to be the same as the gate voltage, which then turns it off. Gate !> SourceYou can do high side with a p channel fet if you pull it down at the gate or with a n channel if you put around 6 volts on the gate.If you download ltspice and run this simulation it might help your understanding.The gates are driven with Sinusoids to demonstrate what happens at different voltage levels rather than the transient effects.

author: Chillance
author_rank: Contributor
timestamp: April 02, 2020, 11:05:57 pm
content: Thanks for your reply. Unfortunately I can't run ltspice in Linux. Maybe you could show me herehttps://www.falstad.com/circuit/circuitjs.htmlby exporting it as text?

author: Chillance
author_rank: Contributor
timestamp: April 02, 2020, 11:17:59 pm
content: Actually, I thew this together:$ 1 0.000005 10.20027730826997 50 5 50f 208 144 256 144 32 1.5 0.02172 160 144 128 144 0 7 3.2 5 0 0 0.5 Gate Voltagew 256 160 256 224 0w 256 128 256 80 1172 256 80 256 48 0 7 3.15 5 0 0 0.5 Drain Voltageg 544 384 544 416 0w 336 288 336 224 1w 336 320 336 384 0172 176 304 128 304 0 7 5 5 0 0 0.5 Gate Voltagef 288 304 336 304 32 1.5 0.02s 160 144 208 144 0 1 falsew 256 224 336 224 0s 176 304 224 304 0 1 falsew 224 304 288 304 0w 336 224 448 224 0162 496 224 560 224 2 default-led 0 1 0 0.01g 624 224 624 256 0w 560 224 624 224 0r 448 224 496 224 0 30r 384 384 432 384 0 30162 432 384 496 384 2 default-led 0 0 1 0.01w 496 384 544 384 0w 384 384 336 384 0o 0 64 0 4099 5 0.025 0 2 0 3Import it there in falstrad.com. Seems to kinda work as I wanted actually..

author: langwadt
author_rank: Super Contributor
timestamp: April 02, 2020, 11:20:43 pm
content: Quote from: Chillance on April 02, 2020, 11:05:57 pmltspice runs just fine in wine

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: April 02, 2020, 11:26:25 pm
content: heres a picture

author: Chillance
author_rank: Contributor
timestamp: April 02, 2020, 11:42:45 pm
content: I tried in wine, but nothing. What version of ltsplice and wine are you running?Edit: Ok, got that old Windows XP one running in wine.

author: Chillance
author_rank: Contributor
timestamp: April 02, 2020, 11:59:44 pm
content: Updated falstrad:$ 1 0.000005 10.20027730826997 50 5 50f 208 144 256 144 32 1.5 0.02172 160 144 128 144 0 7 3.2 5 0 0 0.5 Gate Voltagew 256 160 256 224 0w 256 128 256 80 1172 256 80 256 48 0 7 3.15 5 0 0 0.5 Drain Voltageg 544 384 544 416 0w 336 288 336 224 1w 336 320 336 384 0172 176 304 128 304 0 7 5 5 0 0 0.5 Gate Voltagef 288 304 336 304 32 1.5 0.02s 160 144 208 144 0 1 falsew 256 224 336 224 0s 176 304 224 304 0 0 falsew 224 304 288 304 0w 336 224 448 224 0162 496 224 560 224 2 default-led 0 1 0 0.01g 624 224 624 256 0w 560 224 624 224 0r 448 224 496 224 0 30r 384 384 432 384 0 30162 432 384 496 384 2 default-led 0 0 1 0.01w 496 384 544 384 0w 384 384 336 384 0R 208 176 -64 176 0 1 50 5 0 0 0.159154943092w 208 176 208 144 0o 0 64 0 4099 5 0.025 0 2 0 3o 23 64 0 4099 5 0.00009765625 1 2 23 3o 14 64 0 4099 5 0.025 2 2 14 3So, this seems to work as I was thinking, but I might be missing something in the simulation. I'm just trying to understand this properly.

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 03, 2020, 05:04:36 pm
content: I modified you schematic so that the 3.2V switch can be activated without killing the program$ 1 0.000005 10.20027730826997 50 5 50f 208 144 256 144 32 1.5 0.02172 160 144 128 144 0 7 3.2 5 0 0 0.5 Gate Voltagew 256 160 256 224 0w 256 128 256 80 1172 256 80 256 48 0 7 3.15 5 0 0 0.5 Drain Voltageg 544 384 544 416 0w 336 288 336 224 1w 336 320 336 384 0172 176 304 128 304 0 7 5 5 0 0 0.5 Gate Voltagef 288 304 336 304 32 1.5 0.02s 160 144 208 144 0 1 falsew 256 224 336 224 0s 176 304 224 304 0 0 falsew 224 304 288 304 0w 336 224 448 224 0162 496 224 560 224 2 default-led 0 1 0 0.01g 624 224 624 256 0w 560 224 624 224 0r 448 224 496 224 0 30r 384 384 432 384 0 30162 432 384 496 384 2 default-led 0 0 1 0.01w 496 384 544 384 0w 384 384 336 384 0w 208 176 208 144 0v 208 176 32 224 0 1 40 5 0 0 0.5r 32 224 32 304 0 1g 32 304 32 320 0o 0 64 0 4099 5 0.025 0 2 0 3o 14 64 0 4099 2.5 0.0125 1 2 14 3

author: Chillance
author_rank: Contributor
timestamp: April 03, 2020, 10:13:10 pm
content: Ok, so why does it behave like that in falstad? I mean, this is NOT correct right? It doesn't look like the source pin would get higher voltage and shut it off...

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 03, 2020, 11:52:33 pm
content: Quote from: Chillance on April 03, 2020, 10:13:10 pmSeems to be working right. What, in particular, is bothering you?

author: Chillance
author_rank: Contributor
timestamp: April 04, 2020, 01:27:02 am
content: Yeah, so I'm measuring here on real hardware, and I get these values on one NTR4003NT3G:Gate: 0VDrain: 3.30VSource: 3.09VI was expecting Source to be 0V, since Gate is 0V. Also, not sure why it's 3.09V and not 3.30V, but might not be related.If I put 3.3V on Gate, I still have 3.09V on Source (which I suppose would be expected). Basically Source is always 3.09V for some reason. Maybe because of other MOSFET. Hard to tell at the moment.Thoughts?Now, I don't have an oscilloscope here so who knows if it's swinging, but it looks stable from the simple multimeter I do have here.

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 04, 2020, 01:47:10 pm
content: Quote from: Chillance on April 04, 2020, 01:27:02 amI am showing a simple simulation that indicates what you should expect with the Gate at 0 volts and at 3.3 volts. The model for my transistor sets the threshold voltage at about 0.75 volts which is close to the low end of your transistor range.

author: Zero999
author_rank: Super Contributor
timestamp: April 04, 2020, 02:53:11 pm
content: Perhaps the MOSFET is bad or connected in reverse?

author: Chillance
author_rank: Contributor
timestamp: May 03, 2020, 07:03:43 pm
content: Alright. so I went ahead and made a test PCB board. See attached image for the relevant part. Rest is just USB and regulator stuff.MOSFET N TRENCH 30V 500MA 1.4V @ 250UA 1.5 ? @ 10MA,4V SOT-23(SOT-23-3) ROHShttps://datasheet.lcsc.com/szlcsc/ON-Semicon-ON-NTR4003NT3G_C146737.pdfMOSFET P TRENCH 20V 3.6A 1V @ 250UA 35 M? @ 4A,4.5V SOT-23(SOT-23-3) ROHShttps://datasheet.lcsc.com/szlcsc/Diodes-Incorporated-DMP2035U-7_C110499.pdfNow, I tested the N-channel one.Drain: 3.3VGate: 0.0VSource: 0.0VAs expected.Drain: 3.3VGate: 3.3VSource: 2.35VThis one I don't understand. I thought I would have 3.3V in source here. What am I missing here? Why such a drop in voltage?Drain: 3.3VGate: 4.83V (coming from USB through a schottky diode so that is why the voltage has dropped a bit)Source: 3.3VNow Source goes to 3.3V. So, that is nice.For the P channel mosfet, applying voltage on gate still seems to get voltage on source. For example:Drain: 3.3VGate: 3.3VSource: 2.98VDrain: 3.3VGate: 4.83VSource: 2.86VI would expect source to be 0V. What am I missing here?And for good measure:Drain: 3.3VGate: 0.0VSource: 3.3VThanks!

author: Wimberleytech
author_rank: Super Contributor
timestamp: May 03, 2020, 07:54:14 pm
content: Quote from: Chillance on May 03, 2020, 07:03:43 pmNo that IS what you should expect. The source cannot rise above VG-VT when the device is operating in the saturation region. So if VG=3.3V and VT (at ~200uA) of ~1 volt (within the spec) then you would expect ~2.3V on the source.QuoteIn this mode the device is operating in non-saturation (aka linear). If the gate goes above the drain by a VT, then the channel is fully inverted and the source can pull up to the potential at the drain.QuoteSame concepts should apply as noted above for the N channel transistor. However, you are not applying the correct voltages for a pch device. The gate should be LESS than the source to turn it on. It is not clear to me what you are driving and what is being driven. I hate schematics with ground on top and positive power on the bottom...btw.Quote

author: Chillance
author_rank: Contributor
timestamp: May 03, 2020, 09:04:44 pm
content: QuoteAh! Thanks for replying! Glad to have this confirmed. Is this the Diode Forward Voltage VDS mentioned in the sheet perhaps? Is this normal for a MOSFET then as my impression has been that Source would match Drain voltage when Drain and Gate matches and source is 0V. I'm just trying to understand what to look for. Maybe some other component would match Drain and Source when Gate = Drain? I mean, if one want to use the mosfet as a switch, to have 3.3V on Source coming from Drain, Gate must be more than 3.3V which wouldn't' work if you didn't have 5V then...QuoteAlright!QuoteAha, so, how do I do negative Gate, since Source is essentially going to dive other things and go to GND (0V).Regarding schematics, I try to put power upwards and GND downwards.Thanks!

author: Wimberleytech
author_rank: Super Contributor
timestamp: May 03, 2020, 09:48:23 pm
content: If you want to switch a node to 3.3V, use a pch transistor. Connect the source to 3.3V and the drain to the node that you want to control. When you drive the gate to ground, the drain will be driven to 3.3V. When you drive the gate to 3.3V, the drain will float to whatever the load demands (to ground if the load is a resistor to ground).If you want to switch a node to ground, use an nch transistor. Connect the source to ground and the drain to the node you want to control..When you drive the gate to 3.3V, the drain will be driven to ground. When you drive the gate to ground, the drain will float to whatever the load demands (to 3.3V if the load is a resistor to 3.3V).

author: Chillance
author_rank: Contributor
timestamp: May 04, 2020, 12:25:49 am
content: Aha.Ok, so I thought one could use the nch one for "letting Drain through to Source" when Gate is on. So, essentially Gate would control if Source had voltage or not, and thus you would have 3.3V at Drain, and connect Source to the rest of your components. When Gate had 3.3V, Drain would be 3.3V and so would Source and then the components (IC's etc) would run and do their thing. If Gate was 0V, Source would also be 0V and essentially switch the components off. I figured components would eventually go to ground too, so that could work. Now seeing voltage at Source being 2.35V, that is not 3.3V that would have been better. And this is not the approach then from what I understand now.Regarding pch, take a look at the attached schematic. Notice how the idea there is that as the LiPo battery is connected, it would hinder the Cell battery to be used. When USB is connected, it would block both LiPo and Cell battery. Pretty nifty actually. PWR is then going to a regulator to get a stable 3.3V. How is this related to what you said since you said drain should be connected to what I want to control, where here the source is. I guess since Gate is also going to Source through a diode, this is different. But what about a floating Gate?I'm trying to wrap my head around all of this.Thanks!

author: Wimberleytech
author_rank: Super Contributor
timestamp: May 04, 2020, 01:54:04 am
content: Regardless of the potential on either gate, you have a continuous path for current to flow from the cell battery to PWR via the body diodes of the two MOSFETS.Your solution will not work if I understand your goal.You need to reset and specify this problem in detail.You have two batteries.Under what conditions do you want one battery to provide power and the other not.As I understand, you want USB to determine whether power is delivered from either battery...correct?

author: Chillance
author_rank: Contributor
timestamp: May 04, 2020, 02:07:51 am
content: QuoteI want USB to "take over" and not use either battery when USB is in use, yes. And LiPo doing the same over the CELL battery. Now I realize that the voltage drop from the diode for the LiPo battery might not be good though as it will mess with the whole thing. Also, there is voltage drop through the mosfet too, so even using a CELL battery will be problematic then I guess, being at 3.3V and then drop from there...

author: jackthomson43
author_rank: Contributor
timestamp: May 04, 2020, 04:58:34 am
content: Quote from: Chillance on May 04, 2020, 02:07:51 amYou can design a simple DLD circuit which should check the USB voltage. If there's voltage then cut off the LIPO battery. That's how you can useMOSFET as a switch.

author: Chillance
author_rank: Contributor
timestamp: May 04, 2020, 07:38:02 am
content: QuoteThat is what I thought I was doing using the MOSFETS here basically. But maybe I should just use some logic gate chip instead?

author: Chillance
author_rank: Contributor
timestamp: May 04, 2020, 09:05:46 am
content: So, I managed to get the proper setup using XOR and OR gates. However, isn't this a chicken and egg problem... I mean, the point of this is to select which one to draw power from (CELL, LiPo, USB), but if I use an IC for this, that one needs power to enable the XOR and OR gates... So, how would I be able to power the IC to select which one to take power from?I guess I can hook all of them up to VCC of the chip through a diode. But then there will be a voltage drop.Edit: Maybe I just go for a power multiplexer IC. Might be a bit more expensive though, which is why doing it some other would be fun for learning and cost wise. But still.

author: Wimberleytech
author_rank: Super Contributor
timestamp: May 04, 2020, 07:48:31 pm
content: Quote from: Chillance on May 04, 2020, 09:05:46 amSomebody posted an ideal diode circuit the other day. I have implemented it here three times for each of your inputs. Tested by driving with sine waves delayed from one another.Maybe this could work for you.

author: Chillance
author_rank: Contributor
timestamp: May 04, 2020, 08:40:21 pm
content: Wow, ok. Can you explain it? The idea with mine is the following:Cell battery lowest priority. When connected, 3.3V is applied to the circuit.As soon as LiPo or USB is connected, those take over and "disconnect" drainage from the Cell battery.Next is LiPo. Take precedence over the cell battery, but when USB is connected neither Cell or Lipo is used. That is the idea here. The ideal diode schematics... I'm not sure that works like that.Thanks!

author: Chillance
author_rank: Contributor
timestamp: May 04, 2020, 09:01:27 pm
content: Quote from: Wimberleytech on May 03, 2020, 09:48:23 pmAnd what if I want to switch a node to 3.3V when Gate goes to 5V? 0V when Gate is 0V. Essentially it will enable 3.3V to some part of the circuit (enable pin in this case). I guess this is how the n-channel works... with 3.3V on drain, 5V on gate and source then connected to the enable pin. This is why I was a bit surprised/confused when gate was 3.3V and source 2.35 V. But with 5V on the gate, I get 3.3 on source as wanted...

author: Wimberleytech
author_rank: Super Contributor
timestamp: May 04, 2020, 09:04:26 pm
content: Quote from: Chillance on May 04, 2020, 09:01:27 pmCorrect, the circuit I posted does not work like that. Highest voltage wins in my circuit. This is your first clear explanation of what you are trying to doLet me ponderAnd what if I want to switch a node to 3.3V when Gate goes to 5V? 0V when Gate is 0V. Essentially it will enable 3.3V to some part of the circuit (enable pin in this case). I guess this is how the n-channel works... with 3.3V on drain, 5V on gate and source then connected to the enable pin. This is why I was a bit surprised/confused when gate was 3.3V and source 2.35 V. But with 5V on the gate, I get 3.3 on source as wanted...

author: Chillance
author_rank: Contributor
timestamp: May 05, 2020, 01:06:06 am
content: QuoteYeah, sorry about that. I do have a few scenarios I would like to understand using mosfets, but I think this "3 different powers" one is most important right now.Not sure how involved the cell battery can be, as it's a 2032 one, at 3.3V already. Meaning, that can't go through diodes and other things to drop it's voltage. So it would need to be part of some smart circuit so it would be enabled/disabled properly like I explained earlier.