adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

GPIO current specifications

Mon Jul 23, 2012 2:54 pm

Hi,

I still cannot find any maximum current specifications on the GPIO. Can anyone point me to a trustworthy page for this?

Thanks,
Adam

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Mon Jul 23, 2012 4:47 pm

Also, I found this

http://www.scribd.com/doc/91353537/GPIO-Pads-Control

fragment about setting the current on a GPIO chip that I believe is the one on the Pi. I imagine that this means I can set bits 0--2 to 7 (binary 111) to get 16 mA per pin. It also looks like if I reset the Pi and forget to set these bits again, then it can only handle 8mA.

If anyone can supply some of this information, it would be nice to add it to this Wiki page:

http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23965
Joined: Sat Jul 30, 2011 7:41 pm

Re: GPIO current specifications

Mon Jul 23, 2012 8:19 pm

That's an extract from the published datasheet for the Raspi and is about as official as you can get.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: GPIO current specifications

Mon Jul 23, 2012 8:48 pm

then it can only handle 8mA.
Nearly.
It can source 8mA with the defined voltage output of not less than 2.7V. It actually can source more but the voltage drops, so you can get more current than the maximum permitted current of 17mA source and 12mA sink. These figures come from the Broadcom data sheet.
However, it is not as simple as that and a lot depends on the frequency, the load on other chips, the amount of current switching at any one time. As well as physical things like the layout, quality of decoupling capacitors and capacitive loading.
I imagine that this means I can set bits 0--2 to 7 (binary 111) to get 16 mA per pin.
You can only set the current on a group of pins. There are only three groups:-
Address
0x 7e10 002c PADS (GPIO 0-27)
0x 7e10 0030 PADS (GPIO 28-45)
0x 7e10 0034 PADS (GPIO 46-53)

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Wed Aug 01, 2012 8:28 am

Thanks, Mike.

I now have the pins turning on and off, but I would like to set the maximum current using those registers. Is there some simple (shell script?) way to set those bits? I've never tried to set registers before.

Adam

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO current specifications

Wed Aug 01, 2012 12:34 pm

adamhayes wrote:Thanks, Mike.

I now have the pins turning on and off, but I would like to set the maximum current using those registers. Is there some simple (shell script?) way to set those bits? I've never tried to set registers before.

Adam
Note that the GPIO pins are in three groups or 28 pins so all the pins we're interested in are in the first group, so you can't control the drive for a single pin, but essentially all the pins on the GPIO connector.

The 3 sets of pad drivers are initialised to:

0000001B 0000001F 0000001B

the 0x1B is the ones we're interested in for GPIOs 0-27 and decoding 0x1B into 0001 1011 gives us

slew: 1 - not limited
hyst: 1 - enabled
drive: 011 - 8mA

So in theory we can change drive to 111b (7) and get it up to 16mA.

Now.. I'm not a chip designer and it'll take someone who is (pref. from broadcom!) to explain exactly how the current limiter works, but I know that using the Pi, it's possible to drive LEDs at 15mA using the defaults... Actually, I know that a single GPIO pin will source 35mA if you accidentally short an LED limiting resistor with a DVM set to amps and not volts... My suspicion is that there is an overall current limiter for all the pads in the group, so taking a little more on one pin isn't going to have any effect unless you do it on all of them...

Note the 2nd group is enabled for 16mA drive... The chip reset condition is for 8mA, so something in the kernel has explicitly set that group for higher drive current... A quick look at the schematic shows thos pins in that group being used for the PWM/Audio outputs only.

I did experiment with it in wiringPi, but in the end never really bothered doing anything with it. I suspect that for the most part it's not going to be an issue, but it's easy to change if you need to - some of the code is there in wiringPi, but commented out if you look close enough...


-Gordon
--
Gordons projects: https://projects.drogon.net/

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Wed Aug 01, 2012 2:03 pm

Thanks, Gordon. It sounds like I don't have to fiddle with the limiter yet, but I still don't know how to actually poke the bits 111 into that register. I only did assembler on the 8088 25 years ago.

Ok, I have some other problem, then. I get 3.4 volts, but I'm not driving an optoisolator that works with 3.1V in the same circuit. I guess it's wiring or something.

Is it true that if I put 3.1V on my diode,resistor with a separate power supply and get 8.6 mA, then with the Pi's 3.4V, I must be getting about the same current in my diode. I think it should then give just a bit more than 8.6 mA.

Am I missing something tricky with a current limiter that could give less than 8.6 mA, but still give me the same 3.4V out of the Pi? That doesn't seem possible, but maybe I don't understand the diode. (I thought I understood the I-V plot, and I can get the current I expect on a breadboard.)

Guh.

Adam

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO current specifications

Wed Aug 01, 2012 6:07 pm

