How can I control the current I draw from the GPIO pin?

Thread Starter

AIBang

Joined Feb 3, 2024
30
The PA8 pin of the STM32F405RTG integrated circuit can pass a maximum of 8mA current.

gpio_current.PNG

How can I adjust the current I draw from this pin?
 

BobTPH

Joined Jun 5, 2013
11,465
For a given load, you cannot control the current without dropping the voltage. If that is what you want, forget it.

What is the load? Normally, a series resistor can be used to limit the current.
 

Ya’akov

Joined Jan 27, 2019
10,226
Welcome to AAC.

Using Ohm’s Law you can calculate the current if you know the voltage and resistance. If the current is too high, a current limiting resistor can be added to drop the voltage and therefore limit the current. This is what a current limiting resistor does in the case of LEDs.

The relevant form of Ohm’s Law is:

\[ I (current) = \frac{V (voltage)}{R (Resistance} \]

So, you can first see if the current is too high, then if it is, you can rearrange the formula to determine a resistance that will limit the current to appropriate levels. This AAC calculator will simplify things.

Depending on what you are trying to power with the GPIO, you might have to put a transistor between the pin and the load to act as a switch. If the load is inductive or could be the source of voltage spikes, you can use an optoisolator which is an LED and a phototransistor packaged so that when the LED lights, the phototransistor turns on.

This provides galvanic isolation, that is, electrical separation of the input and output while allowing communication of the logical state of the pin to control an external load.
 

sarahMCML

Joined May 11, 2019
695
You "adjust" it by ensuring that any load or loads that you attach to that pin do not draw more than, in the normal case, 8mA.
If you wish to attach an LED (or something else that doesn't itself need more than 20mA) and drive it at up to 20mA, you select the current limiting resistor to allow that current. But in doing so you drive the output beyond its normal Logic limits. So you cannot then attach additional Logic inputs to the same point.
 

Thread Starter

AIBang

Joined Feb 3, 2024
30
Welcome to AAC.

Using Ohm’s Law you can calculate the current if you know the voltage and resistance. If the current is too high, a current limiting resistor can be added to drop the voltage and therefore limit the current. This is what a current limiting resistor does in the case of LEDs.

The relevant form of Ohm’s Law is:

\[ I (current) = \frac{V (voltage)}{R (Resistance} \]

So, you can first see if the current is too high, then if it is, you can rearrange the formula to determine a resistance that will limit the current to appropriate levels. This AAC calculator will simplify things.

Depending on what you are trying to power with the GPIO, you might have to put a transistor between the pin and the load to act as a switch. If the load is inductive or could be the source of voltage spikes, you can use an optoisolator which is an LED and a phototransistor packaged so that when the LED lights, the phototransistor turns on.

This provides galvanic isolation, that is, electrical separation of the input and output while allowing communication of the logical state of the pin to control an external load.
xx.PNG

Yes, the logic is actually simple, but I cannot calculate how much current I can draw from the chg_wake gpio pin. Knowing only the current, I cannot use the equation.
 

Ya’akov

Joined Jan 27, 2019
10,226
I’m sorry, but I don’t understand your reply.

You have a limit of 8mA you don’t want to exceed. The only load connected to the pin in your schematic are the diode, a 1kΩ resistor, and the transistor.

What is the problem you are having in working out the total current?
 

Alec_t

Joined Sep 17, 2013
15,104
Which port pin are you using for the chg_wake signal? According to that datasheet, some pins can source/sink more current than others.
How frequently does that signal change? Note the capacity limit in the datasheet.
 

Thread Starter

AIBang

Joined Feb 3, 2024
30
Üzgünüm ama cevabınızı anlayamıyorum.

Aşmak istemediğiniz 8mA sınırınız var. Şebekenizdeki pime bağlı olan tek yük diyotu, 1kΩ direnç ve transistördür.

Toplam program programlamada karşılaşmadığınız sorun nedir?
[/ALINTI]
Can we say that the transistor regulates the current drawn from the pin?
 

MrSoftware

Joined Oct 29, 2013
2,273
Firstly, what exactly is the goal here? Is the goal to sense the state of the GPIO pin (high/low)?

Going by your schematic, R8 will limit the current. You know the nominal output voltage of your GPIO pin, there's a drop across the diode then R8 then a tiny drop across the transistor. You can calculate the current for the case that the transistor is fully on. Assuming your goal is to sense the state of that pin, check if you can put that pin in input mode with an internal pull-up. The internal pull-up would likely be 10k-20k, so you'll be loosing less current (less wasted battery power) when the pin is pulled down by your circuit, and that will also limit the current for you.
 

Danko

Joined Nov 22, 2017
2,136
@AIBang:
This is comparator, which sends low level
signal to CHG_WAKE, when PACK voltage is
couple of volts more than BATTERY voltage:
1707320296620.png
How comparator works, see HERE.

See where input (not output) of CHG_WAKE is located:
1707321078877.png
 

Attachments

Last edited:

ApacheKid

Joined Jan 12, 2015
1,762
View attachment 314657

Yes, the logic is actually simple, but I cannot calculate how much current I can draw from the chg_wake gpio pin. Knowing only the current, I cannot use the equation.
Put 3v into that circuit, I mean disconnect from the MCU and just apply 3v to it and put an ammeter in series with it. Then you'll know how much that circuit draws when 3v is applied. Of course the current through Q1 will also depend on its base current and we can't see the rest of that circuit so it's hard to tell.
But doing an actual measurement will at least give you and idea of how much that circuit draws, it might draw 3mA or it might draw 18mA but at least you'll know what your dealing with insofar as that specific circuit's concerned.

As others are pointing out too, the presence of R8 already limits the current, so even if the transistor is fully conducting the current through R8 cant't exceed about 3mA, so nothing you can do can cause > 8mA to ever be drawn from the GPIO pin.
 

MrSoftware

Joined Oct 29, 2013
2,273
Datasheet here (st.com)

OK read more of the datasheet, you're missing some key things here. If that port is to be an input port, it's not going to provide much current at all. i.e. you don't have to worry about limiting the current yourself, it's a non-issue.

Datasheet section 5.3.16 I/O port characteristics, "All I/Os are CMOS and TTL compliant." CMOS inputs are high impedance, so right away you know that if that port is configured as an input, you don't need to worry about limiting the current.

Datasheet section 2.2.34:

"Each of the GPIO pins can be configured by software as output (push-pull or open-drain, with or without pull-up or pull-down), as input (floating, with or without pull-up or pull-down)"

The pin/port can be configured such that you have to pull it up/down yourself (floating), or it can be pulled up/down by internal resistors. You don't show an external pull-up in your schematic, so lets assume you configure the port as input with internal pull-up. You're using pin PA8. In table 48, we see that the internal pull-up for PA8 is nominally 40k. So with the port configured this way, if you dead short pin PA8 to ground, the most you're going to get from it is (I = V/R) 3.3/40,000 = 0.08mA (almost nothing).

So long story short; configure that port as an input with internal pull-up and you've got nothing to worry about.

Table 48:
1707398306939.png
 
Top