BitFlow
← Academy·Timing and Hazards
⏱GATE~45 min

Timing and Hazards

Setup and hold, how fast a circuit can run, glitches and how to remove them, and what happens when signals cross clock domains.

Setup and hold

A flip-flop needs a moment to make its decision. Setup time is how long D must be stable before the clock edge. Hold time is how long it must stay stable after the edge. Clock-to-Q is how long Q takes to change after the edge. Break the window and the flip-flop can misbehave.

Loading the animation…

How fast can it run?

Almost every timing question comes down to one path: from one flip-flop, through some logic, to the next flip-flop. The clock period has to cover all of it.

T_clk ≥ t_clk-q + t_logic + t_setup
The setup check uses the slowest path. f_max = 1 / T_clk(min).
t_clk-q + t_logic(min) ≥ t_hold
The hold check uses the fastest path, and the clock period doesn't appear in it.

Loading the animation…

Worked example: Maximum frequency

t_clk-q = 2 ns, the slowest logic path is 5 ns and t_setup = 1 ns. What's the fastest clock?

  1. Add them up: 2 + 5 + 1 = 8 ns.
  2. f_max = 1 / 8 ns.

Answer:125 MHz

Watch outA setup violation can always be fixed by slowing the clock. A hold violation can't, because it doesn't depend on the clock period at all. The chip simply fails, at any speed, until you add delay to the short path.

Clock skew means the clock reaches two flip-flops at different times. If it reaches the capturing flip-flop later (positive skew), the setup check gets more time, and the hold check gets less. Jitter is variation from one clock edge to the next, and it only ever takes time away.

T_clk + t_skew ≥ t_clk-q + t_logic + t_setup t_clk-q + t_logic(min) ≥ t_hold + t_skew

If a path is too slow, pipelining splits it with a register in the middle. Each half is shorter, so the clock can be faster. The result then takes an extra clock to come out, but a new input can go in every cycle.

Practice

t_clk-q = 1 ns, t_logic = 7 ns, t_setup = 2 ns. Adding a pipeline register splits the logic evenly. What's the new f_max?

Practice

A path has t_clk-q = 1 ns and a fastest logic delay of 0.2 ns. If t_hold = 0.5 ns and there's 1 ns of positive skew, does hold pass?

Hazards

A hazard is a moment when a combinational output glitches because signals reach a gate at different times. A static-1 hazard means an output that should stay 1 briefly dips to 0. A static-0 hazard is the opposite. A dynamic hazard means an output that should change once changes three or more times.

Loading the circuit…

Both outputs compute ab + a'c. y_fixed also has the extra term bc. Slow motion is on.
  • Turn on b and c, and then a. Both lights are on.
  • Now turn a off and watch y: it flickers off and back on, because the term ab ends before a'c begins.
  • y_fixed stays on, because bc holds the output up during the change.

A K-map shows why. A static-1 hazard happens wherever two neighbouring 1s aren't in the same group. Moving between them means leaving one term before the next has started.

abc00011110010011312040507161a'cab
Grouping

y = a'c + ab

Cells 3 and 7 touch, but they sit in different groups. The fix is to add the extra group bc, which covers both. It's redundant logically, and it's exactly the consensus term from Chapter 6.
  • To remove a static hazard, add a group covering each pair of neighbouring 1s that aren't already grouped together.
  • To tolerate hazards, sample only at clock edges. This is why synchronous design is so popular: glitches don't matter as long as everything has settled by the next edge.
  • Where glitches really matter: anything that responds immediately, such as asynchronous resets, clock inputs and enable pins on latches.
Open the circuit editor's Timing panel →Load the Static hazard example, change the gate delays, and see the glitch drawn as a waveform.

Metastability and clock domains

A button press, a serial line, or a signal from a block on another clock can change at any moment, so sooner or later it'll change inside a flip-flop's setup and hold window. Then the flip-flop can hang between 0 and 1. It'll eventually fall one way or the other, but no one can say how long that takes.

Loading the animation…

You can't prevent metastability, only make failures very rare. The standard tool is a two-flip-flop synchronizer: the first may go metastable, but it has a whole clock period to settle before the second reads it.

reg sync1, sync2;
always @(posedge clk) begin
  sync1 <= async_in;   // may go metastable
  sync2 <= sync1;      // use this one
end
Never use sync1 in your logic. Each extra flip-flop adds one more clock period of settling time, at the cost of a clock of delay.
Crossing a clock domainUse
A single, slow control bitTwo-flip-flop synchronizer
A short pulseStretch it, or use a toggle and synchronize that
A counter or pointerConvert to Gray code first, so only one bit changes per step
A data busAn asynchronous FIFO, or a handshake
Watch outNever synchronize each bit of a bus separately. Bits arrive on different clocks, so you can read a value that was never sent. That's why FIFO pointers use the Gray code from Chapter 4.

Exam problemsGATE: fine to skip at first

Timing questions usually give a small circuit and ask for f_max. Find the longest path between flip-flops, add clock-to-Q and setup, and don't forget paths back into the same flip-flop.

Practice · GATE-style

t_clk-q = 3 ns, t_setup = 2 ns, the slowest path has three gates of 4 ns each. What's the highest clock frequency?

Practice · GATE-style

With 2 ns of positive skew on the path above, what's the new highest frequency?

Practice · GATE-style

In F = ab + b'c, for which inputs can a static-1 hazard occur?

Practice · GATE-style

Which change helps a hold violation?

Was this chapter helpful?