Setup, Hold and the Clock Period
Check a path between two flip-flops for setup and hold, find its fastest clock, and see what a slower clock cannot fix.
You Will Be Able To
- Describe the setup and hold window of a flip-flop.
- Compute the minimum clock period and the setup slack of a path.
- Compute the hold slack of a path from its fastest delays.
- Choose the right fix for a setup or a hold violation.
- Lesson
- G5.8
- Time
- 30 min
- Runs on
- Your browser
- Check
- 5 questions
A team doubled the clock period of a failing chip in the lab, and one block still failed. Its problem was hold: a path that was too fast, not too slow. No clock frequency could fix it.
- Cycle 0
The input
dchanges well before the edge, so the flop stores the new value, 1. - Cycle 2
A change 1.5 ns before the edge is inside the 2 ns setup time. The model makes q unknown.
- Cycle 3
A change 0.5 ns after the edge is inside the 1 ns hold time: unknown again.
- Cycle 4
From 1 ns after the edge on, the window is closed and the flop keeps the old value, 0.
Measured: the lines the lab prints.
The Setup and Hold Window
A flip-flop needs its input to be stable for a short time around the clock edge. The setup time is how long before the edge; the hold time is how long after. Together they form a window.
Outside the window the flop behaves. It captures the new value if the change came before, and the old value if it came after. Inside, it may go metastable (G5.11).
| SKY130 dfxtp_1, fastest slews | d rising | d falling |
|---|---|---|
| Setup time | 51 ps | 103 ps |
| Hold time | -29 ps | -47 ps |
Read from the pinned SKY130 Liberty file at 0.01 ns clock and data slews. A negative hold time means d may change slightly before the edge. Lesson T2.1 reads the full tables.
The Setup Check and the Clock Period
Data leaves the launch flop at an edge and must reach the capture flop before the next edge, minus setup.
- Clock / reset
- Storage
- Datapath
- Clock
- Data
- Setup: the slow case
Latest arrival t_pcq + t_pd must come before T − t_setup. So T ≥ t_pcq + t_pd + t_setup.
- Hold: the fast case
Earliest arrival t_ccq + t_cd must come after the same edge plus t_hold. T does not appear.
Read the diagram as text
- Clock edge: t = 0
- Launch flop: clock-to-Q t_pcq
- Logic: propagation t_pd
- Capture flop: needs t_setup before T
- Clock edge → Launch flop
- Launch flop → Logic: Q
- Logic → Capture flop: D
The slack of a check is how much time is left over. Negative slack is a violation.
So the shortest period is the slowest path's clock-to-Q, plus its logic, plus setup. A setup violation can always be fixed by a slower clock, or by a faster path.
The Hold Check
Hold looks at the same edge. The new data launched at that edge must not reach the capture flop before its hold time is over. If it does, it overwrites the value being stored.
So hold uses the fastest delays: the contamination clock-to-Q t_ccq and the short path t_cd (G5.1). The check is t_ccq + t_cd ≥ t_hold, and the period is not in it.
That is why a slower clock fixes setup but never hold. A hold violation is fixed by adding delay to the short path, which must not push the long path past setup.
Asked in interviews
Which of setup and hold depends on the clock period?
Setup: data launched at one edge must arrive before the next edge minus setup, so the period is in the check. Hold compares data launched at an edge with the same edge, so the period cancels out.
How do you fix a setup violation, and how a hold violation?
Setup: shorten the long path (logic, faster cells, pipelining) or slow the clock. Hold: lengthen the short path with delay cells, while keeping setup met.
Write the setup and hold equations.
Setup: T ≥ t_pcq + t_pd + t_setup, with skew added on the capture side. Hold: t_ccq + t_cd ≥ t_hold, with skew added to t_hold. Slack is how far each side beats the other.
With skew between the two clocks, both checks shift. That is lesson G5.9, and the STA track continues in T2.1.
Try It
The flop model stores the new value when d changes at least 2 ns before the edge. It keeps the old value when d changes at least 1 ns after. In between, the model gives x.
The boundaries count as safe: a change exactly 2 ns before or exactly 1 ns after is fine. The window widget uses the same rule.
Change TSU to 3.0 and run again. Which lines change?
d rises at -4.0 ns: ok q=1 d rises at -2.0 ns: ok q=1 d rises at -1.5 ns: setup violated q=x d rises at 0.5 ns: hold violated q=x d rises at 1.0 ns: ok q=0 d rises at 3.0 ns: ok q=0Read included file: tb.sv
// tb.sv: d rises at a chosen offset from a clock edge; the bench reports what the flop saw (read-only).
`timescale 1ns/100ps
module tb;
logic clk = 0, d = 0;
logic q;
int su, ho;
dff_check ff (.clk(clk), .d(d), .q(q), .setup_bad(su), .hold_bad(ho));
// One trial: the flop first stores 0; then d rises 'offset' ns from the next clock edge (negative: before it).
task automatic trial(input real offset);
int su0, ho0;
d = 0; clk = 0;
#5 clk = 1; #5 clk = 0; // an edge that stores 0
su0 = su; ho0 = ho;
fork
begin #(10 + offset) d = 1; end
begin #10 clk = 1; #5 clk = 0; end
join
#5;
$display("d rises at %4.1f ns: %-15s q=%b", offset, su > su0 ? "setup violated" : ho > ho0 ? "hold violated" : "ok", q);
endtask
initial begin
trial(-4.0);
trial(-2.0);
trial(-1.5);
trial( 0.5);
trial( 1.0);
trial( 3.0);
end
endmodule
Check Yourself
Common Mistakes
Wrong Add the hold time into the clock period.
Hold is checked at the same edge that launches the data, so it has nothing to do with the period.
Fix Period ≥ t_pcq + t_pd + t_setup. Hold is a separate check: t_ccq + t_cd ≥ t_hold.
Wrong Fix a hold violation by slowing the clock.
The period does not appear in the hold check. The short path is just as fast at any clock.
Fix Add delay to the short path, as in problem G5.8.2.
Wrong Leave clock-to-Q out of the setup check.
Data leaves the launch flop only after its clock-to-Q delay. Without it, the period is too short.
Fix Start the path at the launch edge: clock-to-Q, then the logic, then setup.
Wrong Use the longest path for the hold check.
Hold fails when data arrives too early, so the fastest path is the one that matters.
Fix Use contamination delays: the earliest clock-to-Q and the shortest logic path.
Remember
- Setup and hold form a window around the edge in which d must not change.
- Setup: T ≥ t_pcq + t_pd + t_setup; the slowest path sets the fastest clock.
- Hold: t_ccq + t_cd ≥ t_hold; the clock period is not in it.
- A slower clock fixes setup; only delay on the short path fixes hold.