If your introduction to digital electronics came more years ago than you’d care to mention, the chances are you did so with 5V TTL logic. Above 2V but usually pretty close to 5V is a logic 1, below 0.8V is a logic 0. If you were a keen reader of electronic text books you might have read about different voltage levels tolerated by 4000 series CMOS gates, but the chances are even with them you’d have still used the familiar 5 volts.
This happy state of never encountering anything but 5V logic as a hobbyist has not persisted. In recent decades the demands of higher speed and lower power have given us successive families of lower voltage devices, and we will now commonly also encounter 3.3V or even sometimes lower voltage devices. When these different families need to coexist as for example when interfacing to the current crop of microcontroller boards, care has to be taken to avoid damage to your silicon. Some means of managing the transition between voltages is required, so we’re going to take a look at the world of level shifters, the circuits we use when interfacing these different voltage logic families.
Do You Even Need A Level Shifter?
It might seem odd to start a treatise on level shifting this way, but the first question for the designer when looking at making a 3.3V part talk to a 5V part should be this: Do I even need a level shifter?
If the 3.3V part is an output and the 5V one an input, the lower voltage part can hardly damage the higher voltage one with overvoltage. And you are not likely to encounter a logic input that might demand so much current that it would damage your output (If you do, use a buffer!). If you are lucky the logic voltage ranges of the two devices may even coincide. For example 3.3V TTL logic shares the 0.8V and 2V thresholds for logic 0 and logic 1 transitions with 5V TTL logic, so a 3.3V TTL output can drive a 5V TTL input without any extra hardware required.
In the other direction, driving a 3.3V input from a 5V output you might expect that a level shifting circuit would be required, and in many cases you would be right. But before reaching for that shifter it’s worth taking a look at the detailed specifications of your 3.3V input. Many devices are designed to be 5V tolerant, and you might be lucky enough to find that your circuit could use one and avoid the extra circuitry. For example the 74LVC series contains a range of 5V tolerant 3.3V versions of many 74-series ICs.
CMOS And TTL: A Level Shifting Cautionary Tale
When directly driving logic you’d normally use at 5V from a 3.3V output there is one cautionary tale of which to take heed, a personal confession of an electronic failure. CMOS logic defines its logic thresholds as a percentage of supply voltage, which with a 5V supply puts the logic 1 threshold of 70% well above the 3.3V logic 1. Some CMOS ICs such as the 74HC4053 analogue switch I used in a Raspberry Pi project don’t quite follow this standard and will work from a 3.3V TTL output, so I was lulled into a false sense of security and reached for another 74HC part to connect to my Raspberry Pi with a new design. As you might expect it failed to work, and of course I wasted time looking everywhere else but my defective choice of part. If there is a moral to this story it is to always read the datasheet carefully, and use the TTL-compatible parts such as in this case 74HCT, when they are available.
If your 3.3V device inputs are not 5V tolerant and your 5V inputs lack 3.3V compatible thresholds then sadly you won’t be able to interface them across voltage levels without a shifter circuit. There are many choices available to you including a whole host of dedicated level shifter devices such as these ones from TI, but aside from personal preference some of them will be dictated by your application. Will it be a step-up, a step-down, or do you need a bi-directional level shifter? If you decide not to use a dedicated part or a 5V tolerant gate in your design, here are a few of the many alternatives.
Step-down level shifters
The simplest possible step-down circuit is a resistive divider. Drive your 5V output into a chain of resistors, from which you tap your 3.3V logic input. A chain consisting of a 2.2k and a 3.3k resistor should produce a 3V output from an applied 5V input. It does not preserve the fan-out characteristic of the 3.3V output and you need to be aware of any capacitances that may also reside in whatever logic is connected to it and the effect they may have along with the resistors on fast rise times, but it should suffice for most simple level downshifting tasks facing a hobbyist. There are variations on this circuit that use diodes instead of a resistor to achieve the required voltage drop.
If the divider is not suitable for your application and you still eschew a dedicated shifter, take a look further down the page at bidirectional shifters.
Step-up level shifters
For stepping up from 3.3V logic to 5V logic and assuming you are not safely within the TTL thresholds as described above such that you can do without a shifter, you will require something a little more complex than the resistive divider in the previous section. The simplest circuit uses a pair of diodes with careful biasing and choice of series resistor as shown in the diagram to the right. The application note it comes from advises that the resistor should be significantly less than the input impedance of the 5V gate, to avoid its being part of a resistive divider with that impedance having an effect on the output voltage.
A rather more obvious circuit uses a MOSFET or bipolar transistor as a switch, driving the gate or base with the 3.3V logic and taking the 5V logic output from the drain or collector. This is very similar to using a gate with an open-collector output in the same application. This is a simple and reliable circuit, but it must be borne in mind that it inverts the 3.3V logic level.
Bi-directional level shifters
The circuits in the previous two sections are both only suitable for unidirectional logic lines, but not in the case of a bidirectional bus. As before there are plenty of off-the-shelf bus level shifters from a range of semiconductor manufacturers to choose from, but if these are not suitable for your design then a handy alternative can be made with a MOSFET and a couple of resistors. It’s also worth pointing out that this doesn’t have to be used on a bidirectional bus, it can serve as a general purpose level shifter for the cost of a 2N7000 or similar, indeed this is a personal favourite for this application. You can readily buy this circuit on a breakout board from several electronics suppliers if building it yourself doesn’t appeal. For more information on its operation take a read of the Philips application note AN97055 (PDF), which examines its use on an I2C bus.
It can be a worry, when you first have to ensure that different logic levels are safely interfaced. Will my 5V Arduino harm this 3.3V sensor? We hope that after reading this piece you’ll have some more confidence, and we’ve equipped you with enough to make some sense of the topic. We’ve not covered every possible technique, but if you read some of the attached application notes and then search the web for real-world usage they should fill in any gaps.