Barcelona Abroad · Week 1 · Day 4  🤖 AI thread starts

Clocked Logic & RTL Thinking

CRAFT cycle · 2.5 hours · Fri 5/29 · Week 1 close

HDL for Digital System Design · UCF ECE · Barcelona Summer 2026

CRAFT

Today at a Glance

PhaseTimeActivity
🌍 Contextualize10 minBarcelona clocked systems · Sagrada photos recap
⚠️ Reframe15 minposedge · <= vs = · RTL = count the assigns
🛠 Assemble70 minD-FF · loadable register · counter · LED blinker from 25 MHz
🛡 Fortify45 minSim + GTKWave · AI sanity check · on-board verify
🔗 Transfer10 minWeek 1 recap · weekend video (D5+D6 merged)
New today: 🤖 Check the Machine. First time we ask an AI to explain a concept and grade the explanation.

▸ Phase 1 of 5  ·  ~10 min

🌍 Contextualize

Barcelona on a clock

The City on a Clock Edge

  • L3 metro train arrivals — every few minutes, on a schedule
  • Traffic light cycles — green/amber/red on a fixed period
  • BCN airport departure board — repaints every second
  • Mercat Boqueria butcher — "next!" — a state machine running at human cadence

Yesterday's combinational logic had no notion of "when." Today: time itself becomes an input.

Sagrada photos

Project a few student photos from yesterday. Ask: "Where in the basilica do you see something that has memory of what came before?" Spoiler: almost nothing. The shape is combinational. Today we add the parts that do remember.

▸ Phase 2 of 5  ·  ~15 min

⚠️ Reframe

The one rule that prevents almost every Day-4 bug

⚠️ Order Doesn't Mean Order

❌ Wrong Model

"Lines inside always @(posedge clk) execute top-to-bottom, like statements in a function."

✓ Right Model

Every assignment in an always @(posedge clk) describes what happens on a single clock edge, all at once. The order of nonblocking (<=) assignments doesn't change the hardware.

Combinational? Use = in always @(*).
Sequential? Use <= in always @(posedge clk).
Don't mix them in the same block.

Blocking vs. Nonblocking — the Picture

Blocking (=) assignments update immediately and in order, chaining within a clock edge; nonblocking (<=) assignments all sample their right-hand sides first, then update together at the edge — which is what real flip-flops do
Two stacked <= updates (q2 <= q1; q1 <= d;) shift data one stage per edge — a real shift register. Swap to = and q2 grabs the new q1, collapsing the pipeline. This is why <= is the rule in clocked blocks.

RTL: Count the Flip-Flops

always @(posedge clk) begin
    if (rst) begin
        q1 <= 0;        // ← FF #1
        q2 <= 0;        // ← FF #2
        cnt <= 0;       // ← FFs (one per bit of cnt)
    end else begin
        q1  <= d;
        q2  <= q1;      // shift-register stage
        cnt <= cnt + 1;
    end
end

Three <= targets ⇒ three storage elements. cnt is N flip-flops where N = bit-width.

This is RTL thinking: read your code, and see the flops before you synthesize.

▸ Phase 3 of 5  ·  ~70 min  ·  You build

🛠 Assemble

From one FF to a visible blinker

Build Plan

  1. Ex 1 · 15 min  D flip-flop — synchronous reset, posedge-only update. Sim first.
  2. Ex 2 · 15 min  Loadable register — add en and load. Implicit feedback when disabled.
  3. Ex 3 · 15 min  Free-running counter — N-bit up-counter with terminal-count output.
  4. Ex 4 · 20 min  LED blinker — clock divider — 25 MHz ÷ 25 000 000 = 1 Hz. The first design where you can see hardware time.
Stretch (Ex 6): Up/down counter on the 7-seg from yesterday. Composes Day 2 + Day 4.

D Flip-Flop — Canonical Form

module dff (
    input  wire clk, rst, d,
    output reg  q
);
    always @(posedge clk) begin
        if (rst) q <= 1'b0;
        else     q <= d;
    end
endmodule

