Page 1 of 1

Maximum GPIO source/sink current

Posted: Fri Mar 26, 2021 9:46 pm
by dg9ngf
Hello,

I want to build an LED dimmer with PWM with an ESP32 controller. The 24 V LED stripes are switched with a MOSFET but that needs a certain current to switch through quickly. An alternative might be a combination of npn+pnp transistors between the GPIO and MOSFET gate (think it's called push-pull but I don't know it, I'm a software developer, not primarily an electronics engineer). Anyway, I'm sitting in front of LTSpice simulating different resistor values and watching the timings. My aim is to be able to turn the LEDs on and off with a minimum GPIO pulse time of 50 ns (equivalent to 20 MHz).

Now I couldn't find out what maximum current I could use here. The datasheet says 40 mA source current on the high level and -28 mA sink current on the low level. Another thread in this forum shows other figures and even states that the limits are configurable. And it says that higher currents might be okay for a short moment.

According to my simulation, I only need the highest current for a very brief moment of around 10 ns, after that it already decreases to the half or less.

But I want to build a controller with 8 channels (as far as I could find it out, that's the number of fast timers available in the MCU). So that's 8 MOSFETs that want some current to be switched. If all of them turn on in the same moment, what is the maximum current I can draw from a single GPIO (or sink into it when they turn off at the same time) and for how long?

The intended PWM period frequency is 2.5 kHz and the dimmer should provide 8000 levels. Then the lowest level has an ON time of 50 ns. I need so many brightness levels because the lighting needs to go from 100% at full working illumination down to so little that it's just an orientation light in the middle of the night. And it should still be able to smoothly fade on and off even for the night light so I need a few levels below it. Sure I can use a lower PWM frequency for the night but I'll try to get as far as possible without that workaround.

Re: Maximum GPIO source/sink current

Posted: Sat Mar 27, 2021 5:18 am
by ESP_Sprite
Heuristically, at these frequencies, with decent (logic-level) mosfets, it shouldn't be an issue.

In general, I think we have tested the ESP32 GPIOs, and you can get the quoted numbers (40mA, -28mA) out of the chip as long as the total doesn't exceed 1.5A or so, so you should be good unless you connect a MOSFET to every single GPIO the ESP32 has.

The GPIOs indeed have a configurable output current, and you probably want to crank that up to the max if you need those numbers. Do be aware that 'hard' switched outputs like that can lead to ringing, dependent on the layout and other components on your PCB.

Re: Maximum GPIO source/sink current

Posted: Sat Mar 27, 2021 6:32 pm
by dg9ngf
Would it be possible to "exceed" the specification if only for very short time spans? Or can I already expect damage from overcurrent even if only very short?

BTW, how long does it take the GPIO to change from low to high and reverse? I couldn't find any data about that behaviour in the datasheet or elsewhere.

Re: Maximum GPIO source/sink current

Posted: Mon Mar 29, 2021 2:32 am
by ESP_Sprite
Well, the thing is, the GPIO won't give you more than the specced amount of mA (given that you stay within the allowable voltage ranges), so there's no such thing as 'exceeding'.

The GPIO will theoretically change instantly from sinking to sourcing current and vice versa, but it needs to charge any (parasitic or otherwise) capacitors connected to it to get the voltage to the required level. That includes the pin capacitance (you can find that in the datasheet, it's 2pF), the gate capacitance of your MOSFET, as well as any added capacitances from your PCB or any components in the path.

Re: Maximum GPIO source/sink current

Posted: Tue Mar 30, 2021 2:45 pm
by dg9ngf
Oh, that's interesting. Does that mean that I could simply connect the MOSFET's gate to a GPIO pin with no resistor in between and have it "charge as quick as it charges"? I've always read that I should put a resistor in that line to limit the charging/discharging current. That statement was probably under the assumption that a GPIO provides whatever you draw from it but at a certain point breaks from overload. If it limits its strength on its own, I wouldn't need to add another limitation to that. Maybe this is just specific to the ESP32.

Re: Maximum GPIO source/sink current

Posted: Wed Mar 31, 2021 2:00 am
by taylorjulie
I have the same question. Thanks

Re: Maximum GPIO source/sink current

Posted: Wed Mar 31, 2021 3:34 am
by ESP_Sprite
You should be able to (just add a high-value resistor from the gate to ground, so the mosfet won't turn 'half-on' when the ESP32 is e.g. in reset). The thing with not using a series resistor is mostly that it can lead to 'ringing', that is, the GPIO can turn on so fast that the combination of gate capacitance and the inductance of the trace from the GPIO to the gate can form a LC tank that 'rings' when the GPIO switches. Compare the LC tank with a tuning fork: if you hit it with something hard, it starts to oscillate. The same can happen with the gate voltage. In that case, a gate resistance can help dampen out these oscillations. In the case of the ESP32, you could instead try to play with the drive strength of the GPIO to add a 'virtual' series resistor.