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.
- Cycle 1
sfalls. The function y = s'a goes from 0 to 1. - Cycle 3
nsrose at 11 whilemwas still 1, soyrises at 12. - Cycle 4
The inner mux has a static-1 hazard:
mdips at 12, andyfollows at 13. - Cycle 5
mrecovers, andyrises 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.
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.
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.
| Change | Path taken | Measured eq |
|---|---|---|
| u then v, 01 to 10 | 01 → 11 → 10 | 1@22 0@23 |
| v then u, 10 to 01 | 10 → 11 → 01 | 1@33 0@34 |
| both at once, 01 to 10 | 01 → 10 | no 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
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.
Products of sums
The dual: every pair of adjacent 0 cells lies inside one sum term.
Multilevel circuits
Factoring can bring back static and dynamic hazards. Check the factored circuit, not only the cover it came from.
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.
- Datapath
- I/O
- Clock / reset
- Control / FSM
- Data
- Reset
- Clock
- Control
- Sampled
A D input is read only at the clock edge. A glitch that ends before the edge leaves no trace.
- 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.
| Input | What a glitch does |
|---|---|
| Clock of a flip-flop | An extra edge: the flop loads early, or a counter counts twice (G5.9). |
| Asynchronous set or reset | The flop is cleared or set in the middle of a cycle. |
| Enable of a latch, S or R of an SR latch | The latch opens or flips for the width of the glitch. |
| Any wire, for power | Each 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
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.
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.
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?
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 changeRead 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
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.