Need some help understanding this NPN BJT and P CHANNEL MOSFET circuit please - Page 1
Forum section: electronics / beginners

author: doublec4
author_rank: Regular Contributor
timestamp: January 22, 2021, 10:02:44 pm
content: Hi all,I would like to high side switch a 12V LED module (low side switching not possible in this case) using a 3.3V signal from an arduino.I have seen some circuits online doing something similar with different voltages so I've copied the general layout and put in some temporary resistor values (see attachment). I would like to know how this circuit works in greater detail (ie. resultant currents / selection of resistor values).My general understanding is that when the GPIO pin is low, Q1 will be "off" and Q2 gate will see 12V and therefore it will also be "off". No current will flow to my RED LED module. When 3.3V GPIO pin is high, Q1 will pull the gate of Q2 low and current can now flow to the red LED load. When the device is not powered and the GPIO pins are floating the pull down resistor R10 will ensure that Q1 base has a GND reference. I hope all of this is correct.Now for the parts that are a bit muddy to me. How do I begin analyzing this circuit to determine the resistor values required? Where do I start?I figure with the P channel MOSFET I need something with a Vgs ON > -12V ... I've found quite a few with -10V so that is not a problem. With Vgs = -12V they P channel mosfet should be fully on and that will be sufficient for my red LED module which is only ~0.3A @ 12V.My (limited) understanding of the MOSFET gate is that it will only consume as much current as it needs. MOSFETS are voltage driven devices and therefore the gate current shouldn't be critical especially since fast switching speed for the LED is not required. It is just simply turning the LED on and holding it on.So that brings me to my question about the resistor values and what they are effectively doing... R8 (4.7kOhm) is limiting current to the base of the 2N3904. With the pull down resistor of 56kOhm, there is a voltage divider created and the base of the 2n3904 should be seeing about 3.1V. But what is the current to the base?Then there is R9 (56kOhm)... is this limiting the current going through the collector/emitter as well as the gate of Q2? Should my strategy be to fully saturate Q1 and then let R9 limit the current going through Q1 such that I don't overheat it or unnecessarily waste power?Any help would be appreciated!(EDIT: Also forgot to mention... for this layout I'm trying to limit myself to DIP packages for ease of soldering on a prototype board, and I'm also trying to limit the space. So I would prefer not to use N type MOSFET in place of the NPN bjt as they are usually larger TO220 vs TO92.. plus for my own knowledge I would like to understand how to build this circuit with the BJT rather than the N type MOSFET)

author: gnuarm
author_rank: Super Contributor
timestamp: January 22, 2021, 10:31:14 pm
content: The p-FET gate must rise close to the 12V rail to turn off. The gate is pulled lower to turn on, exactly how much I can't say as no part number is given. But anything 4V or more will turn on most FETs. So 12V - 4V is 8V. Q1 will do that easily.The currents and voltages should be easy to calculate. Consider Q1 to short collector and emitter when turned on. Not much current is required because the gate of Q2 has a very high resistance.Emitter to base of Q1 when on is about 0.7V, so figure the current in R10 with that voltage. The current required into the base of Q1 is the current in the collector divided by the beta... figure at least 50. So you need very little current into the base. R8 will supply that current easily plus the current into R10. R10 is only there to turn the transistor off when there is no input.Q1 could be an n-FET with similar operation except that there is no real current into the gate.Is that clear enough? Did I leave anything out?

