Maximum GPIO source/sink current

dg9ngf
Posts: 40
Joined: Mon Sep 16, 2019 6:49 pm

Maximum GPIO source/sink current

Postby dg9ngf » Fri Mar 26, 2021 9:46 pm

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.

ESP_Sprite
Posts: 9715
Joined: Thu Nov 26, 2015 4:08 am

Re: Maximum GPIO source/sink current

Postby ESP_Sprite » Sat Mar 27, 2021 5:18 am

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.

dg9ngf
Posts: 40
Joined: Mon Sep 16, 2019 6:49 pm

Re: Maximum GPIO source/sink current

Postby dg9ngf » Sat Mar 27, 2021 6:32 pm

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.

ESP_Sprite
Posts: 9715
Joined: Thu Nov 26, 2015 4:08 am

Re: Maximum GPIO source/sink current

Postby ESP_Sprite » Mon Mar 29, 2021 2:32 am

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.

dg9ngf
Posts: 40
Joined: Mon Sep 16, 2019 6:49 pm

Re: Maximum GPIO source/sink current

Postby dg9ngf » Tue Mar 30, 2021 2:45 pm

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.

taylorjulie
Posts: 1
Joined: Wed Mar 31, 2021 1:53 am

Re: Maximum GPIO source/sink current

Postby taylorjulie » Wed Mar 31, 2021 2:00 am

I have the same question. Thanks
Hello

ESP_Sprite
Posts: 9715
Joined: Thu Nov 26, 2015 4:08 am

Re: Maximum GPIO source/sink current

Postby ESP_Sprite » Wed Mar 31, 2021 3:34 am

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.

Who is online

Users browsing this forum: No registered users and 38 guests