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.

Six Trials of One Flip-Flop ModelEach column is one trial of the lab: d rises at a different offset from the clock edge. Setup 2 ns, hold 1 ns.
012345offset (ns)-4.0-2.0-1.50.51.03.0verdictoksetupholdokq afterinside the window
Scroll horizontally ↔
  1. Cycle 0

    The input d changes well before the edge, so the flop stores the new value, 1.

  2. Cycle 2

    A change 1.5 ns before the edge is inside the 2 ns setup time. The model makes q unknown.

  3. Cycle 3

    A change 0.5 ns after the edge is inside the 1 ns hold time: unknown again.

  4. 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.

Inside the Window
Inside the Windowsetupholdclkdoldnewqnew-6-4-20246ns
Scroll horizontally ↔

Captures the new value. The data is stable 2 ns before the setup time begins: setup slack 2 ns.

QuantityValue
Capture edge0 ns
Data must be stable from-2 ns (setup 2 ns before the earliest edge)
until1 ns (hold 1 ns after the latest edge)
Data changes at-4 ns
Setup slack (window start − data edge)2 ns

  1. Early. The input changes 4 ns before the edge, outside the window. The flop captures the new value.
  2. Just in time. The input changes exactly 2 ns before the edge, as the window opens. Still the new value.
  3. Too late for setup. At 1.5 ns before the edge, d changes inside the window. The flop may go metastable.
  4. Too early for hold. At 0.5 ns after the edge, the old value was not held long enough.
  5. Late. At 1 ns after the edge the window has closed: the flop keeps the old value.

The numbers of the lab model: setup 2 ns, hold 1 ns, clock-to-Q 1 ns. Drag the data edge or use the slider.

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 slewsd risingd falling
Setup time51 ps103 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.

One Path Between Two Flip-FlopsArrows show data from one clock edge to the next. Both flops share the clock.
  • Clock / reset
  • Storage
  • Datapath
  • Clock
  • Data
One path between two flip-flopsArrows show data from one clock edge to the next. Both flops share the clock. clock reset Clock edge t = 0 storage Launch flop clock-to-Q t_pcq datapath Logic propagation t_pd storage Capture flop needs t_setup beforeT QD
  1. clock reset Clock edget = 0
    • Launch flop
  2. storage Launch flopclock-to-Q t_pcq
    • Q → Logic
  3. datapath Logicpropagation t_pd
    • D → Capture flop
  4. storage Capture flopneeds t_setup before T
  1. Setup: the slow case

    Latest arrival t_pcq + t_pd must come before T − t_setup. So T ≥ t_pcq + t_pd + t_setup.

  2. 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
  1. 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.

  2. 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.

  3. 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?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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=0
Read 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

ConceptWhich check depends on the clock period?
Conceptt_ccq = 80 ps, the shortest logic path t_cd = 10 ps, and the hold time is 120 ps. What is the hold slack?
ConceptA path fails hold by 30 ps. Which change fixes it?
Read the waveformA flop has setup 2 ns and hold 1 ns. The clock rises at the start of cycle 3; each cycle is 1 ns. In which cycle can d change and still be captured as the new value?
A clock edge and a window
012345clkwindow
Scroll horizontally ↔

window = 1 marks the time d must be stable.

Predict the outputThe lab model with TSU = 2 and TH = 1: d rises 2.5 ns before an edge. Predict the exact line.
`timescale 1ns/100ps
// dff_check: a flip-flop model that checks its own setup and hold window.
// TSU: d must be stable this long before the edge. TH: and this long after it. TCQ: clock-to-Q.
// A change inside the window makes q unknown (x), as a metastable flop might be.
module dff_check #(parameter real TSU = 2.0, TH = 1.0, TCQ = 1.0) (
  input  logic clk, d,
  output logic q,
  output int   setup_bad, hold_bad
);
  realtime t_d = -100, t_clk = -100;
  initial begin setup_bad = 0; hold_bad = 0; end
  always @(d) begin
    t_d = $realtime;
    if (t_d - t_clk < TH) begin hold_bad++; q <= #(TCQ) 1'bx; end
  end
  always @(posedge clk) begin
    t_clk = $realtime;
    if (t_clk - t_d < TSU) begin setup_bad++; q <= #(TCQ) 1'bx; end
    else q <= #(TCQ) d;
  end
endmodule

module tb;
  logic clk = 0, d = 0, q;
  int   su, ho;
  dff_check ff (.clk(clk), .d(d), .q(q), .setup_bad(su), .hold_bad(ho));
  initial begin
    #5 clk = 1; #5 clk = 0;
    #7.5 d = 1;
    #2.5 clk = 1;
    #2 $display("setup_bad=%0d hold_bad=%0d q=%b", su, ho, q);
  end
endmodule

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.

Practice

Report a problem with this page