author: Benta
author_rank: Super Contributor
timestamp: January 22, 2021, 10:38:54 pm
content: Your circuit is functionally fine. Turning a LED on or off is not time-critical in any way. R9 seems a bit high (I'd go for 10 kohms), but that's more a question of outside noise possibly disturbing the MOSFET gate a bit.Go for it.

author: bob91343
author_rank: Super Contributor
timestamp: January 22, 2021, 10:39:47 pm
content: You know what the base voltage of the NPN is - about 0.7 Volts. With 3.3 V input, that leaves about 2.6V across the 56k resistor, or 45 microamperes or so, if my mental math is correct. With such a high value collector resistor, the transistor will be saturated.You show no current limiting for the load LED so it might be destroyed, depending on the capabilities of the power supply and FET. You could use an NPN transistor instead but still need current limiting.

author: Benta
author_rank: Super Contributor
timestamp: January 22, 2021, 10:41:49 pm
content: erm... it's a 12 V LEDmodule.

author: Peabody
author_rank: Super Contributor
timestamp: January 22, 2021, 11:29:13 pm
content: Before addressing your questions about the resistors, and before I forget, you should move the base pulldown resistor over to the left of the base series resistor. That will eliminate the divider. Also, remember that while mosfet gates are very high impedance voltage-sensitive terminals, a bipolar transistor is current-based, and current would actually have to flow through the base to turn it on. So it's less likely you will actually need a pulldown resistor. It's not impossible for a strong noise source to trigger a bipolar transistor,but if the base is connected to the GPIO pin, it's unlikely that will happen, even if the pin is floating. Finally, be sure you pick a mosfet with a maximum GS voltage large enough for your 12V supply. Ideally, you would want one with a 20V maximum GS voltage.If you are not switching the LEDs at high speed, the currents involved here can be tiny. In the end you pick resistors that make the circuit immune to noise - so the LEDs don't flutter when you come near a mains fixture, and such - even though that produces more current than is absolutely necessary.So you've got about 0.2mA flowing through R9 when the power is on (12 / 56000). No current flows into or out of the gate except what's needed to charge or discharge the gate capacitance, which you can ignore for this purpose. So if the 2N30904 has a DC gain of (conservatively) 30 at very low currents, then the base current only needs to be about 7uA. A 330K resistor would give you 8uA of base current ((3.3 - .6) / 330000), so your 4.7K provides far more current than is needed. But as I said, you often have to reduce the resistor values to achieve noise immunity. I think I would try 47K for R8. With R10 moved over to the left, that would make the effective pulldown resistance 103K, which should be ok.R9 does not limit the current through the mosfet if the gate is grounded by Q1. What's not shown in your drawing is the resistor you will insert in the LED line, which will limit the current through the LED.

author: rs20
author_rank: Super Contributor
timestamp: January 22, 2021, 11:43:11 pm
content: Quote from: Peabody on January 22, 2021, 11:29:13 pm^ This. If you were to build this circuit from random parts in your parts bin, I suspect this would be the one thing that would trip you up.Quote from: Peabody on January 22, 2021, 11:29:13 pmAgain, the OP has a 12V LEDmodule, which implies that it has the resistors built-in already.Quote from: Benta on January 22, 2021, 10:38:54 pmThe idea of outside noise, fighting against a 56k resistor and the gate capacitance of a power MOSFET, could swing the Vgs all the way from 0V to Vgs(on) -- seems implausible. I think having R9 as 56k, or even 100k, is fine. Happy to be proven wrong though.

author: doublec4
author_rank: Regular Contributor
timestamp: January 23, 2021, 02:37:07 am
content: Thank you all for talking this through with me. It does make more sense to me. At first I was a little confused by the approach but it seems that the best place to start is at the P channel, find which one will work with the max Vgs and a low Rds ON for my load, making sure I can fully turn it on.Then, knowing that the gate current requirement is very low as it is a MOSFET, I can arbitrarily use 1mA (overkill, but a nice round number) for my NPN collector current, along with the Vce to calculate R9... so (12V - 0.2V)/0.001A = 11.8kOhmNext, to calculate the base resistor, I should look at the requirement for the base current...Base current = (collector current / hfe) * some over drive factorIb = (0.001A / 30)*10 = 0.00033A = 0.33mAAnd as was suggested the Vbe is ~0.7V...Then Rb = 3.3V - Vbe / Ib:Rb = (3.3V - 0.7V)/0.00033 = 78.8kOhmSo basically any base resistor value lower than 78.8kOhm should be much more than enough to fully saturate the BJT, and any collector resistor less than 11.8K is also overkill since the MOSFET gate doesn't really require a large current.As others have suggested, my LED is a module and has built in resistors so no current limiting to the LED is required on my schematic.Thanks guys!

author: MIS42N
author_rank: Frequent Contributor
timestamp: January 23, 2021, 10:34:55 am
content: I'm looking at the circuit and wondering if R10 is needed. The GPIO when used as an output is active low so should turn off Q1 through R8. I'm assuming the active low state is using a FET as the sink, which basically is a resistor, possibly in series with a current limiting resistor. The ability to sink 10mA at 0.5V would indicate quite a low value, a couple of hundred ohm. This would override any contribution by R10. R10 would be of value if the GPIO was open collector, but I don't think it is.

author: Ian.M
author_rank: Super Contributor
timestamp: January 23, 2021, 10:56:04 am
content: Most MCU GPIOs go tri-state during reset (including POR/BOR), and remain so till the code configures them as an output. The gate pulldown R10 stops the gate floating up due to leakage currents before the GPIO gets configured, and possibly burning out the MOSFET if Vgs gets high enough for it to enter its linear region. Do *NOT* omit it if the load can pass enough current when the MOSFET isn't fully on to exceed the MOSFET's dissipation limit at the highest expected ambient temperature, unless you can guarantee the MCU will never be held in reset and can guarantee the maximum interval from POR or other reset event to the GPIO getting configured.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 11:10:29 am
content: Quote from: Peabody on January 22, 2021, 11:29:13 pmOr the BJT circuit could be reconfigured, so that the gate-source voltage is much lower. The voltage across R1 is roughly equal to the following formula:VR1= (V2 - 0.7)/R2×R1https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440

author: Peabody
author_rank: Super Contributor
timestamp: January 23, 2021, 02:43:58 pm
content: Quote from: Zero999 on January 23, 2021, 11:10:29 amI don't understand your formula. It seems to me if V2 is a relatively low impedance 3.3V source, then the voltage across R1 is going to be 2.6V, period, and cannot be higher than that no matter what R1 and R2 are. If that's right, the GS voltage would be reduced from 12V to 9.4V,, which might allow for the use of a 12V VGSmax part, but a 10V part would still be a little too close for comfort.

author: Ian.M
author_rank: Super Contributor
timestamp: January 23, 2021, 03:24:16 pm
content: Nope. There will be 3.3V-Vbe across R2, which sets the current through R1, making Q1 act as a current sink, and thus sets the voltage across R1, proportional to the resistance ratio.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 05:18:28 pm
content: Quote from: Peabody on January 23, 2021, 02:43:58 pmWith a 3.3V source, the voltage across R2 will be 2.6V, so the current will be 2.6mA, but the current through R1 is nearly equal to R2, assuming the hFEof Q1 is high enough to make the base current negligible, so the voltage across it will be 2.6m×2.2k = 5.7V.Hence:VR1= (V2 - 0.7)/R2×R1 = (3.3 - 0.7)/1k×2.2k = 2.6/1×2.2 = 5.7V

author: Peabody
author_rank: Super Contributor
timestamp: January 23, 2021, 05:47:21 pm
content: I got the resistor labels wrong. I meant the voltage across *R2* is 2.6V. But what I'm having trouble with is the 3.7V that must be dropped across CE, and how/why that happens.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 06:19:57 pm
content: Quote from: Peabody on January 23, 2021, 05:47:21 pmIt's because the transistor never saturates. Ignore R1 for now. Consider an emitter follower. The current taken from V1 depends on V2, not V1, so long as V1 is a bit higher than V2 + 0.7V. As Ian said, the transistor behaves as a constant current sink, with the current dependant on the emitter resistor and base voltage.

author: Peabody
author_rank: Super Contributor
timestamp: January 23, 2021, 07:30:57 pm
content: Ok, I understand. I've just always thought of constant current applying to any upper rail *voltage*, and hadn't thought of it as applying to a fixed voltage but different series resistance. So the transistor is in fact only partially on, and is therefore acting as a resistor.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 07:44:27 pm
content: Quote from: Peabody on January 23, 2021, 07:30:57 pmOh I got the resistors mixed up in the formula, which probably didn't help, so I've corrected it.Yes, it's a classic common emitter amplifier. If we were dealing with AC, the gain would simply equal to R1/R2, since the 0.7V is a DC component, which would be removed by the coupling capacitor.

author: gnuarm
author_rank: Super Contributor
timestamp: January 23, 2021, 08:05:11 pm
content: Quote from: Peabody on January 23, 2021, 05:47:21 pmDon't worry about the CE voltage, the transistor will adjust that due to the gain, not entirely unlike an op amp circuit. What is important is that the gain makes the current in R1 and R2 nearly equal. So Vr1 ~= Vr2*R1/R2. With 2.6V on R2 that gives 5.2V on R1, enough to turn on the FET fully... and not so much as to over voltage the gate.In essence this circuit is a constant current drive to the R1 load resistor with the current set by R2 and Vout of the MCU output. With the low value of the R2 the MCU output is unlikely to leak enough current to turn on the FET enough to cause a problem with over heating.Personally, I don't like this circuit as much as using an n-FET in place of the NPN. Here is an example using three resistors. R2 is optional really and can instead be a pulldown to turn off M2 when the MCU is in reset. While this circuit uses one more resistor, it also uses a lot less current although that is likely not important with the large load current. It also does not depend in any way on the output voltage from the MCU to control the Vgs on the p-FET. What if the MCU is changed to a 5 volt device? Now the Vgs will be over 8V, the limit for many lower voltage FETs.While every part has its purpose, I tend to not use bipolars much anymore. A 2N7002 is almost certainly going to be in the BOM, so why add another line item without need?

author: Peabody
author_rank: Super Contributor
timestamp: January 23, 2021, 10:20:06 pm
content: Quote from: Zero999 on January 23, 2021, 07:44:27 pmBut just to make sure I understand the DC version - if the current is 2.6mA, then if the upper resistor is changed to 3.615384615K, the NPN would then be in full saturation, and would have no equivalent resistance (assuming it's perfect,with infinite gain, etc.). And at that point the mosfet gate voltage would be 2.6V. At any higher resistor value, the gate would still be 2.6V. Is that right?Also, is there any reason these resistor values couldn't be increased by an order of magnitude or more? It seems the math would still work.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 10:53:48 pm
content: Quote from: gnuarm on January 23, 2021, 08:05:11 pmThat will work. The MOSFET has the advantage of drawing less current from the MCU, but it's a little more expensive, than a BJT. I'd say the gate-source voltage being dependant on V1 is more problematic, than the MCU's power supply voltage, which will be very well regulated. If the device is switched for a 5V one, simply change the emitter resistor value: no big deal. What if V1 could vary between 18V and 30V? R1 could be replaced with a zener diode I suppose, but I a resistor is much cheaper and easier.Heck, as it's only 200mA, I'd just use BJTs. Much cheaper than MOSFETs and more resistant to ESD.R2 = 330RR1 = 1kTr1 = BC328Tr2 = BC338Quote from: Peabody on January 23, 2021, 10:20:06 pmYes, as R1's value is increased to the point, when the current through it will no longer be constant, Q1 will be biased into the saturation region.

author: doublec4
author_rank: Regular Contributor
timestamp: January 24, 2021, 05:29:59 am
content: Looks like a lot more was added to the discussion since I last checked in. You guys are like wizards, I have a lot to learn!

author: Peabody
author_rank: Super Contributor
timestamp: January 24, 2021, 03:21:56 pm
content: Quote from: Zero999 on January 23, 2021, 10:53:48 pmApplying the formula, I get the voltage across R1 as 7.88V. But the BC328 has a maximum E-B voltage of -5V. So shouldn't R2 be 560R, or have I done the math wrong?

author: Zero999
author_rank: Super Contributor
timestamp: January 24, 2021, 04:21:43 pm
content: Quote from: Peabody on January 24, 2021, 03:21:56 pmThat specification is for the reverse base-emitter voltage. In the circuit above, the base-emitter junction is forward biased, so the voltage is clipped to around 0.7V. The circuit will work without R1, which is there to turn Tr1 off more quickly and ensure it doesn't turn on a little, due to the leakage through Tr2.

author: Ian.M
author_rank: Super Contributor
timestamp: January 24, 2021, 04:44:59 pm
content: You simply need a different formula. Assuming we are using the simple current controlled approximation for BJT behavior:IC=hFE*IBQ1's B-E junction will clamp Q2 VCapprox 0.7V below the +V rail, (so it only swings 0.7V between on and off) and the quantity we will be interested in will be Q1's base current IB1.R1 'steals' a little of Q1's base current IB1, so:IB1=IC2-VBE1/R1and:IC2=K*(VB2-VBE2)/R2where K=hFE/(hFE+1) as the emitter also carries the base current, so K is near enough unity for high gain transistors.==>IB1≈(VB2-VBE2)/R2-VBE1/R1Substituting known (or approximated) values:IB1≈(3.3V-0.7V)/330R-0.7V/1K≈7.2mAwhich means following the 'forced beta' IB>=10% ICrule of thumb, the load current should always be under about 70mA.

author: Peabody
author_rank: Super Contributor
timestamp: January 24, 2021, 05:08:25 pm
content: Quote from: Zero999 on January 24, 2021, 04:21:43 pmOk, so the formula doesn't apply here at all because of the added current path through the PNP base that wasn't there in the mosfet circuit.

author: Peabody
author_rank: Super Contributor
timestamp: January 24, 2021, 05:21:46 pm
content: Quote from: Ian.M on January 24, 2021, 04:44:59 pmYes, thanks very much. It all makes sense now.

author: Zero999
author_rank: Super Contributor
timestamp: January 24, 2021, 06:22:54 pm
content: Quote from: Ian.M on January 24, 2021, 04:44:59 pmI don't like driving BJTs with IB>10% ICbecause it wastes a lot of power driving the base, especially when the drive voltage is high. I study the data sheet and choose a more appropriate drive current accordingly.It'll be fine for a much higher current than that, unless it's very cold, or you really want to drive it hard into saturation which is normally unnecessary. The BC327 has a minimum hFEof 60, when VC= -1V, so it should be fine up to a few hundred mA, especially given that hFEhas a positive temperature coefficient, meaning it'll improve as it warms up. For example, if IC= 300mA, IB= 7.2mA, that's a forced beta of just over 40, so VC<1V and I doubt it will drop much by increasing IBto 30mA.https://www.mouser.com/datasheet/2/149/BC337-193546.pdf

author: Ian.M
author_rank: Super Contributor
timestamp: January 24, 2021, 07:39:32 pm
content: I agree that if one needs to save power, one needs to get one's thumb out of one's @rse, not to use it as a rule, but to properly study the datasheet limits and curves. Unfortunately your link to the Fairchild datasheet doesn't have any graphs, so here's the OnSemi one:https://www.onsemi.com/pub/Collateral/BC337-D.PDFand yep, fig.4 shows its good for 300mA with as little as 5mA Ib.However nowadays, if you need to push past that rule of thumb, you should probably consider a MOSFET.

author: gnuarm
author_rank: Super Contributor
timestamp: February 03, 2021, 12:35:50 pm
content: I'm out of bipolars and FETs. How about a circuit using a 12AX7?

author: Zero999
author_rank: Super Contributor
timestamp: February 04, 2021, 09:40:55 am
content: Quote from: Ian.M on January 24, 2021, 07:39:32 pmI've never liked that rule of thumb. It tends to underdrive, large high voltage transistors, which often need more base current and needlessly wastes power with small transistors.