Understanding BJT Behavior - Page 1
Forum section: electronics / beginners

author: meshtron
author_rank: Regular Contributor
timestamp: September 03, 2023, 04:53:28 pm
content: I have been testing (and troubleshooting!) my first-ever PCB design recently, and was surprised to find out a feature I was unsure about works exactly as expected even though (due to my omission on BOM), a critical resistor was left off the board. I believe I understand what's happening, but don't want to assume that as my intuition for these things seems to be approximately 150 degrees out of phase.The transistor in question is aBC817-16, shown as Q1 in the attached schematic. The part that was left off is R2 in the same schematic, so the Collector is in fact open on my board. And yet, when I pull the base high (DCLK_CHRG), C2 does indeed charge as was intended. I can't measure how fast C2 is getting charged, but it appears to be happening about like I'd hoped.So what must be happening is there is enough current moving between base and emitter that the cap gets quickly charged even with the open collector. The MCU connected to the base is an ATTiny48 which shows 40mA as max GPIO pin current. But, I can't tell from the BJT datasheet how much current would actually flow from Base to Emitter with open collector and a 5V (diminishing) delta V.I was honestly shocked this whole little circuit performed as I hoped (voltage on DCLK_SNS decays after about 2.5 seconds) and, other than including R2, no changes planned for next round of boards. But, I don't like not understanding WHY it's working even with parts left out.

author: ataradov
author_rank: Super Contributor
timestamp: September 03, 2023, 05:02:41 pm
content: BE junction acts as a diode. The voltage on the emitter would not go past the base voltage minus diode drop, but in a first approximation with a full swing base voltage, it would look similar to a fully connected transistor .

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 03, 2023, 05:04:01 pm
content: Quote from: meshtron on September 03, 2023, 04:53:28 pmThat means you have a phase margin of 30 degrees, so you are probably still within acceptable stability margins.Quote from: meshtron on September 03, 2023, 04:53:28 pmIf you leave the collector of a BJT open, then the Base-emitter junction just acts as any normal signal diode. (Except that the reverse breakdown is pretty low at around 6V usually)If you leave out R2 and make it a short circuit, then you have an "emitter follower" which is also a valid and often used application of a BJT.

author: meshtron
author_rank: Regular Contributor
timestamp: September 03, 2023, 05:27:59 pm
content: Awesome, thanks guys. I will do more research on "emitter follower" - shocked that one of many errors on this board caused something to accidentally work!Looking at a calculator, looks like 40mA would charge C2 in about 0.02 seconds which is way more than fast enough for my purposes. Maybe I could free up some room and dollars by just eliminating Q1 and R2 all together and letting the MCU pin charge the cap? It gets charged one time per on/off cycle so would happen relatively often, but not continuously.

author: ataradov
author_rank: Super Contributor
timestamp: September 03, 2023, 05:35:23 pm
content: 40 mA may be a bit much for an MCU pin. Check with the MCU datasheet.But if you can limit the current to the MCU pin capabilities, then sure, it would work. Set the pin high for charging and set it to the input otherwise.

author: meshtron
author_rank: Regular Contributor
timestamp: September 03, 2023, 05:39:15 pm
content: Datasheet says 40mA max for the GPIO, but maybe I add a 220-ohm resistor too (still getting rid of the BJT) and limit it to less. That feels a bit safer. I don't know how (or if) MCUs limit current draw internally, or if they're counting on me to make sure nothing tries to draw more than that externally.

author: ataradov
author_rank: Super Contributor
timestamp: September 03, 2023, 05:42:05 pm
content: It is not limited internally at all (outside of the Rds_on of the output transistors). It is on you to limit the current, so you will have to use the resistor.

author: meshtron
author_rank: Regular Contributor
timestamp: September 03, 2023, 05:48:32 pm
content: Understood, thank you Alex!

author: magic
author_rank: Super Contributor
timestamp: September 03, 2023, 07:30:43 pm
content: Charging with resistor is the simplest option if you can make it fast enough without overstressing the GPIO.You original circuit had another problem. Initially, the emitter is at 0V and the base at 0.7V or so. During this time only RDS(on) of the MCU pin driver limits base current, which may exceed the MCU's maximum rating. A resistor before the base could limit this further to a few mA or whatever is the MCU's specified limit.

