Timing and clocks · Lesson 4 of 4

Static timing analysis and timing closure for FPGAs

How static timing analysis checks setup and hold, how to write SDC and XDC timing constraints, read WNS, TNS and WHS in a timing report, and fix failing paths.

intermediate50 minUpdated Free

What you will learn

  • Write the setup and hold inequalities for a register-to-register path, including clock skew and uncertainty
  • Calculate setup slack and Fmax for a path from its delay components
  • Constrain clocks, I/O delays and timing exceptions in SDC and XDC
  • Read WNS, TNS and WHS in a timing summary and find the failing path
  • Choose a fix for a failing path: pipelining, retiming, fewer logic levels, lower fanout or floorplanning

Before you start

  • Sequential logic (lesson 7)
  • FPGA architecture (lesson 2)
  • The FPGA design flow (lesson 3)

After this lesson you can calculate whether a register-to-register path meets timing, write the constraints that tell the tools what “meets timing” means for your design, and read the timing report that comes back. You will also know the usual fixes for a failing path and in which order to try them.

What static timing analysis does

A simulator checks function. It does not know how long a signal takes to travel through a LUT or a routing wire. Static timing analysis (STA) fills that gap. After place and route, the timing analyser knows the delay of every cell and every routed net. It checks every path between two timing points against the clock that launches the data and the clock that captures it.

“Static” means no test vectors. The analyser does not simulate. It adds up delays along each path and compares the total with the requirement. That makes it exhaustive: every path is checked, not only the ones a testbench happens to exercise. It also means the result is only as good as your constraints. A path with no clock on it is not checked at all.

Timing analysis runs at more than one operating point. Vendors characterise delays at slow and fast process, voltage and temperature corners. Setup is usually limited by the slow corner and hold by the fast corner, and the tools check both.

Anatomy of a register-to-register path

Most paths in a synchronous design start at one flip-flop and end at another (see sequential logic). Registers break the design into small combinational pieces with a clock edge at each end. The figure shows the parts of one such path.

Two flip-flops, FF1 and FF2, connected through a block of combinational logic. Brackets above the data path mark clock-to-Q delay at FF1, logic plus routing delay through the logic, and setup and hold at FF2. Below, one clock source splits into two branches with buffers, labelled launch clock delay to FF1 and capture clock delay to FF2.
A register-to-register path. Data leaves FF1 after its clock-to-Q delay, passes through logic and routing, and must be stable at FF2 for its setup and hold times. The clock reaches the two flip-flops through different delays, and the difference is the clock skew.

The delays are:

  • Clock-to-Q, tcqt_{cq}: time from the launch clock edge at FF1 to a valid output.
  • Logic delay, tlogict_{logic}: the LUTs, carry chains and other cells between the registers. Each LUT the signal passes through is one logic level.
  • Routing delay, troutet_{route}: the programmable interconnect between those cells. On FPGAs this is often half or more of the total path delay, which is why placement matters so much.
  • Setup time, tsut_{su}: how long before the capture edge the data at FF2 must be stable.
  • Hold time, tht_h: how long after the capture edge the data at FF2 must stay stable.
  • Clock arrival times, tclk,launcht_{clk,launch} and tclk,capturet_{clk,capture}: delay from the clock source to each flip-flop’s clock pin.

The clock skew is the difference in clock arrival:

tskew=tclk,capture−tclk,launcht_{skew} = t_{clk,capture} - t_{clk,launch}

The clock uncertainty tunct_{unc} is a margin for jitter and other effects that make an edge arrive at a slightly different time from cycle to cycle. Vivado calculates it from the clock source and any jitter you specify. Quartus Prime Lite and Standard add it when the SDC file calls derive_clock_uncertainty. You can add more with set_clock_uncertainty.

The setup check

Data launched by one clock edge must arrive at FF2 at least tsut_{su} before the next capture edge, one clock period TT later. Measured from the same clock source:

tclk,launch+tcq+tlogic+troute⏟data arrival time  ≤  T+tclk,capture−tsu−tunc⏟data required time\underbrace{t_{clk,launch} + t_{cq} + t_{logic} + t_{route}}_{\text{data arrival time}} \;\le\; \underbrace{T + t_{clk,capture} - t_{su} - t_{unc}}_{\text{data required time}}

