Dynamic and Function Hazards, and When Glitches Matter

Recognize glitches that no consensus term can fix, and decide where a glitch can do harm and where it cannot.

You Will Be Able To

  • Explain how a multilevel circuit makes a dynamic hazard.
  • Show why a function hazard appears in every cover of a function.
  • State the rules for hazard-free two-level logic.
  • Decide which signals must be glitch-free in a synchronous design.
Lesson
G5.3
Time
25 min
Runs on
Your browser
Check
5 questions

A test engineer saw a counter enable rise, fall and rise again after a single input change. The logic was correct, and its two-level cover had every prime. But the circuit was built in three levels of gates, and a glitch from the inner level reached the output.

s Falls at t = 10: y = S'a Rises Once, Three Edges SeenOne column per gate delay, from t = 9 to t = 14. a = b = 1.
012345snsm (inner mux)y101
Scroll horizontally ↔
  1. Cycle 1

    s falls. The function y = s'a goes from 0 to 1.

  2. Cycle 3

    ns rose at 11 while m was still 1, so y rises at 12.

  3. Cycle 4

    The inner mux has a static-1 hazard: m dips at 12, and y follows at 13.

  4. Cycle 5

    m recovers, and y rises for the second time at 14.

Measured on the circuit model of the figure below, which matches the lab on Icarus.

Dynamic Hazards

A dynamic hazard is an output that should change once but changes three or more times: 0, 1, 0, 1. It needs at least three paths of different delay from one input to the output.

One Change, Three Output Edges
One Change, Three Output Edgesg1 · NOTns=1g2 · ANDt0=1g3 · ANDt1=0g4 · ORm=1g5 · ANDy=1a=1b=1s=0
a=1 b=1 s=0
g1 · NOTs=0 → ns=1
g2 · ANDa=1, ns=1 → t0=1
g3 · ANDb=1, s=0 → t1=0
g4 · ORt0=1, t1=0 → m=1
g5 · ANDns=1, m=1 → y=1
Read the connections
GateKindInputsOutput
g1NOTsns
g2ANDa, nst0
g3ANDb, st1
g4ORt0, t1m
g5ANDns, my

Outputs: y. MUX inputs: d0, d1, select. Latch/flip-flop inputs: data, enable/clock. Unknown values are marked x; high impedance is folded into x in this model.

Gate delay 14. Settled after 14 gate delays from t = 0.

Output values at each gate delay01234567891011121314yxx0000000000101
Scroll horizontally ↔
Every computed frame
Timey
0x
1x
20
30
40
50
60
70
80
90
100
110
121
130
141

  1. Step 11 · Three paths. `s` reaches g5 through the inverter (2 gate delays), and reaches it again through the mux (3 or 4).
  2. Step 12 · First edge. `ns` has risen and `m` is still 1, so `y` rises at 12.
  3. Step 13 · Second edge. The inner mux glitches: `m` is 0 at 12, so `y` falls at 13.
  4. Step 14 · Third edge. `m` is back to 1, and `y` rises again at 14. It should have risen once.

Unit delays, a = b = 1, s falls at 10. The function is y = s'a, so y must go from 0 to 1 once.

A two-level sum of products cannot do this for one input change. Each product term changes at most once, and an OR of terms that all rise, or all fall, moves once. Dynamic hazards live in multilevel circuits, often where an inner static hazard meets another path.

Function Hazards

Now let two inputs change. In real hardware one of them moves first, so the inputs pass through an extra row on the way. If the function has the other value on that row, the output glitches.

Two Inputs, One Order
Two Inputs, One Orderg1 · NOTnu=0g2 · NOTnv=1g3 · ANDt0=0g4 · ANDt1=0g5 · OReq=0u=1v=0
u=1 v=0
g1 · NOTu=1 → nu=0
g2 · NOTv=0 → nv=1
g3 · ANDnu=0, nv=1 → t0=0
g4 · ANDu=1, v=0 → t1=0
g5 · ORt0=0, t1=0 → eq=0
Read the connections
GateKindInputsOutput
g1NOTunu
g2NOTvnv
g3ANDnu, nvt0
g4ANDu, vt1
g5ORt0, t1eq

Outputs: eq. MUX inputs: d0, d1, select. Latch/flip-flop inputs: data, enable/clock. Unknown values are marked x; high impedance is folded into x in this model.

Gate delay 13. Settled after 13 gate delays from t = 0.

