class: center, middle, inverse, title-slide .title[ # Combinational Logic — the Half Adder ] .subtitle[ ## Programmable Electronics — Unit 2 ] .date[ ### Class 17 ] --- # Learning Targets .lt-box[ - Derive the truth table for adding two 1-bit numbers, and identify which output is the sum and which is the carry. - Explain why SUM = A XOR B and CARRY = A AND B, checking each against the table. - Build a half adder from XOR and AND gates and verify its full truth table by measurement. - Read a two-gate circuit as one block with a single combined truth table. ] .eu-label[Essential Understanding:] Wire a few gates together and their combined truth table can look like arithmetic — a circuit that adds. Nothing was added to make it "know" addition; adding is just what that particular tangle of gates *does*. This is the last time in the course you'll see the logic completely exposed. After today, chips hide it. --- # Agenda .agenda-box[ 1. Review: gates and truth tables 2. Adding two bits — build the table first 3. Which gates make that table? 4. The half adder as one block 5. **Build (25 min):** wire and verify a half adder 6. What the half adder can't do 7. Homework ] --- # Review - A **gate** turns input voltages into an output voltage by a fixed rule. Its **truth table** is the whole rule. - You've built gates two ways now — from transistors (Class 11) and from a 74HC chip (Class 16). - **XOR** — output 1 when the two inputs **differ**. - **AND** — output 1 only when **both** inputs are 1. - Same moves as the Class 16 build — decouple, switched inputs, tie off unused inputs, read outputs with the multimeter — two chips instead of one. --- class: small-font # Adding two bits In binary, one bit plus one bit: `$$0+0 = 0 \qquad 0+1 = 1 \qquad 1+0 = 1 \qquad 1+1 = 10_{\text{two}}$$` That last one needs **two** output bits — a low bit and a high bit. Call the low bit **SUM** and the high bit **CARRY**: <table class="truth"> <tr><th>A</th><th class="dv">B</th><th>CARRY</th><th>SUM</th></tr> <tr><td>0</td><td class="dv">0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td class="dv">1</td><td>0</td><td>1</td></tr> <tr><td>1</td><td class="dv">0</td><td>0</td><td>1</td></tr> <tr><td>1</td><td class="dv">1</td><td>1</td><td>0</td></tr> </table> The bottom row is "carry the one" from first-grade arithmetic — `\(1+1 = 10\)`. --- # Which gates make that table? .pull-left.w52[ - Look at the **SUM** column: `0, 1, 1, 0` — output 1 exactly when the inputs **differ**. That's **XOR**. - Look at the **CARRY** column: `0, 0, 0, 1` — output 1 exactly when **both** inputs are 1. That's **AND**. ] .pull-right.w44[ `$$\text{SUM} = A \oplus B$$` `$$\text{CARRY} = A \cdot B$$` ] We didn't design this — we *read it off the table*. Any truth table can be built from gates this way. --- # The half adder .pull-left.w48[ <img src="assets/schematics/half-adder-gates.svg" alt="A and B each feeding an XOR gate producing SUM and an AND gate producing CARRY" style="width:100%;max-height:250px;"/> ] .pull-right.w48[ <img src="assets/schematics/half-adder-block.svg" alt="The same circuit drawn as a single box labelled half adder with inputs A, B and outputs SUM, CARRY" style="width:100%;max-height:200px;"/> ] A and B each go to **both** gates. Two gates, one behavior. The box on the right has the **same truth table** as the gates on the left — that's what **combinational** means, and it's how you'll think about the 555 and the 4017 in the classes ahead. --- class: small-font # Build instructions Breadboard, 6 V pack, **74HC86** (quad XOR) **and 74HC08** (quad AND), **two** 0.1 µF caps, 2-way DIP switch, two 10 kΩ resistors, two LEDs + two 470 Ω, multimeter. 1. Seat both chips. **Decouple both** — a 0.1 µF across each chip's power pins. 2. Inputs **A** and **B** from the DIP switch, each with a 10 kΩ pull-down to ground (same as last class). 3. Route A and B to **one XOR gate's two inputs** and **one AND gate's two inputs**. 4. XOR output → **SUM** LED (through 470 Ω). AND output → **CARRY** LED. 5. **Tie off every unused input** on both chips. 6. Step through all four A, B combinations. Record SUM and CARRY (voltage + LED) for each row. Fill in the table. 7. Check against your prediction — especially **A = 1, B = 1 → SUM = 0, CARRY = 1**. That's "carry the one," in silicon. --- # What the half adder can't do - It has **no carry *in*** — nowhere to feed a carry from a previous column. So you can't chain half adders to add multi-bit numbers. - Add a third input (carry-in) and you get a **full adder**: two half adders and an OR gate. - A chain of full adders adds numbers of any width. A 64-bit processor has **64 of them** in a row, plus tricks to hurry the carry along. - We won't build the full adder — but notice: it's *still just gates*. All the way up. --- class: center, middle # Homework .hw-box[ - Draw the block diagram for adding two **2-bit** numbers using half and/or full adders. How many carry wires are there? - In your own words: the half adder was never "programmed" to add. **What makes it add?** Answer in terms of the truth table. - One or two sentences for the unit's essential question: the half adder shows the logic completely. Next class the 555 hides comparators and a latch you never see. **What do you gain by letting the chip hide it, and what do you lose?** ]