Subtract tclk,launcht_{clk,launch} from both sides and the setup condition becomes:

tcq+tlogic+troute+tsu≤T+tskew−tunct_{cq} + t_{logic} + t_{route} + t_{su} \le T + t_{skew} - t_{unc}

Slack is the margin: required time minus arrival time. Positive slack means the path passes. Negative slack means it fails by that amount.

setup slack=(T+tskew−tsu−tunc)−(tcq+tlogic+troute)\text{setup slack} = \left(T + t_{skew} - t_{su} - t_{unc}\right) - \left(t_{cq} + t_{logic} + t_{route}\right)

Positive skew (capture clock later) gives the data more time and helps setup.

The hold check

The hold check protects FF2 from the same clock edge that launched the data. When FF1 launches new data, FF2 is capturing the old data on that same edge. The new data must not reach FF2 until tht_h after the capture clock arrives there:

tcq+tlogic+troute≥th+tskew+tunc,holdt_{cq} + t_{logic} + t_{route} \ge t_h + t_{skew} + t_{unc,hold} hold slack=(tcq+tlogic+troute)−(th+tskew+tunc,hold)\text{hold slack} = \left(t_{cq} + t_{logic} + t_{route}\right) - \left(t_h + t_{skew} + t_{unc,hold}\right)

Two things follow. First, the clock period TT does not appear, so changing the clock frequency never fixes a hold violation. Second, positive skew hurts hold. The tools fix most hold problems themselves by adding routing delay to fast paths, but only if the clocks are constrained correctly and the skew is small. Hold failures on FPGAs usually point to a clock problem: a clock routed through general logic instead of a dedicated clock network, or a missing constraint between related clocks.

Timing waveform with four rows: clock at FF1, clock at FF2 delayed by skew, FF1 Q changing from old to new value one clock-to-Q delay after the launch edge, and FF2 D changing later after logic and routing delay. A shaded hold window sits just after the first capture edge and a shaded setup window sits just before the next capture edge. An arrow between the data arrival and the setup window is labelled setup slack.
Setup and hold checks for one path. The hold window follows the capture edge that matches the launch edge, and the setup window precedes the next capture edge. Setup slack is the gap between data arrival and the start of the setup window.

Worked example at 100 MHz

The numbers below are example values chosen to show the arithmetic. They are not taken from a specific device.

Assume a 100 MHz clock, so T=10.00T = 10.00 ns. The timing analyser reports these delays for the slowest path:

QuantityValue
Launch clock arrival, tclk,launcht_{clk,launch}2.10 ns
Capture clock arrival, tclk,capturet_{clk,capture}1.90 ns
Clock-to-Q, tcqt_{cq}0.45 ns
Logic delay, tlogict_{logic} (4 LUT levels)3.10 ns
Routing delay, troutet_{route}4.25 ns
Setup time, tsut_{su}0.10 ns
Clock uncertainty, tunct_{unc}0.15 ns

The skew is 1.90−2.10=−0.201.90 - 2.10 = -0.20 ns. The capture clock arrives early, which costs setup margin.

Data arrival time: 2.10+0.45+3.10+4.25=9.902.10 + 0.45 + 3.10 + 4.25 = 9.90 ns.

Data required time: 10.00+1.90−0.10−0.15=11.6510.00 + 1.90 - 0.10 - 0.15 = 11.65 ns.

Setup slack: 11.65−9.90=+1.7511.65 - 9.90 = +1.75 ns. The path passes.

Fmax

The path would still pass with a period 1.75 ns shorter. For a single-clock design whose worst path is a normal one-cycle register-to-register path:

fmax≈1T−WNS=110.00−1.75 ns=18.25 ns≈121 MHzf_{max} \approx \frac{1}{T - \text{WNS}} = \frac{1}{10.00 - 1.75\ \text{ns}} = \frac{1}{8.25\ \text{ns}} \approx 121\ \text{MHz}

