1. A waveform draws each signal on one row along a time axis
A waveform records what value each signal had at each moment. Time runs along the horizontal axis
from left to right, and every signal gets one row. The rising edge of the clock clk is the reference
against which every other row is read.
The waveform below shows the register d → q from the previous unit over six cycles. One cycle is
eight characters wide, and the gap between two cycles is a rising edge. The edge numbers are written
under the edge row.
cycle 0 1 2 3 4 5
clk ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____
edge ^ ^ ^ ^ ^ ^
0 1 2 3 4 5
d 00000000 11111111 11111111 00000000 11111111 00000000
q 00000000 00000000 11111111 11111111 00000000 11111111Cycles and edges are numbered by one rule.
| Name | Meaning |
|---|---|
| Edge n | the n-th rising edge, counted from 0 |
| Cycle n | the interval that edge n ends |
| Cycle 0 | the first interval, with the register already holding its initial value 0; its left boundary is the unnumbered start |
Read the q row with that rule. During cycle 1, d is 1; edge 1, which ends cycle 1, stores that 1;
so q is 1 from cycle 2 on. The q row is the d row shifted one cycle to the right, and that shift
is the register's one-cycle delay.
The lab tables and the waveform line up like this: the "before the edge" column is the value visible
during that cycle, and the "after the edge" column is the value visible during the next cycle. In
cycle 1 the table says "q after the edge: 1"; in the waveform, q is 1 during cycle 2. They are the
same fact.
2. Inputs are driven in the cycle, sampled at the edge, observed after it
A cycle contains three distinct moments.
| Moment | Who | What |
|---|---|---|
| Drive | the testbench | sets the input values during the cycle |
| Sample | the register | stores the inputs present at the edge that ends the cycle |
| Observe | the testbench | reads the outputs after the edge and compares them with the expectation |
After the simulator has processed the register updates scheduled for an edge, Q shows the new value. Before the edge it still shows the old value. A testbench that reads in the same simulation instant must respect that event ordering; merely detecting the edge does not guarantee the update is done. Combinational connections do not wait for a clock edge.
Caution. In a zero-delay RTL simulation, a register output can change at the same timestamp as the edge, with no visible gap. Real hardware has a clock-to-Q delay: a short time after the edge before Q settles. The order in which a simulator processes events within one instant is not a model of that physical delay, so do not read a zero-width change in a waveform as "hardware that switches instantly".
Check
d is 0 in cycles 0 and 1 and 1 from cycle 2 onward. In which cycle is q first 1?
3. One register stage delays by one cycle, two stages by two
In delay2, two registers in a row, the next value of s1 is in and the next value of s2 is the
current value of s1. In the waveform the s1 row is the in row shifted right by one cycle, and the
s2 row by two.
cycle 0 1 2 3 4 5
clk ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____ ‾‾‾‾____
edge ^ ^ ^ ^ ^ ^
0 1 2 3 4 5
in 11111111 00000000 11111111 11111111 00000000 00000000
s1 00000000 11111111 00000000 11111111 11111111 00000000
s2 00000000 00000000 11111111 00000000 11111111 11111111| Cycle | in (at the edge) | s1 before | s2 before | s1 after | s2 after |
|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 1 |
| 2 | 1 | 0 | 1 | 1 | 0 |
| 3 | 1 | 1 | 0 | 1 | 1 |
Two numbers describe such a chain, and they must be kept apart.
| Number | Meaning | One stage | Two stages |
|---|---|---|---|
| Latency | cycles from an input until it appears at the output | 1 | 2 |
| Throughput | values accepted per cycle | 1 | 1 |
Adding stages lengthens the wait but does not slow the flow: a new value enters every cycle and one
value leaves every cycle. In the experiment, change in every cycle while pressing edges and watch the
same value appear one cycle later on s1 and another cycle later on s2.
Concept experiment · delay2
A browser model of the circuit, not a compiled design. The real toolchain runs in the examples.
Inputs
Outputs
- s1
- 0
- s2
- 0
No edge has happened yet. Set the inputs, then apply a clock edge.
Now fill in the missing waveform. From the in column, write s1 and s2 after each edge. Both
registers start at 0 in cycle 0.
Predict, then compare · delay2
Fill in each cell before comparing. Empty cells count as a mismatch.
| Cycle | ininputs sampled at the edge | s1after the edge | s2after the edge |
|---|---|---|---|
| 0 | 1 | ||
| 1 | 1 | ||
| 2 | 0 | ||
| 3 | 1 | ||
| 4 | 0 | ||
| 5 | 0 | ||
| 6 | 1 |
4. Find the first cycle where two waveforms differ
To compare waveforms, find the first cycle that differs and then look at how the rest differs. The two
tables below show s2 of delay2 for the same in. The first is the expectation computed from the
requirement; the second was observed by simulating some design. Both list values after the edge.
| Cycle | in | Expected s2 |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 2 | 1 | 0 |
| 3 | 1 | 1 |
| 4 | 0 | 1 |
| 5 | 1 | 0 |
| 6 | 0 | 1 |
| Cycle | in | Observed s2 |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 2 | 1 | 1 |
| 3 | 1 | 1 |
| 4 | 0 | 0 |
| 5 | 1 | 1 |
| 6 | 0 | 0 |
Check
In which cycle do the expected and observed values first differ?
5. Variation: a rising-edge detector
In the cycle-by-cycle model, inputs are held constant throughout each cycle. Under that assumption,
rise-detect turns a 0-to-1 change of the input into a pulse one cycle long. The register prev
remembers last cycle's in, and the output rise is 1 when in is 1 and prev is 0.
| Signal | Kind | Value |
|---|---|---|
prev | register | the in stored at the last edge |
rise | combinational logic | the current in AND NOT the current prev |
Because rise is not a register, it does not wait for an edge. It becomes 1 in the very cycle in
goes to 1, and when the next edge updates prev to 1 it falls back to 0 for the same in. In the lab
table the rise column is the value during the cycle, not a value after the edge. Raise in to 1 and
press several edges: rise is 1 in the first of those cycles only. If a physical input changes partway
through a cycle, this combinational pulse need not last a full period.
Concept experiment · rise-detect
A browser model of the circuit, not a compiled design. The real toolchain runs in the examples.
Inputs
Outputs
- prev
- 0
- rise
- 0
No edge has happened yet. Set the inputs, then apply a clock edge.
Check
in is 1 in cycles 2, 3 and 4 and 0 in every other cycle. In which cycles is rise 1?
6. Summary
- A waveform has time along the horizontal axis and one row per signal; the rising edge of
clkis the reference for reading it. - Edge n ends cycle n, and cycle 0 starts from the initial value. In the lab tables, "before the edge" is the value visible during that cycle and "after the edge" the value visible during the next.
- Inputs are driven during the cycle, sampled at the edge, and observed after the edge.
- In a simulator's waveform a register output changes at the edge itself; real hardware has a clock-to-Q delay.
- n register stages raise the latency to n cycles and leave the throughput unchanged.
- Compare two waveforms from the first cycle that differs.
The next chapter takes a requirement apart into test cases, separates the roles of the design and its testbench, and reasons from a first mismatch to a likely cause.