Author Topic: Understanding BJT Behavior  (Read 3668 times)

0 Members and 2 Guests are viewing this topic.

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 132
  • Country: us
Understanding BJT Behavior
« on: September 03, 2023, 04:53:28 pm »
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 a BC817-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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11530
  • Country: us
    • Personal site
Re: Understanding BJT Behavior
« Reply #1 on: September 03, 2023, 05:02:41 pm »
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 .
Alex
 
The following users thanked this post: meshtron

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3605
  • Country: nl
Re: Understanding BJT Behavior
« Reply #2 on: September 03, 2023, 05:04:01 pm »
... but don't want to assume that as my intuition for these things seems to be approximately 150 degrees out of phase. :)

That means you  have a phase margin of 30 degrees, so you are probably still within acceptable stability margins.

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. 

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

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 132
  • Country: us
Re: Understanding BJT Behavior
« Reply #3 on: September 03, 2023, 05:27:59 pm »
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11530
  • Country: us
    • Personal site
Re: Understanding BJT Behavior
« Reply #4 on: September 03, 2023, 05:35:23 pm »
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.
« Last Edit: September 03, 2023, 05:37:35 pm by ataradov »
Alex
 
The following users thanked this post: meshtron

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 132
  • Country: us
Re: Understanding BJT Behavior
« Reply #5 on: September 03, 2023, 05:39:15 pm »
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11530
  • Country: us
    • Personal site
Re: Understanding BJT Behavior
« Reply #6 on: September 03, 2023, 05:42:05 pm »
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.
Alex
 
The following users thanked this post: meshtron

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 132
  • Country: us
Re: Understanding BJT Behavior
« Reply #7 on: September 03, 2023, 05:48:32 pm »
Understood, thank you Alex!
 

Online magic

  • Super Contributor
  • ***
  • Posts: 6982
  • Country: pl
Re: Understanding BJT Behavior
« Reply #8 on: September 03, 2023, 07:30:43 pm »
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.
 
The following users thanked this post: meshtron

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 132
  • Country: us
Re: Understanding BJT Behavior
« Reply #9 on: September 03, 2023, 09:06:35 pm »
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.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1547
Re: Understanding BJT Behavior
« Reply #10 on: September 05, 2023, 05:22:32 am »
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.
 
The following users thanked this post: Electro Fan, meshtron

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 132
  • Country: us
Re: Understanding BJT Behavior
« Reply #11 on: September 05, 2023, 02:31:56 pm »
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.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1547
Re: Understanding BJT Behavior
« Reply #12 on: September 08, 2023, 12:04:05 am »
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.

Hi,

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.
 

Offline xavier60

  • Super Contributor
  • ***
  • Posts: 2871
  • Country: au
Re: Understanding BJT Behavior
« Reply #13 on: September 08, 2023, 03:10:46 am »
A single resistor just in series with the Emitter will limit the current for both.
HP 54645A dso, Fluke 87V dmm,  Agilent U8002A psu,  FY6600 function gen,  Brymen BM857S, HAKKO FM-204, New! HAKKO FX-971.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf