Whiteboard RTL questions test whether you think in hardware, not whether you've memorized syntax. This lesson gives you eight high-frequency patterns with code, diagrams, and how to talk through each one aloud — the narration matters as much as the answer.
Rule → Code → Why → Trap. Say the rule first ("blocking in sequential logic causes races"), write the fix, explain synthesis behavior, name the common mistake. Thirty seconds of reasoning beats three minutes of silent typing.
| Pattern | Frequency | Course lesson | I2C tie-in |
|---|---|---|---|
| Blocking vs non-blocking | Very high | blocking-vs-nonblocking | Bit engine counter uses <= |
| Latch inference | Very high | latch-combo-multidrive | CSR read in always @(*) |
| FIFO full/empty | High | sync-fifo | TX queue extension for I2C |
| CDC 2-FF | High | cdc-sync-structures | sda_i synchronizer gap |
| FSM safe default | High | safe-fsm-design | Byte FSM ABORT → IDLE |
| Counter / modulo | Medium | counters | CLKDIV bit timing |
| Priority mux / arbiter | Medium | arbiters | Multi-master bus (extension) |
| Setup / hold | Medium | clocks-setup-hold | ACK sample on SDA |
Question: "What's wrong with this counter? Fix it."
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count = 0; // blocking
else
count = count + 1; // blocking — sim race, wrong synthesis intent
end
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count <= 8'd0;
else
count <= count + 8'd1;
end
"In sequential always blocks I use non-blocking assignment. Blocking evaluates immediately in source order — two registers updating each other in one clock can race in simulation. Non-blocking schedules all RHS reads before any LHS writes — that's the hardware model: all flops sample, then all update."
Using <= in combinational always @(*) is also wrong — use blocking = there. Rule: blocking in combo, non-blocking in seq.
Question: "Will this infer a latch? Fix it."
always @(*) begin
if (enable)
out = in;
// else missing — out holds previous value → LATCH
end
always @(*) begin
out = 8'd0; // default — no latch
if (enable)
out = in;
end
"A latch is transparent when enable is high — synthesis infers it when a combinational output isn't assigned in every branch. I default all outputs at the top of always @(*), or use if/else if/else covering all cases. In sequential logic, every reg gets assigned every clock — that's a flop, not a latch."
Question: "Design a synchronous FIFO with full and empty flags."
// Pointer + count approach (DEPTH must be power of 2 for ptr wrap)
localparam PTR_W = $clog2(DEPTH);
reg [PTR_W:0] wr_ptr, rd_ptr; // extra bit for full/empty discrimination
wire [PTR_W:0] count = wr_ptr - rd_ptr;
assign empty = (count == 0);
assign full = (count == DEPTH);
assign wr_en_ok = wr_en && !full;
assign rd_en_ok = rd_en && !empty;
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
wr_ptr <= 0;
rd_ptr <= 0;
end else begin
if (wr_en_ok) wr_ptr <= wr_ptr + 1;
if (rd_en_ok) rd_ptr <= rd_ptr + 1;
end
end
"Same clock domain — I use write and read pointers plus a count or MSB trick. Empty when pointers equal, full when write has lapped read. I gate wr_en when full and rd_en when empty to prevent corruption. For async FIFO I'd need gray pointers — different question, see our CDC lesson."
Using only lower bits of pointers without the extra MSB — you can't distinguish full from empty when both pointers are equal. See sync FIFO lesson.
Question: "Cross a single-bit control from clk_a to clk_b. Why not synchronize a 32-bit bus this way?"
module sync_2ff (
input wire clk_dst,
input wire rst_n,
input wire async_in, // from other clock domain
output wire sync_out
);
(* ASYNC_REG = "TRUE" *) reg meta, sync;
always @(posedge clk_dst or negedge rst_n) begin
if (!rst_n) begin meta <= 1'b0; sync <= 1'b0; end
else begin meta <= async_in; sync <= meta; end
end
assign sync_out = sync;
endmodule
"For a single control bit I use two flops on the destination clock — first may go metastable, second samples a settled value. Never synchronize a multi-bit bus with independent 2-FF chains — bits can skew across cycles and you'll read garbage. Use gray-code pointers in async FIFO, or a handshake with req/ack. That's exactly the gap I'd fix on sda_i in my I2C capstone."
Deep dive: CDC don'ts — bus vs gray and multi-clock mindset.
Question: "Write a Moore FSM with safe recovery from illegal states."
typedef enum logic [1:0] { IDLE, LOAD, RUN, DONE } state_t;
state_t state, next;
always @(posedge clk or negedge rst_n) begin
if (!rst_n) state <= IDLE;
else state <= next;
end
always @(*) begin
next = IDLE; // safe default — any unhandled state recovers
case (state)
IDLE: next = start ? LOAD : IDLE;
LOAD: next = RUN;
RUN: next = done_flag ? DONE : RUN;
DONE: next = ack ? IDLE : DONE;
default: next = IDLE; // synthesis + sim safety net
endcase
end
"I default next_state to IDLE at the top — if state is corrupted or I add a new state and forget a branch, the FSM recovers instead of latching in an illegal encoding. My I2C byte FSM does the same: ABORT from any state forces IDLE. Two always blocks: one seq for state reg, one combo for next — classic Moore style from our FSM lessons."
See safe FSM design and your I2C byte FSM.
Question: "Build a counter that counts 0 to N-1 then wraps."
module modulo_counter #(
parameter int MAX = 8 // counts 0 .. MAX-1
) (
input wire clk,
input wire rst_n,
input wire en,
output reg [$clog2(MAX)-1:0] count
);
localparam int LAST = MAX - 1;
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count <= 0;
else if (en) begin
if (count == LAST)
count <= 0;
else
count <= count + 1;
end
end
endmodule
"Compare to LAST, wrap to zero — that's the I2C CLKDIV pattern. Width is $clog2(MAX) bits. If MAX isn't power of two, this compare-wrap is cleaner than modulo operator which some synthesis tools handle poorly. I'd mention the I2C bit engine counts down from CLKDIV to zero — same idea, different direction."
Off-by-one: counting 0..N instead of 0..N-1. Always state inclusive range aloud in the interview.
Question: "Four requesters, one grant — fixed priority."
module priority_arb (
input wire [3:0] req,
output reg [3:0] gnt
);
always @(*) begin
gnt = 4'b0000;
if (req[0]) gnt = 4'b0001; // highest priority
else if (req[1]) gnt = 4'b0010;
else if (req[2]) gnt = 4'b0100;
else if (req[3]) gnt = 4'b1000;
end
endmodule
"Fixed priority is a priority encoder — lowest index wins. One-hot grant, at most one bit set. For fairness I'd use round-robin from our arbiter lesson. Multi-master I2C would need bus arbitration — check SDA high before START — that's the protocol version of this pattern."
Extension: arbiters lesson.
Question: "Explain setup and hold. What happens if you violate them?"
Talk track: "Setup: data must be stable before the clock edge by tsu. Hold: data must stay stable after the edge by th. Violate either and the flop may go metastable — output hovers between 0 and 1, then resolves randomly. That's why we don't sample async pads blindly — my I2C ACK sample happens when SCL is stable high, giving implicit setup."
Course links: clocks setup hold, critical path intuition.
Don't start typing code immediately. Pause, restate the question, say "I'll use a two-always-block Moore FSM with safe default" — then write. Interviewers score process.
Question: "Why sync reset deassert? Show the circuit."
// Async assert (immediate) + sync deassert (avoid reset removal metastability)
module reset_sync (
input wire clk,
input wire rst_n_async, // from pad — may be async
output wire rst_n_sync
);
(* ASYNC_REG = "TRUE" *) reg r1, r2;
always @(posedge clk or negedge rst_n_async) begin
if (!rst_n_async) begin r1 <= 1'b0; r2 <= 1'b0; end // async assert
else begin r1 <= 1'b1; r2 <= r1; end // sync deassert
end
assign rst_n_sync = r2;
endmodule
"Assert async so reset works even if clock is dead. Deassert synchronously — releasing reset near a clock edge can cause metastability in downstream flops. Two-flop chain on deassert is standard ASIC practice." Tie to reset synchronizers lesson.
| Level | Patterns | When asked |
|---|---|---|
| Junior | Blocking/NB, latch fix, counter, FSM default | Phone screen, new grad onsite |
| Junior+ | FIFO flags, 2-FF sync, priority arb, setup/hold | Technical round 1–2 |
| Mid | Gray async FIFO, pipeline hazard, multi-clock handshake | After 2+ yr experience |
After this course you're solid on the Junior column. Junior+ is reachable with deliberate practice — that's your 30-day goal from 12.4.