class: center, middle, inverse, title-slide .title[ # Milestone: Traffic Light Controller ] .subtitle[ ## Programmable Electronics — Unit 2 ] .date[ ### Class 19 ] --- # Learning Targets .lt-box[ - Read a three-block design — clock, sequencer, output logic — and explain what each block takes in and puts out before wiring any of it. - Choose a clock period and a step count that produce a defensible red/green/yellow timing, and justify the `\(R\)` and `\(C\)` that give it. - Combine counter outputs with OR gates so one lamp stays on across several steps. - Bring up a multi-chip circuit one subsystem at a time, verifying each before adding the next. ] .eu-label[Essential Understanding:] Nobody designs a circuit this size one wire at a time. You design it as a few blocks that each do one nameable job, decide what passes between them, and only then open the blocks up. That habit is the difference between a build you can debug and a build you have to throw away — and it is the same move you made when the half adder became a box. --- # Agenda .agenda-box[ 1. The whole unit, in one circuit 2. Three blocks 3. The design problem: one-hot vs. a lamp that stays on 4. The phase table, and the gates that fall out of it 5. Choosing the clock 6. How this is graded 7. **Build day** — most of the period 8. Where you should be by the bell ] --- # The whole unit, in one circuit - **Class 11:** a transistor switching on a yes/no input — what a gate physically *is*. - **Class 16:** the 74HC chip, the datasheet, pin 1, the decoupling cap, and clean logic levels. - **Class 17:** gates combined into a block with one job, verified once by its truth table and then trusted. - **Class 12:** the 555 astable — a clock, from one formula and three parts. - **Class 18:** the 4017 — a chip that *remembers*, turning ticks into steps, and the reset trick that sets the step count. Today all five become an intersection that runs itself. **No microcontroller. No code.** Every decision in it is a wire you placed. --- # Three blocks .center[ <img src="assets/schematics/traffic-light-blocks.svg" alt="Block diagram: a 555 astable producing about one tick per second feeds the clock of a 4017, whose step outputs Q0 to Q5 feed 74HC32 OR gates that drive red, green and yellow LEDs; Q6 returns to the 4017 master reset" style="max-height:330px;"/> ] .font-small[ **555 astable** — how fast does time pass? · **4017** — which step are we on? · **74HC32** — which lamp does that step mean? Three questions, three blocks, and exactly **two** wires between them. Name what crosses each boundary before you wire anything. ] --- # The design problem The 4017 is **one-hot**: exactly one output HIGH, all the others LOW. But a traffic light is not one-hot. **Red stays on for several steps in a row.** .pull-left.w48[ So there's a gap between what the counter gives you — *"we are on step 2"* — and what the lamps need — *"red should be lit."* ] .pull-right.w48[ You already own the part that closes it. **Red is lit on step 0 OR step 1 OR step 2.** Say that sentence again and listen to the word in the middle. That's a gate, and it's in your kit. ] .emphasis-center[ This is the first time you use a gate to **shape** a signal rather than to answer a question. ] --- class: small-font # The phase table Six steps. Decide what each one means, and the wiring falls out of the table: | step | counter output | lamp | why | |---|---|---|---| | 0 | Q0 | **RED** | | | 1 | Q1 | **RED** | red gets three steps — the longest phase | | 2 | Q2 | **RED** | | | 3 | Q3 | **GREEN** | | | 4 | Q4 | **GREEN** | green gets two | | 5 | Q5 | **YELLOW** | yellow gets one — the shortest, always | | 6 | Q6 | *(nothing)* | **wired to MR** — the instant it goes high, the count snaps back to step 0 | Read the lamp column upward and the logic is already written: `$$\text{RED} = Q_0 + Q_1 + Q_2 \qquad \text{GREEN} = Q_3 + Q_4 \qquad \text{YELLOW} = Q_5$$` .font-small[ In logic notation `+` means **OR**, not addition. One lamp, several steps. ] --- class: small-font # The output logic .pull-left.w52[ <img src="assets/schematics/traffic-light-logic.svg" alt="Counter outputs Q0 to Q5 entering OR gates: Q0 and Q1 into one gate, its output and Q2 into a second, driving the red LED through 1 kohm; Q3 and Q4 into a third gate driving green; Q5 into both inputs of a fourth gate driving yellow" style="width:100%;max-height:350px;"/> ] .pull-right.w44[ - OR gates take **two** inputs, so three-input RED needs **two of them, cascaded**: *Q0 + Q1* first, then that result *+ Q2*. - GREEN is a plain two-input OR. **Two gates + one gate = three.** A 74HC32 has four. - **YELLOW needs no OR at all** — but don't run it straight off the 4017. Feed Q5 into **both inputs of the leftover gate**. *Q5 + Q5 = Q5*, so the logic is unchanged, and now all three lamps are driven by the same kind of output at the same strength. A gate used this way is a **buffer**. - **1 kΩ** per lamp. A 74HC output only sources about **4 mA** (Class 16), so expect honest but modest brightness. Making them bright is an optional upgrade — you have known how since Class 9. ] --- class: small-font # Choosing the clock One 555 astable sets how long **one step** lasts. Everything else is a multiple of it. Your Class 12 baseline — `\(R_A = 10\ \text{k}\Omega\)`, `\(R_B = 100\ \text{k}\Omega\)`, `\(C = 10\ \mu\text{F}\)` — gives: `$$f = \frac{1.44}{(R_A + 2R_B)C} = \frac{1.44}{(210\,\text{k})(10\,\mu\text{F})} \approx 0.69\ \text{Hz} \qquad T \approx 1.46\ \text{s per step}$$` So: red ≈ 4.4 s, green ≈ 2.9 s, yellow ≈ 1.5 s, full cycle ≈ 8.7 s. - That is a **defensible** traffic light and it uses parts already on your board. Use it, or change it — but if you change it, **calculate it and justify it.** - Faster is easier to demo; slower is more realistic. Yellow is the one phase a real engineer is not free to shorten, and you should be able to say why. - **The duty cycle does not matter here.** The 4017 counts *edges*, not how long the clock sits high. This is the first time that lever from Class 12 is irrelevant — notice that, and know why. --- class: small-font # How this is graded The same five dimensions as every milestone, still with no code: - **Function** — does it cycle red → green → yellow → red, on its own, repeatably? - **Circuit craft** — legible wiring across three chips, both decoupling caps fitted, no floating inputs, correctly sized resistors. - **Documentation** — your phase table, your clock calculation, and a schematic another student could build from. - **Diagnosis** — one failure, how you found it, how you fixed it. Graded **even if it worked first time**; if it did, write down what you checked to make sure. .font-small[ Two days: today is design and bring-up, next class is finish, demo, and the Great Chip Count. A circuit that isn't working yet at the bell today is exactly on schedule. ] --- class: small-font # Traffic Light Controller — grading points | | Points | |---|---| | **Minimum build** — all three lamps, correct order, cycles on its own, documented and demoed | **24,000** | | A **pedestrian button** that does something defensible (you built a one-shot last class) | **+3,000** | | Lamps **buffered with transistors** so they're properly bright, sized and justified | **+2,000** | | Clean schematic of *your* build, phase table and clock calculation included | **+3,000** | | Social-media-style video explaining how it works | **up to +4,000** | | **Maximum** | **36,000** | .font-small[ The minimum build is the whole milestone — the add-ons stack on top. A pedestrian button only counts if you can explain what it does to the sequence and why that is or isn't how a real crossing behaves. ] --- class: center, middle # Build day Most of the period is yours. One block at a time. --- class: small-font # Bring-up order — do not skip ahead Three chips is enough that "wire it all and hope" does not work. Build **one block, verify it, then add the next.** Each step below has a test you must pass before moving on. 1. **Write your phase table first**, in your notebook, before any wire. Six rows. Decide the lamp for each step and which output goes to MR. Everything after this is just executing it. 2. **Power rails and chips.** Seat the 4017 and the 74HC32, pin 1 at the notch, Vdd/Vcc and GND to the rails, **a 0.1 µF decoupling cap across each chip's own supply pins.** Tie INH to ground. **Test:** measure the supply at the far corner of each chip — 6 V, both of them. *(Debug Ladder rung 1, and you do it now rather than after everything is wired.)* 3. **The clock, alone.** Build the 555 astable and put an LED on OUT. **Test:** it blinks, at about the rate you calculated. Do not proceed past a clock you haven't watched. 4. **The counter, with the clock.** 555 OUT → 4017 CLK. Put an LED on Q0 and another on Q1. MR to ground for now. **Test:** the two LEDs take turns, one step apart. Then wire **Q6 → MR** and confirm the cycle shortens to six steps. 5. **One lamp.** Wire only the RED chain: Q0 and Q1 into a gate, that output and Q2 into a second, out to the red LED through 1 kΩ. **Test:** red is on for three steps out of six, off for three. 6. **The rest.** Add GREEN, then YELLOW through the buffer gate. **Test:** the full cycle, in order, repeating. 7. **Document as you go** — phase table, clock calculation, schematic, and a note every time something didn't work and what you did about it. That last one is a graded dimension, and it is unrecoverable if you write it from memory tomorrow. --- class: center, middle # Where you should be by the bell .emphasis[ A **clock you have watched blink** and a **counter you have watched step.** ] The output logic is the easy half, and it is impossible to debug on top of a clock or a counter you never verified. If you have those two working, you are on schedule — even with no lamps lit yet. Label your board, leave it assembled, and write down the last thing you were doing.