C7 · Lesson 11 · Interfacing logic to the world
Driving LEDs, crossing between 5 V and 3.3 V, and how many inputs one output can feed
A logic output is not an ideal voltage source: lesson 1 showed its high level sagging as it sources current, and lesson 10 let several outputs share a wire. Real boards connect logic to LEDs, to chips on a different supply, and to more inputs than the datasheet example shows. A 5 V signal wired straight into a 3.3 V chip can feed current through its protection diodes and latch it up or slowly damage it; a 3.3 V output may not reach a 5 V CMOS input's high threshold at all. Each crossing has a small, calculable fix: a resistor, a divider, a transistor, or a buffer with the right thresholds.
- A 5 V square wave drives a 3.3 V chip's input through a resistive divider (1.8 kΩ over 3.3 kΩ). The capacitor is the input's and the wiring's capacitance.
- The divider scales 5 V to about 3.2 V, safely inside the 3.3 V chip's range. But it also has a Thevenin resistance, and with the input capacitance that slows the edges.
- Raise both resistors to save power and watch the edges round off. At some point a fast signal no longer reaches its levels before it changes.
Predict
A 3.3 V microcontroller's output (guaranteed at least 2.4 V high) drives a 5 V chip from the 74HC family, whose inputs need 3.5 V to read high. What happens?
It may not work. 74HC inputs on 5 V use CMOS thresholds, 70% of the supply, so a valid high is 3.5 V or more, and 2.4 V sits in the forbidden band. Many boards work by luck on the bench and fail across temperature and parts. The fix is a 74HCT part, which runs on 5 V but has TTL thresholds (high above 2.0 V), or a level shifter.
Name it
Driving an LED
A logic output can source or sink a few milliamps. Size the series resistor from the output's guaranteed level at that current:
Check the chip's total current limit too: a port of eight LEDs at 10 mA each may exceed it. For more current, use the output to switch a transistor.
Higher voltage into a lower-voltage input
Inputs have protection diodes to their supply. A 5 V signal into a 3.3 V input turns on the upper diode, pushing current into the 3.3 V rail. Datasheets limit this injection current, often to 1 mA or so, and a chip that's powered off can be powered through its inputs. Options:
- A series resistor limits the injected current: .
- A divider scales the level: , with Thevenin resistance charging the input capacitance, so edges rise with and a 10 to 90% time of .
- A 5 V-tolerant input, which some chips offer on chosen pins.
Lower voltage into a higher-voltage input
The output's high level must exceed the input's :
- Use a part with TTL-compatible thresholds (74HCT, 74ACT): = 2.0 V on a 5 V supply.
- Use an open-drain output with a pull-up to the higher supply (lesson 10).
- Use a MOSFET level shifter: an NMOS with its gate at the lower supply and pull-ups on both sides. It works in both directions, which suits I²C, but its rising edges are only as fast as the pull-ups can charge the bus: .
Noise margins and fan-out
The noise margins between a driver and a receiver are and ; both must be positive, with room for ground noise. Fan-out is how many inputs one output can drive. For families with real input currents it's
For CMOS inputs, which draw almost no DC current, the limit is capacitance: each input adds a few picofarads, and the edges slow down.
Worked example
A 3.3 V microcontroller pin holds at least 2.9 V while sourcing 8 mA. It drives a red LED that drops 2.0 V at that current. What resistor, and what current with the nearest E12 value above?
Show the solution
- Size the resistor. Use the guaranteed high level, 2.9 V:
- Round up to E12. The next E12 value up is 120 Ω, giving about (a little more in practice, since the pin's high level rises as its current falls).
- Why the guaranteed matters. With 3.3 V the calculation gives 162 Ω, and the LED would get less current than planned on a weak part, but never more.
Answer 112 Ω; the E12 value above it, 120 Ω, gives about 7.5 mA.
Worked example
A 5 V sensor output drives a 3.3 V microcontroller pin with 10 pF of input and trace capacitance. Design a divider from E12 values, and find its edge time. Compare a single series resistor that limits injection to 1 mA, with the clamp at 3.6 V.
Show the solution
- Divider output. A 1.8 kΩ over 3.3 kΩ divider gives inside the 3.3 V range.
- Divider edge time. Its Thevenin resistance is = 1.16 kΩ, so and the 10 to 90% rise is 25.6 ns: fine up to a few megahertz.
- Divider current. It draws kΩ ≈ 1 mA whenever the signal is high.
- Series resistor. With 1.5 kΩ, τ = 15 ns.
- Series resistor's cost. It draws nothing while the signal is low, but while it's high it relies on the clamp diode carrying up to 0.9 mA into the 3.3 V rail, which the datasheet must allow and the rail must absorb.
Answer 1.8 kΩ over 3.3 kΩ gives 3.24 V and a 25.6 ns rise, drawing about 1 mA while high; a 1.5 kΩ series resistor gives τ = 15 ns but sends up to 0.9 mA through the clamp diode while high.
Worked example
An I²C bus between a 3.3 V and a 5 V device uses a MOSFET level shifter with 10 kΩ pull-ups on each side. With 50 pF on the 5 V side, what's the rise time there, and is it fast enough for 100 kHz I²C (1 µs maximum) and 400 kHz (300 ns)?
Show the solution
- Rise time with 10 kΩ. slightly too slow even for 100 kHz.
- With 4.7 kΩ. A 4.7 kΩ pull-up gives 0.52 µs, fine at 100 kHz.
- For 400 kHz. It needs about 2.2 kΩ or less (0.24 µs), at the cost of more current when the line is low: within the 3 mA I²C devices must sink.
Answer 1.1 µs, slightly too slow even for 100 kHz; 4.7 kΩ (0.52 µs) works at 100 kHz, and 400 kHz needs about 2.2 kΩ or less.
Check
An output guaranteed at 2.9 V high while sourcing 10 mA drives an LED with 1.8 V across it. What series resistor sets that current?
Write units the way you normally would: 1.5 Ω, 1500 mΩ and 0.0015 kΩ are the same answer.
Check
A 5 V signal drives a 1.8 V chip's input through a series resistor. The clamp diode conducts at 0.3 V above the supply, and the datasheet allows 2 mA of injection. What's the smallest safe resistor?
Write units the way you normally would: 1.5 Ω, 1500 mΩ and 0.0015 kΩ are the same answer.
Check
A 5 V signal drives a divider of 1.8 kΩ over 2.2 kΩ into an input with 22 pF.
(a)
What's the high level at the input?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
(b)
What's its 10 to 90% rise time?
Check
A driver guarantees = 2.9 V and = 0.5 V; the receiver needs = 2 V and = 1.5 V. What's the high-level noise margin? (Negative means it fails.)
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
Check
An output can sink 8 mA low and source 1 mA high. Each input it drives draws 0.1 mA low and 40 µA high. How many inputs can it drive?
Check
A pull-up of 4.7 kΩ charges a bus of 50 pF. What's the 10 to 90% rise time, in µs?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A 3.3 V FPGA must drive a 5 V 74HC-family counter's clock input. Which fix is cleanest?
Check
Choose a divider from E24 values (10, 11, 12, 13, 15, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 43, 47, 51, 56, 62, 68, 75, 82, 91, times any power of ten from 100 Ω to 1 MΩ) that brings Vin = 12 V down to at most Vout_max = 3.3 V and as close as possible to Vout = 3 V, with Thevenin resistance at most Rmax = 50 kΩ. Set R1, R2 (ohms) and v (the output voltage). Break ties by the smaller Thevenin resistance.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
A 5 V Arduino's output is wired straight to a 3.3 V sensor's input. The sensor works, but its 3.3 V rail measures 3.6 V whenever the Arduino's output is high and the sensor's own regulator is lightly loaded. Explain what's happening and how to fix it.
When the 5 V output goes high, the sensor's input protection diode to its 3.3 V rail conducts, so the output pushes current through the diode into the sensor's supply. If the rest of the circuit draws less than that current, the regulator can't sink it (most regulators only source), so the rail rises toward 5 V minus a diode drop, here 3.6 V. That stresses the sensor and anything else on the rail, and if the sensor is unpowered, it can power it through the pin. The fix is to limit or remove the injection: a series resistor sized to keep the current within the datasheet's limit, a divider that scales 5 V to about 3.2 V, or a level-shifter buffer powered from 3.3 V with 5 V-tolerant inputs.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.