Synthesis tools are picky parsers with a netlist printer attached. The habits you build now — full case, one driver per signal, sync resets, no # delays — are what separate "it simulates" from "it ships."
Write RTL as if a human reviewer and a lint tool will read it tomorrow. Clarity is not optional — ambiguous code becomes ambiguous gates.
Good style reduces surprise between simulation and synthesis.
| Habit | Synthesizer loves | Synthesizer hates |
|---|---|---|
| case statements | case + default (full) | Missing default → latch inference |
| Constants | localparam / parameter | Magic numbers scattered in code |
| Assignments | One driver per signal | Multiple always driving same reg |
| Timing | always @(posedge clk) | #10 delays in RTL |
| Resets | Sync or async — but consistent | Mixing styles randomly per flop |
In combinational always @(*) or case, every output must have a defined value for every input combination. Missing branches infer latches.
// BAD — latch inferred when sel=2'b11
always @(*) begin
case (sel)
2'b00: out = a;
2'b01: out = b;
2'b10: out = c;
// no default — out holds previous value → latch
endcase
end
// GOOD — full case with safe default
always @(*) begin
case (sel)
2'b00: out = a;
2'b01: out = b;
2'b10: out = c;
default: out = {WIDTH{1'b0}}; // or explicit 2'b11 branch
endcase
end
casez / casex with don't-cares can hide coverage holes. In RTL, prefer full binary case unless you truly need priority encoding and document it.
// BAD if (state == 3'd5) next_state = 3'd7; // GOOD localparam ST_IDLE = 3'd0; localparam ST_READ = 3'd1; localparam ST_WRITE = 3'd2; localparam ST_DONE = 3'd3; if (state == ST_READ) next_state = ST_WRITE;
Magic numbers are like unlabeled buttons in a cockpit. localparam names are the labels — future you (and lint) will thank you.
Every wire or reg should be assigned in exactly one place. Multiple drivers create multiply-driven nets — synthesis errors or silicon fights.
One always @(posedge clk) block owns all sequential outputs in a module section.
Two separate always blocks both assigning count <= ... — illegal for synthesis.
// GOOD — single sequential block owns state
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
count <= 8'd0;
done <= 1'b0;
end else begin
if (en) count <= count + 8'd1;
done <= (count == MAX);
end
end
Default to always @(posedge clk) with non-blocking <= for registers. Reserve blocking = for combinational always @(*).
Hard rule: Never put # delay literals in modules targeted for synthesis. Delays are for testbench timing only — they do not become physical delay elements in modern ASIC/FPGA flows.
| Construct | RTL (synth) | Testbench (sim) |
|---|---|---|
#N delay | Forbidden | Clock generation, stimulus spacing |
initial | Reset/config only (tool-dependent) | Stimulus, $finish |
posedge clk | Primary sequential template | Also used in TB sync |
State machines are everywhere. The style you learn now carries into Module 4's deep FSM lessons: two-process or one-process — but always named states and full transitions.
localparam S_IDLE = 2'd0, S_RUN = 2'd1, S_DONE = 2'd2;
reg [1:0] state, next_state;
// Sequential: state register only
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= S_IDLE;
else state <= next_state;
// Combinational: next-state logic — full case!
always @(*) begin
next_state = S_IDLE; // default assignment prevents latch
case (state)
S_IDLE: next_state = start ? S_RUN : S_IDLE;
S_RUN: next_state = done ? S_DONE : S_RUN;
S_DONE: next_state = ack ? S_IDLE : S_DONE;
default: next_state = S_IDLE;
endcase
end
Use localparam state encodings. Assign a default next_state before the case. Document unreachable states. Avoid overlapping state bit patterns.
| Topic | Bad | Good |
|---|---|---|
| Reset | Some flops async, some sync, undocumented | One reset policy per module, documented header comment |
| Widths | assign y = a + b; (implicit widths) | assign y = a + b; with declared widths + overflow plan |
| Combo logic | Missing default in if/else chain | Default else branch or default assignment at top |
| File split | TB initial mixed into DUT | dut.v + dut_tb.v separation |
| Comments | "Fix later" with no ticket | Header: clock, reset type, interface protocol |
// uart_tx_byte — byte serializer // Clock: 50 MHz, sync active-low reset // Interface: valid/ready handshake on byte_in // States: IDLE → SHIFT → DONE (see fsm_preview pattern) module uart_tx_byte ( input wire clk, input wire rst_n, // ... );
case has default or is provably full# delays, $display, or TB tasks in synth fileslocalparam names<=; combo blocks use =Module 4 preview: You have the Verilog vocabulary. Next we build real blocks — decoders, muxes, counters, and full FSMs — using these style rules as non-negotiable defaults.
case + default prevents accidental latches.# delays in RTL; sync style is the default.