Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 37 ยท Synthesis and FPGA

Timing and Constraints

Learn setup and hold time, critical paths, clock period and slack, how to write a timing constraint, and how to shorten paths with registers in a VHDL design.

A VHDL design that is logically correct can still fail on the chip because the signals do not arrive in time. Gates and wires take real time, and the clock does not wait. Timing is the study of whether every signal gets from one flip-flop to the next before the next clock edge. Every FPGA engineer lives by the timing report, so this lesson gives you the vocabulary and the habits.

Timing analysis needs real tools and a real device, so VHDL and constraint files are read-only here. The C programs model the arithmetic of timing so you can calculate slack and maximum clock frequency yourself.

The two rules every flip-flop obeys

A flip-flop samples its input at the clock edge. For that to work reliably:

  • Setup time (t_su): the data must be stable for a short time before the edge.
  • Hold time (t_h): the data must stay stable for a short time after the edge.

Between two flip-flops there is combinational logic and wiring. The data launched at one edge must travel through all of it and still meet the setup time of the receiving flip-flop at the next edge.

flowchart LR
  FF1["flip-flop A<br/>(launch)"] -->|"clock-to-Q"| L["logic and routing"]
  L -->|"data path delay"| FF2["flip-flop B<br/>(capture)"]

The data path must be shorter than one clock period minus setup time.

Period, frequency and slack

The minimum clock period is set by the slowest register-to-register path, the critical path:

TEXT
T_min = t_clk-to-Q + t_logic + t_routing + t_setup (+ clock skew)
f_max = 1 / T_min
slack = T_clock - (t_clk-to-Q + t_logic + t_routing + t_setup)

Slack is the spare time. Positive slack: the path meets timing. Negative slack: it fails, and the design may work on the bench, fail when warm, or fail randomly. Tools report the worst negative slack (WNS) and total negative slack (TNS).

C C stand-in: slack and maximum frequency of paths

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

The multiplier path is the critical path, and it alone decides what clock the whole design can run. The standard fix is to cut it in two with a register, which is the subject of Pipelining.

Writing the constraint

The synthesis and place-and-route tools do not know how fast your clock must be unless you say so. The constraint file (for Xilinx and AMD tools an .xdc file, for Intel .sdc, both based on Tcl) holds it:

TEXT
# 100 MHz clock on pin "clk"
create_clock -period 10.000 -name sys_clk [get_ports clk]

# Inputs arrive 2 ns after the clock edge, outputs must be ready 3 ns before
set_input_delay  -clock sys_clk 2.0 [get_ports din]
set_output_delay -clock sys_clk 3.0 [get_ports dout]

Without create_clock the tools optimize for nothing in particular. Always constrain the clock, then inputs and outputs.

What affects delay

  • Logic depth: the number of LUTs in series. Fewer levels, faster paths.
  • Fan-out: a signal driving hundreds of loads is slow. The tool can duplicate registers, or you can do so in code.
  • Routing: distant cells are slower. Large designs have more routing delay.
  • Carry chains: wide adders are slow; 64-bit adders may need splitting.
  • Operators: multiplication, division, comparison and wide multiplexers cost the most.
C C stand-in: logic depth of an N-input AND built from 4-input LUTs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Every level adds delay. A tree of LUTs grows logarithmically with the number of inputs, so wide logic needs few levels but many LUTs.

Hold time and clock skew

Hold violations occur when data changes too soon after the edge, usually because of clock skew between two flip-flops on the same clock. Tools fix hold problems automatically by inserting delay, so you mainly worry about setup. In ASIC flows and in clock-crossing designs, hold needs attention too.

Synchronous design rules

These rules keep timing manageable:

  1. One clock per module where possible, and a clock only drives flip-flop clock pins.
  2. Register your outputs and (when they come from outside) your inputs.
  3. Do not use combinational signals as clocks; gating by a clock-enable signal instead.
  4. Do not feed asynchronous inputs (buttons, other clocks) straight into logic. Synchronize them with two flip-flops (see Clock Enables and Clock-Domain Crossing).
  5. Prefer synchronous reset for FPGAs: it uses the flip-flop's built-in reset input and is part of normal timing analysis. An asynchronous reset needs deassertion synchronized to the clock, or the flip-flops may leave reset at slightly different edges.

Reading a timing report

Look for four things:

  1. Constraints met? WNS positive, TNS zero.
  2. The worst path: it lists each element (clock-to-Q, LUTs, nets, setup). The biggest net or LUT chain is your target.
  3. Unconstrained paths: a design with no constraints can look fine because nothing was checked.
  4. Clock domains: every clock must be defined, and crossings between domains must be handled explicitly.

When timing fails, change one thing at a time: add a pipeline register, reduce fan-out or simplify a comparison. Re-run and read the new worst path.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is slack?

    Slack = required time minus arrival time; negative slack means a timing violation.
  2. 2. A clock of 100 MHz has a period of

    Period = 1 / frequency = 1 / 100 MHz = 10 ns.
  3. 3. The critical path is

    The slowest path decides the minimum clock period for the whole design.
  4. 4. Why should you add create_clock to a constraints file?

    Without the constraint, timing is not analyzed against any requirement.

Summary

  • Setup and hold times govern flip-flop sampling; slack measures how much margin a path has.
  • The critical path determines the maximum clock frequency.
  • Constrain the clock, inputs and outputs with create_clock and I/O delay constraints.
  • Reduce logic depth and fan-out, and add registers to split long paths.
  • Keep designs synchronous: registered outputs, synchronized inputs, one clock per module.

Next: The FPGA Flow, Pins and Your First Board