Understanding Outputs

 

The Raspberry Pi has a connector that gives you access to 17 of the processor's GPIO pins. GPIO stands for General Purpose Input Output and it means that these pins can be either an input or an output depending on how the software configures them. As well as general purpose, these can be specialised as well, like serial port pins, SPI or I2C lines. Here I want to look at these pins when used as a simple output.

From the GPIO pins

One of the first questions you need to ask when considering interfacing anything is, what current can you draw from the output? On this processor particularly, it is not an easy answer. The simplest answer would be 3mA, but a more considered answer might be:-


A maximum of 16mA per pin with the total current from all pins not exceeding 51mA.


This is further complicated by the fact that there is a register which allows you to set the drive strength of all the pins from 2 to 16mA. This is often a cause of confusion to beginners as they tend to misunderstand the term. What drive strength means is the current that can be drawn, while maintaining the appropriate voltages for logic level inputs. What it does not mean is the maximum amount of current you can take from a pin, nor is it the limit that will be given from a pin. It will not limit the current to a safe level. What it does mean is that it actually changes the supply impedance of the output pin.

Maximum Output Current

This term impedance is often not well understood so this is a explanation of the concept. In electronics anything that generates a voltage has what is known as an output impedance. The symbol for an ideal voltage generator is a simple circle. We say it is an ideal voltage source because it has no output impedance. This is a device that will drive current into a load according to Ohm’s law, you might think that is done with real voltage sources but as we shall see it is not quite. Imagine the situation where you have a short circuit across the voltage source, Ohm's law says that there will be an infinite amount of current drawn, that simply is not going to happen. Consider the case of shorting out the terminals of a 9V PP3 type battery, I would be surprised if you would notice it. Now replace this battery with a car battery, most likely the wire would melt or if it is a spanner causing the short then at least a chunk will be melted out of it, and there would be lots of sparks. So what is the difference? Well it is not the difference in voltage, Ohm's law predicts an infinite current in both cases, what is the different is the amount of current capacity of the two batteries. This is determined by the chemistry of the batteries involved. Well in electronics there is no point in delving into chemical equations, it does not help determine the current, which it the only thing we are interested in, and besides it would not help with the situation of a limited current from a bench supply or the output of an amplifier. So we come up with the concept of source impedance, this is simply a hypothetical resistor that is placed in series with the idealised voltage source. Being hypothetical it does not exist as a resistor but it takes into account all the factors that limit the current draw. Now we can easily explain the difference between our two batteries, the car battery has a low output impedance where as the 9V battery has a high output impedance. We can calculate the value of this hypothetical resistor and use it in calculations. For example in the case of a short circuit across a voltage source the current is limited by the output impedance of the source and can be calculated using Ohm's law.

At this point people tend to ask, “Why call it an output impedance why not an output resistance?” Well, the term impedance is used in electronics for things that impede the flow of current which you might think is the same as resisting the flow of current. The difference is that if something is an impedance, its value can change along with some other factors like current or frequency, where as a resistance is a fixed value no matter what current is flowing, although I am not talking about temperature coefficients here. Again, going back to our batteries, the impedance changes with the amount of charge in the battery, as well as the amount of current being drawn. Another way of looking at it is to say a resistance is a linear quantity, where as an impedance is non linear. In things like amplifiers, the impedance is also dependent of the frequency of signal it is outputting.


Well what has all this got to do with the output pins of a Raspberry Pi? It is that the drive strength setting of the output pin alters its output impedance, and so affects the amount of current it can supply, along with the voltage output on the pin when it supplies this current.

So the drive of the pin is actually an impedance setting caused by the selective enabling of three output amplifiers. These are connected in parallel and so the overall impedance is determined by the output impedances of each enabled amplifier in parallel. This impedance value is not quoted in the data sheet but it can be calculated by doing a bit of measurement. I first measured the voltage from a pin with no load on the output, this is nominally 3.3V but you will see this was slightly over in my setup. Then I set the output current to 8mA by placing a potentiometer or variable resistor and adjusting it until the measured current was 8mA and then I measured the voltage from the output pin. I did this for each drive strength setting of the pins to get the following results. These results are only as accurate as my meters so do’t take the decimal places too literarily.

Back to the Punnet

A maximum of 16mA per pin with the total current from all pins not exceeding 51mA.

I also measured the voltage output of the pin for different currents, the results are quite linear and show a straight line relationship between current and voltage. Note that I only measured up to 16mA as that is the "safe" value of current for a pin. You can however draw more current from a pin by putting a higher load on it, that is, a load with a low resistance, or even a short circuit.

This table shows the calculated short circuit current for each drive strength. Notice that all the drive strength settings produce a current OVER the recommended maximum limit.

So what are the other factors limiting the output current you can achieve? Well this current from the pins has to come from somewhere, in this case it comes from the 3V3 regulator. If you drew 16mA from each of the 17 pins this would add up to

16 * 17 = 272mA.

This is too much current for the regulator to supply. When the Pi was designed, they used a figure of 3mA per GPIO pins in determining if the regulator could supply enough current. Hence the simple 3mA limit mentioned before. However, if not all the pins are supplying current then you can divert those pin’s share of the current into the ones you are using. Hence the total recommended current limit of 17 * 3 = 51mA.

Well undoubtedly they can, in electronics there is no such thing as a point where below is safe and above will destroy the chip. It is a continuum, there is a point where the chip or wires inside the chip will melt, however before you get to that point you enter the region where the chip deteriorates faster than it otherwise would. Where that point is you can't say because no absolute values are given in the data sheet. This can result in early failure or life shortening. It is just like smoking, damage is being done to you lungs all the time but you don't immediately drop dead, it is just that you don't live as long. Do you know that smokers have a much lower chance of getting Alzheimer's disease, it's not because of any protective effect of smoking but simply smokers tend to die before they can contract it. The same with exceeding recommended values in electronics. I would take the 16mA limit as a hard limit although I am sure you could push this a bit without too much damage. Where as the total current draw from all the pins I would treat a bit more flexibly. Here the worst that could happen is that the 3V3 regulator shuts down with over current and not much harm is done.

Can these limits be pushed?

Other considerations

There are other things to take into account as well. There is the SSO (Simultaneous Switching Outputs) limitations, this is the amount of current that can be switched at any instant. Again there is no quoted value, this is because it depends on a lot of factors that are not under the control of the chip manufacturers, like the layout of the board and the number and quality of decoupling capacitors used. What happens is that so much current is returned through the ground wire that this wire increases in voltage due to the small resistance that it has. So instead of being ground it is temporarily higher. This is known as ground bounce and can disturb the processor's operation. It is not fatal in that it will not cause damage but it will stop the system working correctly.


So knowing the output impedance and the current limits of the pins you can make more sensible decisions about how you connect your outputs.