This is an estimate. A new run at a tighter clock gives a different placement and different delays. Quartus reports a per-clock “Fmax Summary”. Vivado does not report Fmax directly; you calculate it from WNS as above.

Check it the other way: at 125 MHz (T=8.00T = 8.00 ns) the required time drops by 2.00 ns and the slack becomes 1.75−2.00=−0.251.75 - 2.00 = -0.25 ns, a failure.

Hold on the same pair of registers

The hold check uses the fastest delays, from the fast corner. Assume (again example values) a shortest path of tcq=0.30t_{cq} = 0.30 ns and tlogic+troute=0.25t_{logic} + t_{route} = 0.25 ns. At the fast corner the clock arrives at 1.40 ns at FF1 and 1.55 ns at FF2, so the skew is +0.15 ns. With th=0.05t_h = 0.05 ns and a hold uncertainty of 0.05 ns:

Hold slack =(0.30+0.25)−(0.05+0.15+0.05)=+0.30= (0.30 + 0.25) - (0.05 + 0.15 + 0.05) = +0.30 ns.

Input and output delays

A path that starts or ends at an FPGA pin has only one end inside the FPGA. The other register is in an external chip. You describe the outside part of the path with set_input_delay and set_output_delay, measured relative to a clock.

Input delay is the time from the external clock edge until the data is valid at the FPGA pin: the external device’s clock-to-output time plus the board trace delay. The -max value drives the setup check and the -min value drives the hold check.

Output delay is how much of the clock period the outside world uses after the FPGA pin: the external device’s setup time plus the trace delay for -max, and the trace delay minus the external hold time for -min. The -min value is often negative.

Example values: an ADC launches data on the same 100 MHz clock with a clock-to-output time of 1.0 ns to 3.0 ns and a trace delay of 0.3 ns to 0.5 ns. A DAC needs 2.0 ns of setup and 0.5 ns of hold, with 0.2 ns to 0.4 ns of trace delay.

# Example values; take the real numbers from the data sheets and the board layout.
create_clock -name sys_clk -period 10.000 [get_ports clk]

# ADC -> FPGA: max = 3.0 + 0.5, min = 1.0 + 0.3
set_input_delay  -clock sys_clk -max  3.5 [get_ports {adc_data[*]}]
set_input_delay  -clock sys_clk -min  1.3 [get_ports {adc_data[*]}]

# FPGA -> DAC: max = 2.0 + 0.4, min = 0.2 - 0.5
set_output_delay -clock sys_clk -max  2.4 [get_ports {dac_data[*]}]
set_output_delay -clock sys_clk -min -0.3 [get_ports {dac_data[*]}]

This simplified model assumes the clock reaches the FPGA and the external chip at the same time. On a real board, add the clock trace delay difference to the numbers. These commands are written the same way in Vivado XDC and Quartus SDC.

Use registers in the I/O cells (IOB registers in Vivado, I/O registers in Quartus) for these interfaces. They give the same pin-to-register delay on every build.

Writing constraints

Both Vivado and Quartus use the Synopsys Design Constraints (SDC) command set. Vivado stores constraints in .xdc files, which hold SDC timing commands plus Vivado-specific physical properties such as pin locations. Quartus reads timing constraints from .sdc files and keeps pin and device settings in the .qsf project file.

The main differences you will meet:

TopicVivado (XDC)Quartus (SDC)
Hierarchy separator in names/, e.g. u_core/cnt_reg[3]|, e.g. u_core|cnt[3]
Object queriesget_cells, get_pins, get_nets, get_ports, get_clocksget_registers, get_keepers, get_pins, get_nets, get_ports, get_clocks
PLL/MMCM output clocksCreated automatically from the input clockLite and Standard: derive_pll_clocks in the SDC file
Clock uncertaintyCalculated automaticallyLite and Standard: derive_clock_uncertainty in the SDC file
Path delay without clock skewset_max_delay -datapath_onlyNo -datapath_only option

The open-source nextpnr flow takes a target frequency per clock (for example with its --freq option) and reports the achieved Fmax, but it does not support the full SDC command set.

Clocks

Every clock that enters the FPGA needs a create_clock on its pin:

