Learn / Digital logic / Flip-flops

Timing, Setup and Hold, and Metastability

ReviewedAdvanced ProAbout 6 min
ABY
In short

Timing, Setup and Hold, and Metastability: the short answer

A flip-flop captures its input on the clock edge, but only if the input is stable for a short time before the edge (the setup time) and after it (the hold time). For a 74HC74 at 5 V these are in the order of 10 to 20 ns, and the datasheet gives exact values for each supply voltage.

Level
Advanced
Time
About 6 min
Topic
Digital logic
You will learn to

Check setup and hold times, find the maximum clock speed of a logic path, and synchronise signals that cross clock domains.

Before this: Flip-Flops, Debouncing and Counters, State Machines

A flip-flop captures its input on the clock edge, but only if the input is stable for a short time before the edge (the setup time) and after it (the hold time). For a 74HC74 at 5 V these are in the order of 10 to 20 ns, and the datasheet gives exact values for each supply voltage. Violate them and the output may be wrong, or worse, metastable: stuck between 0 and 1 for an unpredictable time before settling either way.

The maximum clock frequency of a synchronous circuit comes from its slowest path. Between two flip-flops, the signal must leave the first flip-flop (clock-to-output delay), pass through any gates (propagation delay), and arrive at the second flip-flop before its setup time. So the clock period must be at least tco + tlogic + tsetup, plus some allowance for clock skew. FPGA tools do exactly this calculation for every path in a static timing report.

Metastability cannot be avoided when a signal comes from outside the clock's control: a push button, a sensor's data-ready pin or a signal from another clock domain. It can only be made rare. The standard fix is a two-flip-flop synchroniser: the asynchronous signal goes into one flip-flop, and its output goes into a second flip-flop on the same clock. The first one may go metastable, but it almost always settles within one clock period, so the second captures a clean value. Never feed one asynchronous signal into several flip-flops in parallel, as they may capture different values. Multi-bit buses crossing clock domains need a handshake or a FIFO, not separate synchronisers per bit.

Setup and hold in practice

A flip-flop needs its data stable for the setup time before the clock edge and the hold time after. In a design the data takes a time to pass through logic from one flip-flop to the next, and that time plus the setup time must be less than the clock period. If not, the circuit fails at that speed, and slowing the clock or shortening the logic fixes it.

Hold violations are the opposite: the data changes too soon after the edge. These do not depend on clock speed, so slowing the clock does not cure them.

Crossing between clocks

A signal from another clock, or an asynchronous input such as a button, can change at any moment, including near the edge. The flip-flop can then land in an in-between state, called metastability, and take longer to settle, which may be read differently by different parts of the circuit.

The standard cure is a two-stage synchroniser: pass the signal through two flip-flops in a row on the new clock. The first may go metastable, and the second almost always sees a settled value. It reduces the chance of failure to an extremely small figure, but never to zero.

Multi-bit signals

Do not synchronise each bit of a multi-bit value separately, because the bits may arrive on different cycles and give a value that never existed. Use a handshake, a FIFO designed for clock crossing, or send one bit that says the data is ready, and Gray coding for counters.

Common mistakes
  • Feeding an asynchronous input straight into logic without a synchroniser.
  • Synchronising each bit of a bus separately.
  • Trying to fix a hold violation by slowing the clock.
Key formulas
tclk-q + tlogic + tsetup < Tclk
setup check: the path must settle inside one clock period
tclk-q + tlogic > thold
hold check: data must not change too soon
Advanced lesson · Pro plan

Practise this lesson with Pro

The explanation above is free for everyone. The practice for Advanced lessons in every domain are part of the Pro plan at ₹999 a month.

With Pro you also get: a worked example, a hands-on task, a 3-question check.

Common questions

What will I learn in "Timing, Setup and Hold, and Metastability"?

Check setup and hold times, find the maximum clock speed of a logic path, and synchronise signals that cross clock domains.