Output values at each gate delay012345678910111213eqxxx00000000010
Scroll horizontally ↔
Every computed frame
Timeeq
0x
1x
2x
30
40
50
60
70
80
90
100
110
121
130

  1. Step 10 · u rises first. The inputs are now 11 for one gate delay. On that row the function is 1.
  2. Step 12 · The circuit answers. The term uv turned on at 11, so `eq` rises at 12. The circuit is right: for a moment the inputs really were equal.
  3. Step 13 · And recovers. `v` fell at 11, so uv turned off at 12 and `eq` falls at 13.

Both primes of u ⊙ v are present, so no single change glitches it. Change both pins and step again.

This is a function hazard. It belongs to the function, not to the circuit. The equality detector has both prime implicants, so no single change glitches it. Yet from 01 to 10, either order passes a row where the inputs are equal.

ChangePath takenMeasured eq
u then v, 01 to 1001 → 11 → 101@22 0@23
v then u, 10 to 0110 → 11 → 011@33 0@34
both at once, 01 to 1001 → 10no change

Times in ns from the lab. Value@time lists each change of eq. Only the ideal zero-skew change is clean.

No consensus term helps here: the circuit answers the inputs it sees, and for one gate delay it really sees 11.

Rules for Hazard-Free Logic

  1. One input changes

    A two-level sum of products is free of static-1 hazards when every pair of adjacent 1 cells lies inside one term. Adding all prime implicants is enough.

  2. Products of sums

    The dual: every pair of adjacent 0 cells lies inside one sum term.

  3. Multilevel circuits

    Factoring can bring back static and dynamic hazards. Check the factored circuit, not only the cover it came from.

  4. Several inputs change

    A function hazard cannot be designed out. Allow one change at a time, or wait for the output to settle and sample it.

When Glitches Matter

Most glitches do no harm. A flip-flop looks at its D input only at the clock edge. If the logic settles before the edge, its glitches are gone.

Some inputs act on any pulse at any time. On these, a glitch is a real event.

Where a Glitch LandsArrows show one glitchy combinational output fanning out to four kinds of input.
  • Datapath
  • I/O
  • Clock / reset
  • Control / FSM
  • Data
  • Reset
  • Clock
  • Control
Where a glitch landsArrows show one glitchy combinational output fanning out to four kinds of input. datapath Combinationallogic may glitch while itsettles io Flop D input sampled at the edge:harmless clock reset Asynchronousclear acts at once: harmful clock reset Clock pin an extra edge:harmful control Latch enable opens the latch:harmful
  1. datapath Combinational logicmay glitch while it settles
    • Flop D input
    • Asynchronous clear
    • Clock pin
    • Latch enable
  2. io Flop D inputsampled at the edge: harmless
  3. clock reset Asynchronous clearacts at once: harmful
  4. clock reset Clock pinan extra edge: harmful
  5. control Latch enableopens the latch: harmful
  1. Sampled

    A D input is read only at the clock edge. A glitch that ends before the edge leaves no trace.

  2. Level or edge sensitive at any time

    A clear, a clock or a latch enable acts on the glitch itself.

Read the diagram as text
  • Combinational logic: may glitch while it settles
  • Flop D input: sampled at the edge: harmless
  • Asynchronous clear: acts at once: harmful
  • Clock pin: an extra edge: harmful
  • Latch enable: opens the latch: harmful
  • Combinational logic → Flop D input
  • Combinational logic → Asynchronous clear
  • Combinational logic → Clock pin
  • Combinational logic → Latch enable

Synchronous design keeps combinational logic away from the three lower pins.

InputWhat a glitch does
Clock of a flip-flopAn extra edge: the flop loads early, or a counter counts twice (G5.9).
Asynchronous set or resetThe flop is cleared or set in the middle of a cycle.
Enable of a latch, S or R of an SR latchThe latch opens or flips for the width of the glitch.
Any wire, for powerEach extra edge charges and discharges the load, and costs energy (G9.9).

Synchronous data inputs are missing from this table on purpose: their glitches are harmless.

Asked in interviews
  1. What is a dynamic hazard?

    An output that should change once changes three or more times. It needs three or more paths of different delay from one input. So it occurs in multilevel logic, never in a two-level sum of products.

  2. Can every glitch be removed with extra logic?

    No. Static hazards can be covered with consensus terms. A function hazard, from two inputs changing together, appears in every implementation. The cure is timing: sample the output after it settles.

  3. Where must logic be glitch-free?

    On clocks, asynchronous sets and resets, and latch enables, since they act on any pulse. Data sampled by flip-flops can glitch freely as long as it settles before the clock edge.