create_clock -name sys_clk -period 10.000 -waveform {0.000 5.000} [get_ports clk]

-waveform gives the rising and falling edge times; {0 5} is the default 50 % duty cycle for a 10 ns period.

Clocks made inside the FPGA need create_generated_clock, so the analyser knows their relation to the source clock. Vivado creates MMCM and PLL output clocks automatically, and in Quartus Prime Lite and Standard derive_pll_clocks does the same. A clock divided in fabric logic must be declared by hand:

# Vivado: a divide-by-2 clock from register clk_div_reg
create_generated_clock -name clk_div2 -source [get_pins clk_div_reg/C] \
    -divide_by 2 [get_pins clk_div_reg/Q]

# Quartus: the same register, Quartus naming
create_generated_clock -name clk_div2 -source [get_pins {clk_div|clk}] \
    -divide_by 2 [get_pins {clk_div|q}]

A clock from a fabric register leaves the dedicated clock network and adds skew. Use a PLL or MMCM output, or a clock enable on the fast clock, instead. Clock domain crossing covers what happens at the boundary between clocks.

False paths

set_false_path removes paths from analysis. Use it only where timing truly does not matter, for example a push button that enters a synchroniser:

set_false_path -from [get_ports btn_raw]

A false path on a real synchronous path hides a bug that the hardware will find for you later.

Multicycle paths

Sometimes data only needs to arrive every second cycle, because the destination register has a clock enable that is high every other cycle. A multicycle constraint relaxes the setup check to N cycles. It must be paired with a hold constraint of N - 1, otherwise the hold check moves out with the setup edge:

# Vivado: setup over 2 cycles, hold back to the launch edge
set_multicycle_path 2 -setup -from [get_cells {acc_reg[*]}] -to [get_cells {result_reg[*]}]
set_multicycle_path 1 -hold  -end -from [get_cells {acc_reg[*]}] -to [get_cells {result_reg[*]}]

# Quartus: same constraint, Quartus naming
set_multicycle_path -setup -end 2 -from [get_registers {acc[*]}] -to [get_registers {result[*]}]
set_multicycle_path -hold  -end 1 -from [get_registers {acc[*]}] -to [get_registers {result[*]}]

The constraint is only correct if the RTL guarantees it. If the enable logic changes, the constraint becomes a lie the tools cannot detect.

Clock groups

set_clock_groups -asynchronous tells the analyser that two sets of clocks have no phase relation, so it does not time paths between them:

set_clock_groups -asynchronous -group [get_clocks sys_clk] -group [get_clocks eth_rx_clk]

Use it only when every crossing between the groups goes through a proper synchroniser. The clock domain crossing lesson shows the synchronisers and the CDC-specific constraints that go with them.

Checking the constraints

Run check_timing in Vivado or the “Unconstrained Paths” report in Quartus after every constraint change. Both list clocks without definitions, I/O ports without delays and registers without a clock. Fix these before you read any slack numbers.

Reading a timing report

Start with the summary. Vivado’s report_timing_summary gives these numbers:

  • WNS (worst negative slack): the smallest setup slack of all paths. Positive means every setup check passes.
  • TNS (total negative slack): the sum of the negative setup slacks over all failing endpoints. It shows whether you have one bad path or thousands.
  • WHS (worst hold slack) and THS (total hold slack): the same for hold.

Quartus shows setup and hold summaries per clock and per corner, with the worst slack and the “End Point TNS” for each clock. In either tool, timing is met only when WNS and WHS are both positive at every corner and every clock.

Then open the worst path. A detailed path report lists every cell and net with its delay, split into the data path and the clock paths. For the worked example above, the shape of the report is (simplified layout, not literal tool output):

Slack (MET):        1.750 ns
Source:             u_core/acc_reg[7]/C   (rising edge sys_clk)
Destination:        u_core/sum_reg[15]/D  (rising edge sys_clk)
Requirement:        10.000 ns
Data path delay:    7.800 ns  (logic 3.550 ns 45.5%, route 4.250 ns 54.5%)
Logic levels:       4
Clock path skew:    -0.200 ns
Clock uncertainty:  0.150 ns