author: meshtron
author_rank: Regular Contributor
timestamp: September 03, 2023, 09:06:35 pm
content: Wow yeah good call on that too! I'm lucky the MCU is standing up to it so far, but I will simplify and correct on my round 2 of prototypes.

author: MrAl
author_rank: Super Contributor
timestamp: September 05, 2023, 05:22:32 am
content: Hi,There is one more thing to consider with respect to the MCU pins.The MCU will have a max current spec for each pin but will also have a max current spec for all of the pins. It could be something like 100ma or 200ma for the whole package. That means that if you have a 100ma limit and you have 10 pins putting out 10ma all at the same time, you have reached the max for that chip even though each pin is rated for 40ma.The transistor circuit is often called an "emitter follower" or "voltage follower". That means that the emitter voltage follows the base voltage to a certain degree of accuracy. There is usually about a 0.7v drop though. That means if you apply 5v to the base you will get about 4.3v or so at the emitter, after the cap fully charges.Since the base emitter diode is of fairly low impedance, that means that the MCU pin pretty much drives the capacitor almost directly. When the cap is discharged, that means the MCU pin would be putting out the maximum that it could given the internal structure of the output pin driver. It will most likely be higher than the max for that one pin, so a limiting resistor would be a good idea as others have pointed out. Since the voltage difference during that time would be roughly 5v, a 470 Ohm resistor in series with the base would limit the current to around 10ma. The time to charge the capacitor then, assuming the collector was tied to the +5v rail, would be the base resistor divided by the beta (maybe 50) times the cap value times 5, as an approximation, which is the time to charge to about 99 percent of max.Now if you remove the transistor, the MCU pin charges the cap through a 470 Ohm resistor. The time to charge then is approximately the base resistor value times the cap value times 5. Since without the transistor we lose that divide by 50, that means with the transistor the cap charges about 50 times faster than without the transistor. However, either way may work for the application. It's only if you need faster charging times that you need the transistor. Note that if the beta of the transistor is 100, then it would charge 100 times faster than without a transistor, but if it was only 20 then it would only charge 20 times faster than without the transistor. In practice it will be a little slower though because the transistor apparent beta actually decreases gradually as the cap charges.In effect we are talking about a charge time of 0.075 seconds with no transistor, and about 0.004 seconds with a transistor that has a beta of about 20. With a beta of 50, we are talking about 0.002 seconds approximately. If 0.075 seconds is acceptable, then you don't need a transistor but you always need that resistor of about 470 Ohms.Also interesting is if you can get away with a slight decrease in output voltage, you can use a 1k resistor, and that will take about 0.15 seconds to charge, but will strain the MCU pin even less. The output voltage will not get up to max though because of that 8k resistor load.One more little detail. You have to watch out for the max output voltage of the MCU pin because it may not reach up to exactly 5v, it may only go up to 4.5v or something.So that's pretty much the long and the short of it.

author: meshtron
author_rank: Regular Contributor
timestamp: September 05, 2023, 02:31:56 pm
content: Thank you @MrAl! That really clears it up and all makes sense to me. For my use case, anything faster than about 0.5 seconds is okay so I will go with a bit bigger resistor.I hadn't thought about the MCU collective source/sink before, but that's a great thing to keep in mind. In general, my rule has been to try to not have pins sourcing or sinking ANY mA-level current, but obviously here I missed the boat with not understanding how BJTs work.This whole experience has been incredible, but I'm thinking it will soon be time (as I continue to get deeper into PCB design and firmware) to get some better tools. My $20 Amazon logic analyzer proved indispensable when (eventually) discovering my SPI slave device expected Mode 1 rather than Mode 0, but it doesn't help me at all with good quality waveform info nor have any ability to measure/monitor power consumption, voltages, etc. Using my (automotive-type) multimeter has been comically clumsy as even my smallest probes are massive compared to PCB-scale things.

author: MrAl
author_rank: Super Contributor
timestamp: September 08, 2023, 12:04:05 am
content: Quote from: meshtron on September 05, 2023, 02:31:56 pmHi,Oh, you are welcome, and I know what you mean about the probe size. I found those mini grabbers and micro grabbers helpful for grabbing onto small parts on the board. They help a lot with measurements.The mini grabbers are smallish, but the micro grabbers are the smallest and I think they can even clamp onto DIP package IC pins.

author: xavier60
author_rank: Super Contributor
timestamp: September 08, 2023, 03:10:46 am
content: A single resistor just in series with the Emitter will limit the current for both.