adamhayes wrote:Thanks, Gordon. It sounds like I don't have to fiddle with the limiter yet, but I still don't know how to actually poke the bits 111 into that register. I only did assembler on the 8088 25 years ago.

Ok, I have some other problem, then. I get 3.4 volts, but I'm not driving an optoisolator that works with 3.1V in the same circuit. I guess it's wiring or something.

Is it true that if I put 3.1V on my diode,resistor with a separate power supply and get 8.6 mA, then with the Pi's 3.4V, I must be getting about the same current in my diode. I think it should then give just a bit more than 8.6 mA.

Am I missing something tricky with a current limiter that could give less than 8.6 mA, but still give me the same 3.4V out of the Pi? That doesn't seem possible, but maybe I don't understand the diode. (I thought I understood the I-V plot, and I can get the current I expect on a breadboard.)

Guh.

Adam
I'd not fiddle with it at all as I've now found out a little more about it. Essentially they're not limiters they're drivers and what you're doing is paralleling up more drivers to each set of pins....

The net effect, as far as we're concerned is that for driving LEDs it's really not going to matter unless we're driving them really really fast. If driving larger resistive loads then the outputs may not get to the full 3.3v, or capacitive loads then the more drivers enabled, the faster the signal will rise/fall.

So for your issue, I'd measure the voltage at the opto isolator (does it have an internal resistor?) and make sure it's in-spec. Try connecting it directly to the Pi's 3.3v supply to check it will work.

I actually went as far as to put some stuff into wiringPi to change the drivers, but it's not actually working - I can read them OK, but not set them, however I've been busy with other stuff today to do more checks, and it might be that there is some trick required to actually write that register anyway.

-Gordon
--
Gordons projects: https://projects.drogon.net/

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Wed Aug 01, 2012 6:17 pm

Gordon, this is more help than I've gotten from anywhere. Thanks.

So, it sounds like I don't have to worry about going up to maybe 15 mA with the register set for 8 mA; I just might see the voltage drop and have to rethink my board.

Is that about right? If so, then I need only an idiot-check!

Thanks,
Adam

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO current specifications

Wed Aug 01, 2012 6:38 pm

adamhayes wrote:Gordon, this is more help than I've gotten from anywhere. Thanks.

So, it sounds like I don't have to worry about going up to maybe 15 mA with the register set for 8 mA; I just might see the voltage drop and have to rethink my board.

Is that about right? If so, then I need only an idiot-check!

Thanks,
Adam
If all you're doing is driving opto isolators which are effectively LEDs, then have a look at this photo:

Image

If I can do that, then you can drive opto isolators which are usually lower powered - unless they have internal resistors that are on the high side - e.g. designed for 5V TTL type...

I'm using 330 ohm resistors there and the LEDs are dropping 2v, so about 5mA flowing. Perhaps you could let us know what it is your trying to drive?

-Gordon
--
Gordons projects: https://projects.drogon.net/

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Thu Aug 02, 2012 12:10 am

Ok, Gordon, you did it. I was doing the right thing treating the isolator (diode side) as an ordinary visible-wavelength LED, but I was lost on the current limits of the GPIO, and that kept me from focusing on the real problem. My isolator has no internal resistor, by the way. It's a 2504, I think.

Now that you set me straight on that, I am pretty sure I'm not overloading anything, and that let me move on to more basic debugging. If you're interested...

I ordered (I thought) 26 pin headers for my board, but they sent 34 pin headers. (Let's blame the supplier for the sake of the discussion.) So--if you're interested--I counted pins sometimes from the top and sometimes from the bottom of the header when I wired it up. You can guess the rest, but here's the thing that really had me scratching my head:

I had wired another GPIO output in place of the ground pin. I checked that the pin I wanted, GPIO 25, (this one happened to be wired correctly) was going high and low as my software set it. It sure was, so I was perplexed about being way off the I-V plot for the isolator. With a (high-impedance) voltmeter, I saw it go high and low, relative to another output pin. When I put a load on it, it didn't work using the other GPIO output as the ground, which seems reasonable! :D


Again, thanks for the help. You should put some of that info about the current limits and what the register settings mean on the Pi Wiki somewhere. I am not the only one who has been confused about this.

Thanks!
Adam

User avatar
Gert van Loo
Posts: 2486
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIO current specifications

Thu Aug 02, 2012 11:15 am

I just found an major error in the GPIO specification document. So I deleted it and posted a new one.
I also added a lot more information on how the GPIO drive strength works and what you should
and should not do.

http://www.scribd.com/doc/101830961

Can somebody update the wiki to point to the new version please?

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Thu Aug 02, 2012 12:19 pm

Very helpful, Gert. Just a couple of questions:
Edit: more than a couple. :)
The raspberry-Pi 3V3 supply was designed with a maximum current of ~3mA per GPIO pin. If you load each pin with 16mA the total current is 272mA. The 3V3supply will collapse under that!
  • Does "collapse" mean only that it will fail to supply the board with enough current to run, or does it mean that you will do some damage? Since each pin can handle about 16mA, it isn't clear to me what would happen.

    (Sounds like I should set up my devices controlled by the Pi so that a short pulse will turn them on, and they will then remain on when the pin goes low. Just to avoid trouble, it sounds smart to have your software turn things on sequentially, that is, all controlled by one process, so that there is no chance of many turning on at once.)
  • Can you (or someone) provide a sample script (bash or python would be ideal) that shows how to set the register?
  • Do these register bits reset when the Pi is turned off or rebooted? I could just try it, but (next question...)
  • Can I really muck things up if I set the register incorrectly, with the wrong address, etc?

    Maybe that is the end of the questions, finally! At least, I think, this could be trimmed down to a nice wiki page!

    Edit: Really the last question-- Gordon's LEDs seem to be pulling 5mA * 17 = 85 mA total, and the maximum on the new "GPIO Pads Control2" post seems to be 3.*26=78 mA. Does the maximum of ~3 mA per pin refer to the whole header of 26 pins, or the 17 GPIOs?

    Adam

