3.3 Gate delays and glitches
Why this matters
Until now a gate's output has changed the instant its input did. Real gates are not that fast, and the difference can matter: a circuit whose output should never change can still twitch for a moment while a change makes its way through the gates. This section shows where that twitch comes from, using a circuit that could matter a great deal, and how to work out when an output is first safe to trust.
Learning goals
Section titled “Learning goals”- Define propagation delay and say what a glitch is.
- Draw the waveform of every net in a small circuit when each gate has its own delay.
- Find a glitch in a delay waveform and explain which two paths cause it.
- Work out how long after power-up an output first has a known value, from the gate delays.
- Say why a zero-delay simulation cannot show a glitch.
Intuition first
Section titled “Intuition first”Imagine two couriers leaving the same office at the same moment, one with the message "stop" and one with the message "go", each to the same warehouse, by different routes. If the stop courier arrives first, the warehouse is stopped for a while until the go courier arrives. Nobody did anything wrong, and the final instruction, go, is what was meant. But for the time between the two arrivals the warehouse was doing the wrong thing.
A circuit with two routes from one input to one output works the same way. Gates are the couriers: each takes a little time to turn a change at its inputs into a change at its output. If one input reaches the output by two routes of different length, the output can follow the short route's message first and the long route's message later. For a programmer, this is a race between two threads that read one shared value. The analogy breaks in this way: a circuit has no scheduler. Which route wins is decided by the delays of the gates on each route, not by chance in the program, but those delays differ from chip to chip.
Delay and glitches
Section titled “Delay and glitches”The propagation delay of a gate is the time between a change at one of its inputs and the resulting change at its output. In the models of this section each gate kind has a fixed delay. A gate whose delay is 0 passes a change to its output at the same instant.
A glitch is a brief, unwanted change at the output of a combinational circuit while a change is still travelling through it. Usually the output leaves a value it should keep and returns to it a short time later; it can also change more than once on the way to a new value (Section 3.8).
A glitch is not a function of the circuit's truth table, which says only what the output is once everything has settled. It is a property of the timing. Section 3.8 returns to when a circuit can glitch and how to design one that cannot.
The autopilot circuit
Section titled “The autopilot circuit”An autopilot has three inputs. CAR is a request from the copilot, PAR is a request from the pilot, and PIC says whether the pilot is in charge. The output AE says the autopilot is engaged. The rule is that the autopilot is engaged when whoever is in charge asks for it: . Three nets inside the circuit are named: pic_n is the inverted PIC, via_copilot is the output of the copilot's AND gate, and via_pilot is the output of the pilot's.
Only NOT, AND, OR gates (1 NOT, 2 AND, 1 OR). 4 gates in all.
A logic schematic with inputs CAR, PIC and PAR and output AE.
NOT gate g_a: input PIC; output pic_n.
AND gate g_b: inputs CAR and pic_n; output via_copilot.
AND gate g_c: inputs PIC and PAR; output via_pilot.
OR gate g_ae: inputs via_copilot and via_pilot; output AE.
It agrees with the function logic:ch03/autopilot#AE.
Description: A NOT gate takes PIC and produces pic_n. An AND gate takes CAR and pic_n and produces via_copilot. A second AND gate takes PAR and PIC and produces via_pilot. An OR gate takes via_copilot and via_pilot and produces AE.
Suppose both requests, CAR and PAR, are 1 and the pilot hands charge to the copilot, so that PIC falls from 1 to 0. Whoever is in charge, an autopilot request is on, so AE should be 1 before the change and 1 after. Now give every gate the same delay, and call it one gate delay. Follow the change from the moment PIC falls.
- One gate delay later, the NOT gate has responded:
pic_nrises. At the same moment the pilot's AND gate has responded to PIC alone:via_pilotfalls. - One more gate delay later, the copilot's AND gate has seen
pic_nrise, sovia_copilotrises. At the same moment the OR gate, which sawvia_pilotfall one delay ago whilevia_copilotwas still low, responds, and AE falls. - One more delay later, the OR gate sees
via_copilothigh and AE rises again.
The output is 1, then 0 for exactly one gate delay, then 1. The route PIC to via_pilot to the OR gate is two gates long, and the route PIC to the NOT gate to via_copilot to the OR gate is three. The short route carries the message "the pilot's request no longer counts" two gate delays after PIC fell, and the long route carries "the copilot's request counts" a delay later. In between, neither request counts.
In SystemVerilog
Section titled “In SystemVerilog”The circuit, written without gate delays, is a module of four assignments. Its internal nets have the names used in the figure.
// Autopilot request logic. PIC says the pilot is in charge. The autopilot is engaged (AE) when the copilot// requests it and the pilot is not in charge, or when the pilot requests it and the pilot is in charge.module autopilot ( input logic CAR, // copilot autopilot request input logic PAR, // pilot autopilot request input logic PIC, // pilot in charge output logic AE // autopilot engaged); logic pic_n, via_copilot, via_pilot;
assign pic_n = ~PIC; assign via_copilot = CAR & pic_n; assign via_pilot = PAR & PIC; assign AE = via_copilot | via_pilot;endmoduleA testbench holds both requests high and lets PIC fall at time 60. The comments say that AE is 1 at the end of both steps.
// Testbench for autopilot with no gate delays: both requests stay high while the pilot hands over charge.module autopilot_tb(); logic CAR, PAR, PIC, AE;
autopilot dut(.*);
initial begin CAR = 1; PAR = 1; PIC = 1; #60; // expect: AE=1 PIC = 0; #60; // expect: AE=1 $stop; endendmoduleTime in ps; one column is 10 ps.
Timing diagram from simulation, ch03/autopilot-ideal: time in ps from 0 to 120, 12 columns of 10 ps.
CAR: 1 at 0, no changes.
PAR: 1 at 0, no changes.
PIC: 1 at 0, then 0 at 60.
dut.pic_n: 0 at 0, then 1 at 60.
dut.via_copilot: 0 at 0, then 1 at 60.
dut.via_pilot: 1 at 0, then 0 at 60.
AE: 1 at 0, no changes.
Description: A timing diagram of CAR, PAR, PIC, the internal nets pic_n, via_copilot and via_pilot, and AE. PIC falls halfway through the run. pic_n and via_copilot rise and via_pilot falls at the same instant as PIC, and AE stays high throughout.
In Figure 3.3.2 PIC falls at time 60. At that same instant pic_n rises, via_copilot rises and via_pilot falls, because every gate responds with no delay. AE does not change. Within that one instant the simulator updates the nets one after another, but no simulated time passes between the updates, so nothing a waveform can show happens to AE. The section slides say that the simulations in the course give every gate a delay of zero. (fact ch03/zero-delay-setup) A simulation like this cannot show a glitch, because a glitch lives in the time between two gates responding, and here that time is zero.
To see the glitch, the simulation needs a delay for each gate. This book never puts delays in a design file: synthesis ignores them, and the hardware's real delays depend on the chip, not on the source code. The book keeps them in a separate file marked as a model for simulation only. Gate primitives take a delay after their name: not #10 g_not (pic_n, PIC); is a NOT gate with a delay of ten time units, named g_not, whose output is the first signal in the parentheses.
// Simulation-only model of autopilot with a delay of 10 time units in every gate.module autopilot_delay ( input logic CAR, input logic PAR, input logic PIC, output logic AE); logic pic_n, via_copilot, via_pilot;
not #10 g_not (pic_n, PIC); and #10 g_copilot (via_copilot, CAR, pic_n); and #10 g_pilot (via_pilot, PAR, PIC); or #10 g_engage (AE, via_copilot, via_pilot);endmoduleThe book's tools check that this model computes the same function as the module above once everything has settled; they do not check that the glitch is the right size for any real chip. The testbench applies the same stimulus, then after PIC falls waits four steps of ten time units and a last step of twenty, with a comment on each line. A comment reads the output one time unit before its step ends, so the six comments see AE at times 59, 69, 79, 89, 99 and 119. They say AE is 1, 1, 1, 0, 1 and 1: the 0, read at time 89, is the dip.
// Testbench for the delay model of autopilot: the same stimulus as the zero-delay testbench, read every ten time units.module autopilot_delay_tb(); logic CAR, PAR, PIC, AE;
autopilot_delay dut(.*);
initial begin CAR = 1; PAR = 1; PIC = 1; #60; // expect: AE=1 PIC = 0; #10; // expect: AE=1 #10; // expect: AE=1 #10; // expect: AE=0 #10; // expect: AE=1 #20; // expect: AE=1 $stop; endendmoduleTime in ps; one column is 10 ps.
Timing diagram from simulation, ch03/autopilot-glitch: time in ps from 0 to 120, 12 columns of 10 ps.
CAR: 1 at 0, no changes.
PAR: 1 at 0, no changes.
PIC: 1 at 0, then 0 at 60.
dut.pic_n: unknown at 0, then 0 at 10, 1 at 70.
dut.via_copilot: unknown at 0, then 0 at 20, 1 at 80.
dut.via_pilot: unknown at 0, then 1 at 10, 0 at 70.
AE: unknown at 0, then 1 at 20, 0 at 80, 1 at 90.
Description: A timing diagram of CAR, PAR, PIC, the internal nets pic_n, via_copilot and via_pilot, and AE. All the nets inside the circuit start unknown and become known during the first two columns. After PIC falls, via_pilot falls and pic_n rises one column later, then via_copilot rises and AE falls another column later, and AE rises a column after that.
Read Figure 3.3.3 from left to right. PIC falls at time 60. One gate delay later, at time 70, pic_n rises and via_pilot falls. At time 80 via_copilot rises and AE falls. At time 90 AE rises again. So AE is 0 from time 80 to time 90, one gate delay, exactly what the hand trace said. At the left edge of the figure pic_n, via_copilot, via_pilot and AE start hatched: the simulator has no value for the output of a gate until one gate delay after enough of its inputs are known to decide it. pic_n and via_pilot become known at time 10, because the inputs are known from time 0. via_copilot becomes known at time 20, one delay after pic_n. AE is already known at time 20 as well, which is one delay after via_pilot. via_pilot is 1, and an OR gate with a 1 on one input is 1 whatever the other input is, so AE does not have to wait for via_copilot.
This dip belongs to this circuit, these delays and this direction of change. It is not something every circuit does, and it is not something this circuit does for every input change: Exercise 3.3.4 has PIC rising and uses the same gates and AE does not dip. Whether a circuit can glitch, and how to build one that cannot, is the subject of Section 3.8.
Suppose the NOT gate were twice as slow as the other gates, and PIC fell as before. What would happen to the dip in AE?
Course conventions
Section titled “Course conventions”How CSE 369 writes this
The slides draw each waveform on its own grid, so every figure has to say what a column is. In this section a column is 10 time units, which is one gate delay in the autopilot figures; the exercises with mixed delays say how long each gate takes. The lecture's autopilot waveform gives every gate the same delay, drawn as one column of the grid. (fact ch03/same-delay-lecture) The practice problems give different gate kinds different delays in one circuit. (fact ch03/mixed-delay-practice) Read the delay of every gate, including any that is 0, before you draw anything.
Pitfalls
Section titled “Pitfalls”Common pitfall
- Assuming a gate's output changes at the same instant as its input. Every gate takes a little time.
- Looking for a glitch in a zero-delay simulation, or concluding from one that a circuit has none.
- Treating the unknown values at the left edge of a delay simulation as a bug. They are there because nothing has reached the outputs yet.
- Giving the sum of the delays along the longest path as the time an output is known, in every case. That sum is a limit that the output does not exceed, and a controlling input can make the output known sooner.
- Drawing a delay waveform without writing down the delay of every gate first, including the gates whose delay is zero.
Check your understanding
Section titled “Check your understanding”Take the quiz (4 questions)
What does the zero-delay simulation of the autopilot show for AE when PIC falls with both requests high?
pic_n, via_copilot and via_pilot all change at the same simulated time as PIC, and one of via_copilot and via_pilot is high at every point of the waveform.In the delay waveform of the autopilot, AE is known at time 20, not 30. Why?
via_pilot becomes 1, which is time 20. It does not need via_copilot. The longest route through the circuit, which goes through the NOT gate, would give time 30.Which description fits a glitch?
A gate has a delay of 0. How does its output respond to a change at its input?
Exercises
Section titled “Exercises”The autopilot circuit is rebuilt with a slower NOT gate. The delays are: NOT 20, AND 10 and OR 10 time units, and one column of the figure is 10. Both requests are high from time 0, and PIC falls at time 60. Draw pic_n, via_copilot, via_pilot and AE for the whole run, including the unknown values at the start.
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/autopilot-slow-glitch: time in ps from 0 to 120, 12 columns of 10 ps.
CAR: 1 at 0, no changes.
PAR: 1 at 0, no changes.
PIC: 1 at 0, then 0 at 60.
Empty lanes for the reader to complete: dut.pic_n, dut.via_copilot, dut.via_pilot, AE.
Description: A timing diagram of CAR, PAR and PIC, with the lanes for pic_n, via_copilot, via_pilot and AE left empty.
Hint
Solution
Take each net in turn, in the order the signals reach them.
pic_n, the NOT gate: its input PIC is known from time 0, sopic_nis unknown until time 20 and is 0 from then on. PIC falls at 60, sopic_nrises at 80.via_pilot, the pilot's AND gate: it is unknown until time 10, and then 1. PIC falls at 60, sovia_pilotfalls at 70.via_copilot, the copilot's AND gate: its inputpic_nbecomes 0 at time 20, sovia_copilotbecomes 0 at time 30.pic_nrises at 80, sovia_copilotrises at 90.- AE, the OR gate:
via_pilotis 1 at time 10, so AE is 1 at time 20, even thoughvia_copilotis still unknown.via_pilotfalls at 70, so AE falls at 80.via_copilotrises at 90, so AE rises at 100.
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/autopilot-slow-glitch: time in ps from 0 to 120, 12 columns of 10 ps.
CAR: 1 at 0, no changes.
PAR: 1 at 0, no changes.
PIC: 1 at 0, then 0 at 60.
dut.pic_n: unknown at 0, then 0 at 20, 1 at 80.
dut.via_copilot: unknown at 0, then 0 at 30, 1 at 90.
dut.via_pilot: unknown at 0, then 1 at 10, 0 at 70.
AE: unknown at 0, then 1 at 20, 0 at 80, 1 at 100.
Description: The full timing diagram of CAR, PAR, PIC, pic_n, via_copilot, via_pilot and AE for the circuit with the slower NOT gate. AE is 0 from time 80 to time 100.
AE is 0 from time 80 to time 100, two columns, which is the delay of the NOT gate. The dip began when the pilot's route let go at time 80, and it lasted until the longer route through the NOT gate delivered, 20 later.
The circuit below has three gates with different delays: the AND gate 20, the NOT gate 10 and the OR gate 0, which means its output changes in the same instant as its input. All three inputs, P, Q and R, are 1 from time 0. How long after time 0 does G first have a known value, and what is it?
Only NOT, AND, OR gates (1 AND, 1 NOT, 1 OR). 3 gates in all.
A logic schematic with inputs P, Q and R and output G.
AND gate g_and: inputs P and Q; output n1.
NOT gate g_not: input R; output n2.
OR gate g_or: inputs n1 and n2; output G.
It agrees with the function logic:ch03/s03-known#G.
Description: An AND gate takes P and Q and produces n1. A NOT gate takes R and produces n2. An OR gate takes n1 and n2 and produces G.
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/known-all-ones: time in ps from 0 to 60, 6 columns of 10 ps.
P: 1 at 0, no changes.
Q: 1 at 0, no changes.
R: 1 at 0, no changes.
Empty lanes for the reader to complete: dut.n1, dut.n2, G.
Description: A timing diagram of P, Q and R, all high for the whole run, with the lanes for n1, n2 and G left empty.
Hint
Solution
- n1, the AND gate: known 20 after its inputs are known, so at time 20. With P and Q both 1, it is 1.
- n2, the NOT gate: known at time 10. With R equal to 1, it is 0.
- G, the OR gate, which takes no time: it needs both n1 and n2. n2 is 0 from time 10, which does not decide the OR, so G stays unknown until n1 is known at time 20. At time 20 G is 1, since n1 is 1.
So G is first known at time 20, which is the sum of the delays along the longest route, AND 20 plus OR 0.
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/known-all-ones: time in ps from 0 to 60, 6 columns of 10 ps.
P: 1 at 0, no changes.
Q: 1 at 0, no changes.
R: 1 at 0, no changes.
dut.n1: unknown at 0, then 1 at 20.
dut.n2: unknown at 0, then 0 at 10.
G: unknown at 0, then 1 at 20.
Description: The full timing diagram of P, Q, R, n1, n2 and G. n2 becomes 0 at time 10, and n1 and G become 1 at time 20.
The same circuit and delays as in the previous exercise, with P and Q equal to 1 as before, but now R is 0 from time 0. How long after time 0 does G first have a known value? Is it the same as before? Why or why not?
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/known-r-low: time in ps from 0 to 60, 6 columns of 10 ps.
P: 1 at 0, no changes.
Q: 1 at 0, no changes.
R: 0 at 0, no changes.
Empty lanes for the reader to complete: dut.n1, dut.n2, G.
Description: A timing diagram of P and Q, which are high, and R, which is low, for the whole run, with the lanes for n1, n2 and G left empty.
Hint
Solution
n2 is known at time 10, and with R equal to 0 it is 1. An OR gate with a 1 on one input outputs 1 whatever its other input is, so G is known at time 10, as soon as n2 is. The AND gate's output n1 does not become known until time 20, but G no longer needs it. So G is known at time 10, not at time 20.
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/known-r-low: time in ps from 0 to 60, 6 columns of 10 ps.
P: 1 at 0, no changes.
Q: 1 at 0, no changes.
R: 0 at 0, no changes.
dut.n1: unknown at 0, then 1 at 20.
dut.n2: unknown at 0, then 1 at 10.
G: unknown at 0, then 1 at 10.
Description: The full timing diagram of P, Q, R, n1, n2 and G. n2 and G become 1 at time 10, and n1 becomes 1 at time 20.
The sum of the delays on the longest route, 20, is a limit and not a prediction. Whether an output is known earlier depends on the input values: an input that decides a gate by itself, a 1 into an OR gate or a 0 into an AND gate, lets the output be known without waiting for the others.
The autopilot circuit with one gate delay for every gate, as in the section. Now PIC starts at 0 and rises to 1 at time 60, with both requests high. Draw pic_n, via_copilot, via_pilot and AE. Does AE glitch?
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/autopilot-rise: time in ps from 0 to 120, 12 columns of 10 ps.
CAR: 1 at 0, no changes.
PAR: 1 at 0, no changes.
PIC: 0 at 0, then 1 at 60.
Empty lanes for the reader to complete: dut.pic_n, dut.via_copilot, dut.via_pilot, AE.
Description: A timing diagram of CAR, PAR and PIC, with PIC rising halfway through the run, and the lanes for pic_n, via_copilot, via_pilot and AE left empty.
Hint
via_copilot should be 1 and via_pilot should be 0. Follow the rise of PIC along both routes.Solution
At the start, pic_n is known at time 10 and is 1, because PIC is 0. via_pilot is known at time 10 and is 0. via_copilot is known at time 20 and is 1. AE needs via_copilot, since via_pilot is 0 and does not decide an OR, so AE is known at time 30 and is 1.
PIC rises at time 60.
- At time 70, one gate delay later,
pic_nfalls andvia_pilotrises. - At time 80,
via_copilotfalls. AE has seenvia_pilotrise and stays 1. - AE never changes.
Time in ps; one column is 10 ps.
Timing diagram from simulation, ch03/autopilot-rise: time in ps from 0 to 120, 12 columns of 10 ps.
CAR: 1 at 0, no changes.
PAR: 1 at 0, no changes.
PIC: 0 at 0, then 1 at 60.
dut.pic_n: unknown at 0, then 1 at 10, 0 at 70.
dut.via_copilot: unknown at 0, then 1 at 20, 0 at 80.
dut.via_pilot: unknown at 0, then 0 at 10, 1 at 70.
AE: unknown at 0, then 1 at 30.
Description: The full timing diagram of CAR, PAR, PIC, pic_n, via_copilot, via_pilot and AE. After PIC rises, via_pilot rises and pic_n falls one column later, then via_copilot falls, and AE stays high.
AE does not glitch. When PIC rises, the pilot's route raises the pilot's request before the copilot's route lowers the copilot's, so there is always one request on. With both requests high, the same circuit and the same delays glitch when PIC falls and not when it rises: the direction of the change matters.