Author Topic: Need some help understanding this NPN BJT and P CHANNEL MOSFET circuit please  (Read 3207 times)

0 Members and 1 Guest are viewing this topic.

Offline doublec4Topic starter

  • Regular Contributor
  • *
  • Posts: 119
  • Country: ca
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)
« Last Edit: January 22, 2021, 10:08:55 pm by doublec4 »
 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
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?
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 
The following users thanked this post: doublec4

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6221
  • Country: de
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.
 
The following users thanked this post: doublec4

Offline bob91343

  • Super Contributor
  • ***
  • Posts: 2675
  • Country: us
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.
 
The following users thanked this post: doublec4

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6221
  • Country: de
erm... it's a 12 V LED module.

 
The following users thanked this post: doublec4

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
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.
 
The following users thanked this post: doublec4

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2320
  • Country: au
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.

^ 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.

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.

Again, the OP has a 12V LED module, which implies that it has the resistors built-in already.

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.

The 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.
 
The following users thanked this post: doublec4

Offline doublec4Topic starter

  • Regular Contributor
  • *
  • Posts: 119
  • Country: ca
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.8kOhm

Next, to calculate the base resistor, I should look at the requirement for the base current...

Base current = (collector current / hfe) * some over drive factor
Ib = (0.001A / 30)*10 = 0.00033A = 0.33mA

And as was suggested the Vbe is ~0.7V...       

Then Rb = 3.3V - Vbe / Ib:

Rb = (3.3V - 0.7V)/0.00033 = 78.8kOhm

So 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!
 
The following users thanked this post: rs20

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 516
  • Country: au
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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13076
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.
« Last Edit: January 23, 2021, 10:58:56 am by Ian.M »
 
The following users thanked this post: MIS42N

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19920
  • Country: gb
  • 0999
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.
Or 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×R1

https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440
« Last Edit: January 23, 2021, 07:40:53 pm by Zero999 »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
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.
Or 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:
VR2 = (V2 - 0.7)/R2×R1

https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440

I 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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13076
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.
« Last Edit: January 23, 2021, 05:21:37 pm by Ian.M »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19920
  • Country: gb
  • 0999
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.
Or 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×R1

https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440

I 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.
With 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 hFE of 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
« Last Edit: January 23, 2021, 07:41:50 pm by Zero999 »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
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.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19920
  • Country: gb
  • 0999
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.
It'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.
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
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.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19920
  • Country: gb
  • 0999
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.
Oh 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.
 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
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.

Don'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?
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
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.
Oh 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.

But 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.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19920
  • Country: gb
  • 0999
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.

Don'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?
That 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 = 330R
R1 = 1k
Tr1 = BC328
Tr2 = BC338

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.
Oh 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.

But 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.
Yes, 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.

 

Offline doublec4Topic starter

  • Regular Contributor
  • *
  • Posts: 119
  • Country: ca
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!
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us

Heck, as it's only 200mA, I'd just use BJTs. Much cheaper than MOSFETs and more resistant to ESD.

R2 = 330R
R1 = 1k
Tr1 = BC328
Tr2 = BC338


Applying 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?

 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19920
  • Country: gb
  • 0999

Heck, as it's only 200mA, I'd just use BJTs. Much cheaper than MOSFETs and more resistant to ESD.

R2 = 330R
R1 = 1k
Tr1 = BC328
Tr2 = BC338


Applying 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?
That 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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13076
You simply need a different formula.   Assuming we are using the simple current controlled approximation for BJT behavior:
   IC=hFE*IB
Q1's B-E junction will clamp Q2 VC approx 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/R1
and:
   IC2=K*(VB2-VBE2)/R2
where 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/R1
Substituting known (or approximated) values:
   IB1≈(3.3V-0.7V)/330R-0.7V/1K≈7.2mA
which means following the 'forced beta' IB>=10% IC rule of thumb, the load current should always be under about 70mA.

« Last Edit: January 24, 2021, 04:52:01 pm by Ian.M »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf