driving external BJT using internal pull-up resistor? - Page 1
Forum section: electronics / general

author: 240RS
author_rank: Regular Contributor
timestamp: September 28, 2022, 08:10:49 am
content: I am using STM32G4's a lot and solder through-hole nucleo boards. If I drive quite some transistors (BC549C with high gain), I use 10k base resistor normally if I want to switch 6mA to ground (1/20th of collector current).Would be nice if I could drive the transistor directly from the MCU without the base transistor and thought of the following: why not use the internal pull-up to switch the transistor on pull the output pin low for logical to switch the transistor off. Is that being done?At powerup and down, I need to make sure the transistor is never switched on. Is there a risk that cannot be done by configuring the PWR registers correctly?The only thing I am trying to do is save space by using less through-hole resistors.Also, I want the the collector-emitter voltage to be as low as possible at 6mA and use a 1/20th base current as rule of thumb. With a higher gain transistor like the BC549C (hfe in the 100s), is this still 1/20th? The internal pull-up of the MCU seems to be around 40k. My ideal value was 10k.Thanks!

author: wek
author_rank: Frequent Contributor
timestamp: September 28, 2022, 08:30:57 am
content: I don't like the idea, but I am not a HW expert. If the datasheet-guaranteed maximum pullup resistance, minimum used VDD and datasheet-guaranteed minimum hfe at the datasheet-given Vce yields the required current, and if you don't need speed, well then maybe it's OK.From the powerup/down point of view, the GPIO state during reset is not influenced by PWR or any other internal register, and is given in GPIO chapter of DS (with the extraUSBC-PD caveat in 'G0/'G4). Most pins are floating/analog in 'G4 during and after reset, check the leakage table in datasheet and assert, if max leakage x maximum hfe won't result in exceedingly high current for your application. Note, that some pins (the JTAG/SWD ones) do have pullups/pulldowns switched on during reset.Also from programming point of view, using pullups/pulldowns dynamically brings in atomicity problem, if you want to use it in interrupts (note that when using "normal" outputs, atomicity at hardware level is ensured by using GPIO_BSRR register).JW

author: srb1954
author_rank: Super Contributor
timestamp: September 28, 2022, 10:11:24 am
content: Quote from: 240RS on September 28, 2022, 08:10:49 amI wouldn't recommend using the internal pull-up resistors in the micro as they usually don't have a sufficiently well controlled resistance value to ensure adequate base current drive to your BJT. There is also a risk that the BJTs and the micro are damaged by excessive current if you accidentally configure the port O/Ps as a strong active push-pull drive and there is no resistor to limit the base current.Considerable space saving could be made by using resistor arrays. Depending on your PCB design rules you save 50-75% of the space of discrete resistors.Two other options that can completely eliminate base resistors are:(a) Use a MOSFET and drive it directly from the micro O/P pin. You will need to ensure that the MOSFET is a low threshold device that can be fully turned on by the available output voltage swing of the micro port pin. Suitable low-threshold MOSFETs will likely be more expensive than a BJT and there is also a possibility that the MOSFET is inadvertently switched on by port leakage during the power-up process of the micro and until such time as the S/W sets the ports to O/Ps and to the correct inactive state.(b) Use BJTs with internal bias resistors, sometimes known as 'digital transistors'. These are more predictable during power-up conditions as they incorporate an internal base-emitter resistor that will keep the transistor turned off while the micro is performing its power-up procedure.

author: 240RS
author_rank: Regular Contributor
timestamp: September 28, 2022, 01:46:23 pm
content: Thanks for the two posts. This concludes it for me: I will just use base resistors. Thanks. Learned a lot.

author: Peabody
author_rank: Super Contributor
timestamp: September 28, 2022, 02:32:10 pm
content: I have done that with other processors, and it has worked well. But I only do hobby stuff, not production design. In the end, you might want to just try it and see what happens. If the internal pullup is 40K, and the DC gain of the transistor is at least 90, then switching 6mA should be no problem. And if the GPIO pins are floating on powerup, I don't think the transistors will turn on, even momentarily. That leads to the question of how you would turn the transistors off. In theory, you could just disable the pullup so the port is floating. Without base current, the transistor should turn off. But in a very noisy environment, you might want to change the port to output, low. Just be careful to change it back to input first to turn the transistor back on. You don't want it to ever be output, high.Well I'll defer to the judgement of the EEs here, but my suspicion is it would work just fine.

author: wek
author_rank: Frequent Contributor
timestamp: September 28, 2022, 08:21:59 pm
content: QuoteSTM32 have also switchable pulldowns, and the control for both is through the same register for a given pin, so a "swap" from pullup can be done in a single operation.JW

author: thm_w
author_rank: Super Contributor
timestamp: September 28, 2022, 09:25:11 pm
content: Quote from: srb1954 on September 28, 2022, 10:11:24 amOP said they are using through hole resistors... so you'd definitely save 75%+ space by using SMD resistor arrays.https://www.alliedelec.com/m/d/e3a99357d474a10a17a554dd52b3f6d3.pdf

author: Benta
author_rank: Super Contributor
timestamp: September 28, 2022, 10:06:13 pm
content: No matter what you do (base resistor or not), the transistors will be "on" at powerup/reset with your design.If this is OK for you, fine. Otherwise you need to rethink it.

author: wek
author_rank: Frequent Contributor
timestamp: September 28, 2022, 11:17:59 pm
content: Quote from: Benta on September 28, 2022, 10:06:13 pmAre you sure? BC549C are NPN.JW

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 28, 2022, 11:36:09 pm
content: Quote from: 240RS on September 28, 2022, 08:10:49 amMeasure it and see- use a small series R and check the drop across it, keep in mind the pullups can be non linear, depending on the chip design.You can measure the available base current, and the Vcesat follows a curve.Better data sheets show the saturation region eg this onehttps://datasheet.lcsc.com/lcsc/2008011835_LGE-BC547C_C713614.pdfThese days, mosfets and pre biased / digital transistors are a more common solution to avoid the resistor.Quote from: 240RS on September 28, 2022, 08:10:49 amYou do need to check the pin reset values for your MCU, as how they handle the default port settings (float or pullup) varies with vendor and family.

author: thm_w
author_rank: Super Contributor
timestamp: September 29, 2022, 12:21:13 am
content: I wouldn't measure it when they give you the number in the datasheet:https://www.st.com/resource/en/datasheet/stm32g474cb.pdf

author: srb1954
author_rank: Super Contributor
timestamp: September 29, 2022, 01:51:11 am
content: Quote from: thm_w on September 28, 2022, 09:25:11 pmYou can get THT resistor arrays as well; these are commonly known as SIL (single-in-line) resistor packages. My estimate of 50-75% space saving was based on using SIL packages.You can certainly do a lot better by by going to SMD technology even if you use discrete SMD resistors, especially if you are prepared to go to 0201 or smaller package sizes.

author: Benta
author_rank: Super Contributor
timestamp: September 29, 2022, 06:27:36 pm
content: Quote from: wek on September 28, 2022, 11:17:59 pmYes, I'm sure. The transistors will be "on". But if you mean that the output (collector) voltage will be "low", then that's true as well.