The logic-to-route split in Vivado counts clock-to-Q as logic, so 0.45 + 3.10 = 3.55 ns. Look at three things first: the number of logic levels, the route percentage and the clock skew. They tell you which fix to try.

Fixing failing paths

Work through these in order. The first ones change the RTL and give the largest gains; the last ones only work around a placement problem.

1. Pipeline the path

Add registers to split a long path into shorter ones. You pay with latency, so the surrounding logic must accept the extra cycles. The download below sums eight 16-bit numbers two ways. sum8_chain.sv registers the inputs and output and puts seven adders in series between them. sum8_pipe.sv uses a balanced adder tree with a register after each level, so each register-to-register path holds a single adder:

always_ff @(posedge clk) begin
    x_r <= x;
    for (int i = 0; i < 4; i++) begin
        s1[i] <= (W+1)'(x_r[2*i]) + (W+1)'(x_r[2*i+1]);
    end
    for (int i = 0; i < 2; i++) begin
        s2[i] <= (W+2)'(s1[2*i]) + (W+2)'(s1[2*i+1]);
    end
    y <= (W+3)'(s2[0]) + (W+3)'(s2[1]);
end

Latency grows from 2 to 4 cycles. The valid signal travels through a shift register of the same length, so downstream logic knows when y is ready. The testbench feeds both versions the same random inputs and checks both against a reference sum.

Download sum8_chain.sv Download sum8_pipe.sv Download tb_sum8.sv
iverilog -g2012 -o sim tb_sum8.sv sum8_chain.sv sum8_pipe.sv && vvp sim
# PASS: 798 sums checked on each design

2. Let the tool retime

Retiming moves existing registers across combinational logic to balance the delays on either side, without changing the function seen at the outputs. It works best when you add a few registers at the end of a path and let the tool push them into the logic. Vivado supports retiming during synthesis (synth_design -retiming) and in physical optimisation. Quartus has register retiming options, and Quartus Prime Pro adds Hyper-Retiming for devices with the Hyperflex architecture (Stratix 10 and Agilex). Retiming cannot move registers that have asynchronous resets or that the tool must preserve, such as synchronisers.

3. Reduce logic levels

Look at how the logic is written. Common causes of deep logic:

  • Priority chains from long if/else if sequences where the conditions are mutually exclusive. A case statement or a parallel AND-OR structure is shallower.
  • Wide comparisons or counters where only a terminal value matters. Compare with a registered “almost done” flag instead.
  • Arithmetic followed by more arithmetic in the same cycle, as in the chain example.
  • Decoding done again in every module instead of once, registered, and shared.

Vivado’s report_design_analysis shows the logic-level distribution of the worst paths, which tells you whether the problem is one path or a pattern.

4. Reduce fanout

A signal that drives hundreds of loads (a pipeline enable, a reset, a state bit) has a long, spread-out net. Its routing delay dominates. Duplicate the source register so each copy drives a local group of loads. The tools do this when asked: the MAX_FANOUT attribute in Vivado, the maximum fanout assignment in Quartus, and Vivado’s physical optimisation step also replicates high-fanout drivers. Reset nets are a frequent offender. Resetting only the registers that need a known start value (control state, valid flags) and leaving data path registers without reset reduces this load.

5. Floorplan, as a last resort

If the logic is shallow but the route percentage is high, the cells are placed far apart. Sometimes that is because a block connects to I/O on opposite sides of the die, or because two large blocks compete for the same area. Floorplanning (Pblocks in Vivado, Logic Lock regions in Quartus) confines logic to a region. It can help, but it also removes freedom from the placer, and a bad floorplan makes timing worse. Try it only after the RTL and constraint fixes, and keep the regions generous.

When nothing else works, lowering the clock frequency is also a legitimate fix if the system allows it.

Exercise

Calculate slack and Fmax

