Setup and Hold Time, Explained with Verilog and a Little Maths
What setup and hold constraints really mean, how to derive them, and how they show up in your RTL. A practical guide for VLSI beginners.
Every synchronous digital circuit makes one promise: data will be stable when the clock edge arrives. Setup and hold times are the two numbers that define what “stable” means. Get them wrong and your chip works in simulation but fails on silicon.
The flip-flop’s view of the world
A D flip-flop samples its input on the rising clock edge. To sample reliably, the input must be:
- stable for at least \(t_{setup}\) before the edge (setup time), and
- stable for at least \(t_{hold}\) after the edge (hold time).
If data changes inside that window, the flop can go metastable: its output hovers between 0 and 1 for an unpredictable time before resolving.
A register-to-register path
Consider two flops, FF1 (launch) and FF2 (capture), with combinational logic between them.
module reg2reg (
input wire clk,
input wire [7:0] a, b,
output reg [8:0] sum_q
);
reg [7:0] a_q, b_q;
// Launch flops (FF1)
always @(posedge clk) begin
a_q <= a;
b_q <= b;
end
// Combinational logic + capture flop (FF2)
always @(posedge clk)
sum_q <= a_q + b_q; // adder delay sits between FF1 and FF2
endmodule
The adder’s delay, \(t_{comb}\), is the quantity timing analysis cares about.
Deriving the setup constraint
Data launched at one edge must arrive at FF2 at least \(t_{setup}\) before the next edge. With clock period \(T\), clock-to-Q delay \(t_{cq}\) and clock skew \(t_{skew}\) (capture clock arrival minus launch clock arrival):
\[t_{cq} + t_{comb,max} + t_{setup} \le T + t_{skew}\]Rearranging gives the maximum clock frequency:
\[f_{max} = \frac{1}{t_{cq} + t_{comb,max} + t_{setup} - t_{skew}}\]Setup slack is the margin left over. Negative slack means the path is too slow.
Deriving the hold constraint
Hold is about the same edge. New data launched by FF1 must not reach FF2 so fast that it corrupts the value FF2 is still capturing:
\[t_{cq} + t_{comb,min} \ge t_{hold} + t_{skew}\]Notice that \(T\) does not appear. You cannot fix a hold violation by slowing the clock. That is why hold failures are so dangerous: they make a chip fail at every frequency.
A worked example
| Parameter | Value |
|---|---|
| \(t_{cq}\) | 80 ps |
| \(t_{setup}\) | 50 ps |
| \(t_{hold}\) | 30 ps |
| \(t_{comb,max}\) | 620 ps |
| \(t_{comb,min}\) | 40 ps |
| \(t_{skew}\) | 20 ps |
Setup: \(80 + 620 + 50 - 20 = 730\) ps, so \(f_{max} \approx 1.37\) GHz.
Hold: \(80 + 40 = 120 \ge 30 + 20 = 50\) ps. Hold slack is 70 ps, so this path is safe.
How tools fix violations
| Violation | Typical fixes |
|---|---|
| Setup | Pipeline the logic, upsize cells, use faster (low-Vt) cells, restructure logic, reduce useful skew |
| Hold | Insert delay buffers on the short path, adjust skew |
Key takeaways
- Setup depends on the longest path and the clock period.
- Hold depends on the shortest path and is independent of the clock period.
- Skew helps setup and hurts hold when the capture clock arrives late, and the reverse when it arrives early.
In a future post we’ll look at how STA tools like OpenSTA and PrimeTime report these paths, and how to read a timing report line by line.