BitFlow

Setup and hold time explained (with worked examples)

What setup and hold time are, the two timing equations every digital designer uses, a worked maximum-frequency example, how clock skew changes both, and how to fix each kind of violation.

By BitFlow · · 8 min read

The definitions

A flip-flop samples its D input at the clock edge, but it needs the input to be steady for a short window around that edge:

  • Setup time (t_su): how long D must be stable before the clock edge.
  • Hold time (t_h): how long D must stay stable after the clock edge.
  • Clock-to-Q delay (t_cq): how long after the edge the new value appears at Q.

If D changes inside the setup-hold window, the flip-flop may capture the wrong value or go metastable: its output hovers between 0 and 1 for an unpredictable time before settling. Timing analysis exists to make sure that never happens between flip-flops on the same clock.

The two equations

Picture one register launching data, a cloud of combinational logic, and a second register capturing it on the next edge.

T_clk ≥ t_cq + t_logic,max + t_su
Setup: the slowest path must arrive before the next edge, with t_su to spare.
t_cq,min + t_logic,min ≥ t_h
Hold: the fastest path must not reach the capturing flip-flop before its hold window from the same edge has closed.

Notice what is missing from the hold equation: the clock period. A hold violation cannot be fixed by slowing the clock down. A design with a hold violation fails at any frequency.

Worked example: maximum clock frequency

Worked example: How fast can this path run?

t_cq = 0.3 ns, the slowest logic path is 4.2 ns, the fastest is 0.05 ns, t_su = 0.5 ns, t_h = 0.1 ns, t_cq,min = 0.1 ns. Ignore skew.

  1. Setup: T_clk ≥ 0.3 + 4.2 + 0.5 = 5.0 ns.
  2. f_max = 1 / 5.0 ns = 200 MHz.
  3. Hold: t_cq,min + t_logic,min = 0.1 + 0.05 = 0.15 ns, which is ≥ t_h = 0.1 ns. Hold is met with 0.05 ns of slack.

Answer:The path runs at up to 200 MHz, and hold is met.

What clock skew does

Clock skew (t_skew) is how much later the clock reaches the capturing flip-flop than the launching one. It helps one check and hurts the other:

T_clk ≥ t_cq + t_logic,max + t_su − t_skew
Positive skew gives the slow path extra time.
t_cq,min + t_logic,min ≥ t_h + t_skew
…and takes the same amount away from the hold margin.
Worked example: Same path, 0.1 ns of skew

Use the numbers above with t_skew = +0.1 ns.

  1. Setup: T_clk ≥ 5.0 − 0.1 = 4.9 ns, so f_max rises to about 204 MHz.
  2. Hold: 0.15 ns ≥ 0.1 + 0.1 = 0.2 ns is false. The path now has a hold violation of 0.05 ns.

Answer:Skew bought 4 MHz and broke hold. This is why clock trees are balanced so carefully.

How to fix each violation

Setup violationHold violation
MeaningThe slow path is too slow for the clockThe fast path is too fast
Lower the clock frequency?Fixes itDoes nothing
Usual fixesPipeline the path, restructure or simplify the logic, use faster cells, retime registersInsert delay (buffers) on the short path, reduce skew
Found byStatic timing analysis at the slow cornerStatic timing analysis at the fast corner
TipIn RTL, the setup fix you control is pipelining: split a long combinational path with a register. BitFlow's 3-stage pipelined multiplier problem is exactly this trade: more latency, a much shorter critical path.

Signals from another clock domain

The equations above only work when both flip-flops share a clock. A signal from another clock domain, or a push button, can change at any moment, so it will eventually violate setup or hold. You cannot prevent that, so you contain it: pass the signal through two flip-flops in a row (a synchroniser) before using it. The first may go metastable; the second gives it a full clock period to settle.

reg s1, s2;
always @(posedge clk) begin
  s1 <= async_in;   // may go metastable
  s2 <= s1;         // safe to use
end

Multi-bit values need more than this, because the bits can be caught at different moments. That is what Gray-coded pointers in an asynchronous FIFO solve.

Questions

What is setup time?

The minimum time the data input of a flip-flop must be stable before the active clock edge so that it is captured correctly.

What is hold time?

The minimum time the data input must remain stable after the active clock edge. If it changes sooner, the flip-flop may capture the new value or go metastable.

Can a hold violation be fixed by reducing the clock frequency?

No. The hold check compares two delays from the same clock edge, so the clock period does not appear in it. Hold violations are fixed by adding delay to the fast path or reducing clock skew.

How do you calculate the maximum clock frequency?

Find the minimum period T = t_cq + t_logic,max + t_su (minus any useful skew) over the slowest register-to-register path, then f_max = 1 / T.

Was this article helpful?

Keep going