A path has these example values: tcq=0.40t_{cq} = 0.40 ns, tlogic=2.20t_{logic} = 2.20 ns, troute=3.60t_{route} = 3.60 ns, tsu=0.08t_{su} = 0.08 ns, launch clock arrival 1.50 ns, capture clock arrival 1.62 ns, clock uncertainty 0.12 ns. The clock is 150 MHz.

  1. Calculate the setup slack.
  2. Estimate Fmax for this path.
  3. The shortest path into the same register has tcq+tlogic+troute=0.18t_{cq} + t_{logic} + t_{route} = 0.18 ns at the fast corner, with the same skew, th=0.05t_h = 0.05 ns and a hold uncertainty of 0.03 ns. Does it meet hold?
Show solution
  1. T=1/150 MHz=6.667T = 1 / 150\ \text{MHz} = 6.667 ns. Skew =1.62−1.50=+0.12= 1.62 - 1.50 = +0.12 ns. Data path =0.40+2.20+3.60=6.20= 0.40 + 2.20 + 3.60 = 6.20 ns. Setup slack =(6.667+0.12−0.08−0.12)−6.20=6.587−6.20=+0.387= (6.667 + 0.12 - 0.08 - 0.12) - 6.20 = 6.587 - 6.20 = +0.387 ns. The path passes.
  2. fmax≈1/(6.667−0.387)=1/6.280 ns≈159f_{max} \approx 1 / (6.667 - 0.387) = 1 / 6.280\ \text{ns} \approx 159 MHz.
  3. Hold slack =0.18−(0.05+0.12+0.03)=−0.02= 0.18 - (0.05 + 0.12 + 0.03) = -0.02 ns. It fails by 20 ps. The positive skew that helped setup hurts hold here. The router normally fixes a violation this small by adding delay to the short path; if it cannot, check why the skew is positive (for example, a clock that leaves the dedicated clock network).
Exercise

Constrain a multicycle path

A 32-bit divider in your design takes its inputs from registers div_a and div_b and writes div_q. A control FSM loads the inputs and enables div_q only every fourth cycle of the 200 MHz clock clk_core. Write the Vivado constraints that relax the path, and state what you must check in the RTL before you trust them.

Show solution
set_multicycle_path 4 -setup -from [get_cells {div_a_reg[*] div_b_reg[*]}] -to [get_cells {div_q_reg[*]}]
set_multicycle_path 3 -hold  -end -from [get_cells {div_a_reg[*] div_b_reg[*]}] -to [get_cells {div_q_reg[*]}]

The setup multiplier is 4 and the hold multiplier is 4 - 1 = 3, which brings the hold check back to the launch edge. Before trusting the constraint, check that div_a and div_b never change during the four cycles before div_q is enabled, and that div_q has a clock enable that is high only on the fourth cycle. In simulation, an assertion on these conditions is cheap insurance. If the FSM is ever changed to load faster, the constraint must change with it.

Summary

  • Static timing analysis adds up cell and routing delays on every path and compares them with the clock constraints. Paths without constraints are not checked.
  • Setup requires tcq+tlogic+troute+tsu≤T+tskew−tunct_{cq} + t_{logic} + t_{route} + t_{su} \le T + t_{skew} - t_{unc}. Hold requires the data path to be longer than th+tskewt_h + t_{skew} plus uncertainty, and does not depend on the clock period.
  • Slack is required time minus arrival time. WNS and TNS summarise setup; WHS and THS summarise hold. Both must be positive at every corner.
  • Constrain every clock with create_clock or create_generated_clock, every synchronous I/O with input and output delays, and add exceptions (false paths, multicycle paths, clock groups) only where the RTL guarantees them.
  • Fix failing paths in this order: pipeline, retime, reduce logic levels, reduce fanout, and floorplan only as a last resort.

Check your understanding

Pick an answer for each question, then check. Answers stay hidden until you submit.

1. A path has 0.6 ns of setup slack at 100 MHz. Assuming every other part of the path stays the same, what is the approximate Fmax of this path?
2. Clock skew on a path is positive: the capture clock arrives later than the launch clock. What does that do?
3. Raising the clock frequency fixes nothing about a hold violation. Why?
4. You add set_multicycle_path 2 -setup between two registers in the same clock domain and nothing else. What is the most likely problem?
5. A timing summary shows WNS = +0.312 ns, TNS = 0.000 ns, WHS = -0.045 ns. What is the state of the design?

Found a mistake or something unclear?Report a correction.