There is one thing that unites almost every computer and logic circuit commonly used in the hardware hacking and experimentation arena. No matter what its age, speed, or internal configuration, electronics speak to the world through logic level I/O. A single conductor which is switched between voltage levels to denote a logic 1 or logic zero. This is an interface standard that has survived the decades from the earliest integrated circuit logic output of the 1960s to the latest microcontroller GPIO in 2018.
The effect of this tried and true arrangement is that we can take a 7400 series I/O port on an 8-bit microcomputer from the 1970s and know with absolute confidence that it will interface without too much drama to a modern single-board computer GPIO. When you think about it, this is rather amazing.
It’s tempting to think then that all logic level outputs are the same, right? And of course they are from a certain viewpoint. Sure, you may need to account for level shifting between for example 5V and 3.3V families but otherwise just plug, and go, right? Of course, the real answer isn’t quite that simple. There are subtle electrical differences between the properties of I/O lines of different logic and microcontroller families. In most cases these will never be a problem at all, but can rear their heads as edge cases which the would-be experimenter needs to know something about.
Consider the Voltage
These differences are best approached from two angles: voltage and current. We’ve dealt with voltage differences before with a look at level shifters, but it’s worth revisiting some of the ground covered there with a short précis as it contains at least one trap for the unwary. We’ve mentioned that there are several different voltage standards for logic, and of those the two that we will most commonly encounter are the afore-mentioned so-called 5V and 3.3V families. In loose terms both recognise a logic 0 as 0V and a logic 1 as 5v or 3.3V, but of course it is a little more complex.
Each individual family of logic has a voltage range instead of a single voltage that it recognises as a particular logic level, and courtesy of TI’s marketing department we’ve reproduced a handy diagram showing them. The trap for the unwary lies with the two different types of 5V logic, the so-called TTL variants accept a much wider range than their CMOS stablemates. Thus a 5V TTL input will detect logic levels from a 3.3V output while the CMOS version will not, and many an engineer including us has been caught by using the wrong chip to interface between levels, only to find a circuit doesn’t work.
The variants carry the labels “TTL” and “CMOS”, but confusingly these refer to their voltage compatibility with the original TTL and CMOS logic families of the 1960s and 1970s rather than their manufacturing. A more recent chip with a CMOS fabrication process will often be available in both a “TTL” and a “CMOS” version. In the popular “HC” CMOS logic series which dates from the 1980s for example the “TTL” versions are denoted by a “T” in the part number such as “74HCT00” as opposed to “74HC00”.
And Then the Current
Once any concerns over voltage have been overcome, we can move on to the current properties. It’s easy to generalise about logic pins as all being the same: low impedance outputs driving high impedance inputs. A typical output should easily be able to supply enough current to drive a reasonable fan-out of other gates, the base of a transistor, or perhaps an LED through a series resistor. And as above in most cases that’s all a designer needs to know. But again therein lie a few gotchas. And since these are of the variety that can result in destruction of the part in question, it’s imperative to explore a little further.
There are two current figures to bear in mind when looking at an output pin on a logic chip or microcontroller. The first is the current an individual pin can supply, and the second is the total current that can be supplied simultaneously across all pins. Yet again we refer to TI’s 2017 Logic Guide (PDF) for a handy summary of the individual pin current for the multitude of different discrete logic families, and find a significant variation.
As an aside, the TI Logic Guide is an interesting document from a historical perspective, because unlike almost all other semiconductor product lines we find almost all the major logic families produced since the early 1960s together for comparison, and unbelievably still in production after all these years. We celebrate long-lived ICs such as the NE555 or the μA723, we really ought to do the same for the 7400 quad 2-input NAND gate. First brought to market in 1964 and in continuous production ever since, it is arguably the root from which all our current digital devices and computers grew. Without it we would have certainly reached the same point by a different means, but it could be seen as the first link in the chain of integrated circuits that led to our Core i7s or multicore ARMs today.
Back to our pin currents, and paging through the logic guide we find a significant variation in output currents between families. In most cases they list figures for a run-of-the-mill gate and for a buffer designed with a stronger output, so in this case we’re taking the lower figures from the everyday functions.
Even Hackaday Falls into Pitfalls
It depends of course what you are wishing to do with a logic output, but shall we suggest a stalwart of the breadboard experimenter: lighting an LED? Without a second thought we take a rule of thumb and calculate a series resistor for a 10mA LED current which is fine for an original 7400’s 16mA output, but it comes as a bit of a shock to find the HC series of CMOS chips quoted at 5.2mA. Even in the course of writing this article we’ve found that something we’ve certainly done with a 74HC chip could have been exceeding its rated capabilities without our realising it. We must have lit an LED on a breadboard hundreds of times from 74HC series chips, the fact that we seemingly got away with it likely stems from our not exceeding that other figure for the total current supplied by all pins simultaneously. This experience shows how easy it is to fall into this kind of trap by assuming that all logic outputs are the same, it seems to have been purely by good fortune that we avoided coming face to face with the fact that they are not.
GPIO Is the Front Line of Protecting Today’s More Expensive Chips
So we have arrived at a cautionary tale in our examination of 74 series logic, but of course in a large number of cases we won’t be interfacing with a logic chip in 2018. Instead our logic-level outputs are likely to come through a GPIO pin on a microcontroller or single-board computer. At this point the stakes become significantly higher, as instead of a logic chip costing pennies we have the possibility of damaging something worth a significant price should we overload them. So it is necessary to study data sheets and heed the advise of others carefully indeed to avoid an expensive mistake.
Casting around for information on a few common boards, we find the ATmega328-based Arduino has a comparatively generous allowance of 40 mA per pin, but a slightly confusing 200 mA of total current across the eight pins which share each port register . Meanwhile the ESP8266 with its 3.3V logic has a more modest allowance of 12mA per pin, but with the unexpected bonus that all pins can operate at that current simultaneously.
The Raspberry Pi also has 3.3V logic levels, but with an interesting twist. Instead of a single driver behind each GPIO line it has a bank of buffers that can be switched in and out under software control, allowing the output level to be set on a pin-by pin basis. Thus its maximum output can be as high as 16mA, but it can be wound back in applications where a fraction of that drive capability is required.
So we’ve explored the world of logic-level outputs, exposed a pitfall that we’d fallen into, and ended up revealing an unexpected feature of a popular board. It’s still broadly the case that when level shifting is taken care of, all logic lines can talk to each other. But we hope now the chances of your doing so without releasing the magic smoke are decreased.