Three lines of behavior. One flip-flop in the netlist. This is the atom of all sequential logic.

On the board: tie d to a button, clk to the 25 MHz pin. The LED reflects the button — but only at clock edges. Press fast — see the sampling.

LED Blinker — Hardware Time

module blinker (
    input  wire clk,            // 25 MHz from Go Board
    output reg  led
);
    localparam HALF_PERIOD = 12_500_000;   // 0.5 s
    reg [23:0] cnt;

    always @(posedge clk) begin
        if (cnt == HALF_PERIOD - 1) begin
            cnt <= 0;
            led <= ~led;
        end else begin
            cnt <= cnt + 1;
        end
    end
endmodule

24-bit counter (224 = 16 777 216 > 12 500 000). The toggle pattern is the canonical "slow event from a fast clock."

▸ Phase 4 of 5  ·  ~45 min  ·  Verify · waveform · AI check

🛡 Fortify

Sequential logic earns sequential proof

Sim First — Waveforms Tell the Truth

cd labs/week1_day04/ex1_dff/starter
iverilog -o dff_tb dff.v dff_tb.v
vvp dff_tb           # generates dump.vcd
gtkwave dump.vcd     # add clk, d, q to viewer
  • Does q change only on the rising edge of clk? Look — don't assume.
  • Does q sample the value of d at the edge, not before or after?
  • Does reset force q low immediately on the next edge?
  • For the blinker: shrink HALF_PERIOD to 5 in sim — watch the counter wrap and the LED toggle.
If it doesn't blink in simulation, it won't blink on hardware.

🤖 Check the Machine (first time!)

Prompt: Ask an AI (ChatGPT, Claude, Copilot — pick one) to explain the difference between blocking (=) and nonblocking (<=) assignment in Verilog.

  • Does the answer match what you learned? Where exactly is it imprecise?
  • Does it warn about simulation-synthesis mismatch when you mix them?
  • Does it explicitly say: "= in always @(*), <= in always @(posedge clk)"?
  • Save the prompt + reply to your AI workflow portfolio (this is graded — 8% of the course).
The thread: from here on, every week we use AI for something specific and verify what it gave us. Monday's merged D5+6 session, you'll have AI write a full testbench — and then you'll find its bugs.

Hardware Verification

  • D-FF on board: press button rapidly — LED updates only on clock edges (you won't see flicker because 25 MHz >> eye).
  • Loadable register: hold en low → output frozen even when d changes.
  • Counter: wire bottom 4 bits to LEDs (a slow-clock version) — binary count visible.
  • Blinker: ~1 Hz toggle on LED 0. Time it with a phone stopwatch — should be within ±1%.
Dual-speed stretch: two LEDs blinking at different rates from the same counter — one bit toggles fast, one bit toggles slow.

▸ Phase 5 of 5  ·  ~10 min  ·  Week 1 closes

🔗 Transfer

What four days bought you

Week 1 Recap

D1 Concurrent mental model. Toolchain. LED on hardware.

D2 Vectors, muxes, hierarchy. Adder + 7-seg decoder.

D3 Procedural combinational. Latch trap. First PPA compare. ALU.

D4 Clocked logic. RTL counting. You can now build any clocked digital circuit.

Combinational logic + flip-flops = every digital chip ever made.

Weekend → Week 2 Prep

Monday is the merged D5+D6 session — counters + testbenches + the deep dive on AI-assisted verification.

Monday afternoon: Semidynamics visit — RISC-V vector processor startup, RTL meets commercial silicon.

This weekend

  • 📺 Watch D5+D6 pre-class video (~90 min — merged)
  • 📝 D5+D6 pre-class quiz
  • 🇪🇸 Eat well · sleep · Montserrat photos welcome
Reflection prompt: in one sentence, what surprised you most about hardware this week? Bring an answer Monday — we open with them.

🔗 End of Week 1 · Buen fin de semana

You can build any digital circuit.

Four days. Four working boards. One mental model that fits all of hardware.
Week 2: verification, AI, and the visits that show you why this matters.

CRAFT