Try It

The first line is the dynamic hazard: three edges where one was needed.

The next two lines are the function hazard. Whichever input moves first, eq pulses to 1 for one gate delay, though it is 0 before and after.

The last line changes both inputs in the same instant. The ideal simulator then shows no glitch. Real wires never match that well, so do not rely on it.

Change the bench so that v moves 2 ns after u. How wide is the pulse on eq now?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: s falls: y = 1@12 0@13 1@14 u then v, 01 to 10: eq = 1@22 0@23 v then u, 10 to 01: eq = 1@33 0@34 both at once: eq = no change
Read included file: tb.sv
// tb.sv: lists every output change as value@time (read-only).
`timescale 1ns/1ns
module tb;
  logic  a = 1, b = 1, s = 1, u = 0, v = 1;
  wire   y, eq;
  string seen;
  gated_mux u1 (.a(a), .b(b), .s(s), .y(y));
  equal     u2 (.a(u), .b(v), .eq(eq));
  always @(y)  if ($time > 5) seen = {seen, $sformatf(" %b@%0d", y, $time)};
  always @(eq) if ($time > 5) seen = {seen, $sformatf(" %b@%0d", eq, $time)};
  task automatic show(input string what);
    #10 if (seen.len() == 0) seen = " no change";
    $display("%-25s%s", what, seen);
    seen = "";
  endtask
  initial begin
    seen = "";
    #10 s = 0;           show("s falls: y =");
    u = 1; #1 v = 0;     show("u then v, 01 to 10: eq =");
    v = 1; #1 u = 0;     show("v then u, 10 to 01: eq =");
    u = 1; v = 0;        show("both at once: eq =");
  end
endmodule

Check Yourself

ConceptWhich output pattern is a dynamic hazard on a signal that should go from 1 to 0?
ConceptA function is 1 on rows 00 and 11 of its inputs a and b, and 0 on rows 01 and 10. The inputs move from 00 to 11. What can the output do?
Read the waveformA combinational enable glitches in cycle 2. A flop samples it at the clock edge that ends each cycle. What does the flop store at the end of cycle 2?
A glitch between clock edges
01234clkenablesampled
Scroll horizontally ↔

The pulse on enable starts and ends inside cycle 2, before the edge.

ConceptWhy can a two-level sum of products not show a dynamic hazard when one input changes?
Predict the outputIn the equality detector, u rises at t = 10 and v falls 2 ns later, at t = 12. Predict the exact line.
`timescale 1ns/1ns
module tb;
  logic u = 0, v = 1;
  wire  nu, nv, t0, t1, eq;
  time  up, down;
  not #1 g1 (nu, u);
  not #1 g2 (nv, v);
  and #1 g3 (t0, nu, nv);
  and #1 g4 (t1, u, v);
  or  #1 g5 (eq, t0, t1);
  always @(posedge eq) if ($time > 5) up = $time;
  always @(negedge eq) if ($time > 5) down = $time;
  initial begin
    #10 u = 1; #2 v = 0;
    #10 $display("eq high from t=%0d to t=%0d", up, down);
  end
endmodule

Common Mistakes

Wrong Add consensus terms to fix a glitch caused by two inputs changing.

A function hazard comes from the function itself. The equality detector has every prime and still glitches.

Fix Sample the output with a clock after it settles, or make only one input change at a time.

Wrong Drive an asynchronous reset or a clock from combinational logic.

These pins act on any pulse. In the predict item a 1 ns glitch cleared a flop that should have kept its 1.

Fix Drive clocks and asynchronous resets from a flip-flop or from a dedicated, glitch-free cell.

Wrong Worry about glitches on every data signal.

A flop samples its D input only at the clock edge. A glitch that dies before the edge leaves no trace.

Fix Make sure data settles before the edge (G5.8). Glitch-free logic matters on clocks, resets and latch enables.

Wrong Assume two inputs that change "at the same time" really do.

Wires and drivers differ, so one input always moves first. Only the ideal simulation with zero skew showed no glitch.

Fix Analyse both orders of a multiple-input change.

Remember

  • A dynamic hazard is three or more edges where one is needed; it needs three paths and occurs in multilevel logic.
  • A two-level cover with every prime has no hazard for a single input change.
  • A function hazard comes from two inputs changing: some order passes a row of the other value, in any circuit.
  • Glitches matter on clocks, asynchronous resets and latch enables; data sampled at a clock edge may glitch freely.

Practice

Report a problem with this page