EEVblog Electronics Community Forum
Electronics => Beginners => Topic started by: doublec4 on January 22, 2021, 10:02:44 pm
-
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)
-
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?
-
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.
-
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.
-
erm... it's a 12 V LED module.
-
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.
-
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.
-
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!
-
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.
-
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.
-
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/?action=dlattach;attach=1156088;image)
https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440 (https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440)
-
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/?action=dlattach;attach=1156088;image)
https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440 (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.
-
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.
-
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/?action=dlattach;attach=1156088;image)
https://www.eevblog.com/forum/beginners/3-3v-from-pir-amplify/msg3426440/#msg3426440 (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
-
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.
-
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.
(https://www.eevblog.com/forum/beginners/need-some-help-understanding-this-npn-bjt-and-p-channel-mosfet-circuit-please/?action=dlattach;attach=1156404;image)
-
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.
-
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.
-
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?
-
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.
-
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.
(https://www.eevblog.com/forum/beginners/control-led-from-teensy-uc/?action=dlattach;attach=573140;image)
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.
-
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!
-
Heck, as it's only 200mA, I'd just use BJTs. Much cheaper than MOSFETs and more resistant to ESD.
(https://www.eevblog.com/forum/beginners/control-led-from-teensy-uc/?action=dlattach;attach=573140;image)
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?
-
Heck, as it's only 200mA, I'd just use BJTs. Much cheaper than MOSFETs and more resistant to ESD.
(https://www.eevblog.com/forum/beginners/control-led-from-teensy-uc/?action=dlattach;attach=573140;image)
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.
-
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.
-
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.
Ok, 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.
-
You simply need a different formula.
Yes, thanks very much. It all makes sense now.
-
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.
I don't like driving BJTs with IB >10% IC because 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 hFE of 60, when VC = -1V, so it should be fine up to a few hundred mA, especially given that hFE has 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 IB to 30mA.
https://www.mouser.com/datasheet/2/149/BC337-193546.pdf (https://www.mouser.com/datasheet/2/149/BC337-193546.pdf)
-
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.PDF (https://www.onsemi.com/pub/Collateral/BC337-D.PDF)
and 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.
-
I'm out of bipolars and FETs. How about a circuit using a 12AX7? >:D
-
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.PDF (https://www.onsemi.com/pub/Collateral/BC337-D.PDF)
and 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.
I'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.