User avatar
Gert van Loo
Posts: 2486
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIO current specifications

Thu Aug 02, 2012 12:56 pm

The 3V3 supply is short circuit protected. So "collapse" mean the LDO will turn the voltage down and your Pi will stop working.
There will be no damage.

No you don't have to 'pulse' the outputs. Best is to stick with the value I always gave: ~3mA per pin and you are fine.
There may be an occasional case where somebody needs to draw more current from one or two pins and
the document describes how it all works and what to expect.

Every bit in every register is cleared when you turn the computer off.
The same happens on reset except the GPIO pull-up/pull-down resistors which hold their last state as long as there is power. But AFAIK those are reset by the SW.
Can I really muck things up if I set the register incorrectly, with the wrong address, etc?
Yes you can! Those registers are in the clock/power control section of the chip. Make sure your address is the correct one. You can damage the chip if you accidental would write a high value to the wrong register e.g. the overvoltage register. It is very, very difficult but not impossible. That is why there is a 0xA5... protection value at the top.

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Thu Aug 02, 2012 4:46 pm

Awesome help. Maybe I'll edit this thread and put something on the Wiki...

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO current specifications

Fri Aug 03, 2012 8:21 am

adamhayes wrote:Awesome help. Maybe I'll edit this thread and put something on the Wiki...
Might be good - I'll tempted to do a blog post on it too.

I've just added a function to wiringPi to control it, dangerous though it is (lathough it goes have range checking!), and an extra function in my gpio command... Still not convinced it's that worthwhile fiddling with it though, although I can detect a tiny voltage change when increasing the drive to 7... I do reckon that it's worthwhile buffering for anything more than low power LEDs though.

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: GPIO current specifications

Fri Aug 03, 2012 8:30 am

So as a guide to beginners asking the question "what is the current output I can get from a GPIO pin"
The answer of:-

No more than 16mA per pin with a total current draw from all pins not exceeding 51mA.

Would be a sufficient answer?

adamhayes
Posts: 9
Joined: Mon Jul 23, 2012 2:48 pm

Re: GPIO current specifications

Fri Aug 03, 2012 11:17 am

No more than 16mA per pin with a total current draw from all pins not exceeding 51mA.
That would have gotten me started weeks ago, Grumpy. Someone (I'll try today) should put Gert & Gordon's details on the Wiki, but your summary above should be the first thing anyone sees, in my opinion as a new user. I'm what they call an "expert novice" with over 20 years being a novice.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: GPIO current specifications

Sun Aug 05, 2012 11:09 am

OK I have done a page of my own that encapsulates this information along with some measurements I have made of the voltage / current relationship of the output pins with different drive strengths.
It is here:-
http://www.thebox.myzen.co.uk/Raspberry ... tputs.html

neteng
Posts: 24
Joined: Wed May 11, 2016 3:56 am

Re: GPIO current specifications

Tue Sep 27, 2016 1:35 am

I am trying to read the output channels of an optical encoder.....I have already reading one, having its vcc supplied by the RPi's own 3V3 rail...........It works fine....However, i still have to read 5 more encoders (2 channels per encoder) and 5 limits switches.

Note that I want to supply my encoders Vcc via an ATX power supply(using the orange wire 3.3V ) Also my limit switches, are to be supplied with also this 3V3 power...

So i need 12 GPIO pins to sink my encoder outputs....and 5 to sink my limit switches...17 pins altogether

So what is the maximum current that a single pin can sink???.......

I am concerned with the current handling capacity of the Pi's GPIO......

Help anyone

Return to “Interfacing (DSI, CSI, I2C, etc.)”