G5.5.1 The Latch That Let Data Through

MediumDebugIcarus · browser samples / server checksReview the topic

Find the first cycle where a capture register showed a value too early, and name the mistake that made it a latch.

Hardware context: A capture register that stores a sensor reading at each rising clock edge, with a clear and a load enable. Diagnose a register written as a latch and repair it as a flip-flop.

A capture register should store a sensor reading at a rising clock edge: clear wins, then load, else hold. In the system, the reading changes shortly after each edge, while the clock is still high. The register showed new readings one cycle early, and the test below ends with errors. The bench is correct.

Run the failing test to see its log and waveform.

Step 1: find the first cycle where held shows a value a correct register would not, and name the signal. Step 2: choose the cause from four real bugs; each fails in a different way. Step 3 is optional: fix the register and run the tests.

Signals in the Timeline

SignalWidthRole
script40input of each check
Full specification
The register's ports
module capture (
  input  logic       clk,
  input  logic       clr,    // at a rising edge: clear to 00 (wins over load)
  input  logic       load,   // at a rising edge: load din
  input  logic [7:0] din,
  output logic [7:0] held
);
  ...
endmodule
At a rising edge of clkheld becomes
clr = 100
clr = 0, load = 1din
clr = 0, load = 0held (no change)
SignalIn each cycle
clr, load, dinSet 2 ns after the rising edge that starts the cycle, while clk is still high.
heldMust change only at a rising edge of clk.

Cycle N is the stretch where the cycle counter shows N. The fix tests make four rising edges and change din while the clock is high after each one.

Diagnose the Failing Run

The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.

Log

Waveform

Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.

Step 1 · The first bad cycle and signal
Step 2 · The cause

Step 3 is optional: fix the code in the editor, then run the tests.

Examples

Example 1

Clear, Then Load Twice
Input
clr=1 load=0 din=11, clr=0 load=1 din=3c, clr=0 load=1 din=a5, clr=0 load=0 din=ff
Output
held_edge1 = 0x0, held_edge2 = 0x3c, held_edge3 = 0xa5, held_edge4 = 0xa5

Edge 1 clears, edges 2 and 3 load 3c and a5, edge 4 holds a5. The complement of din that arrives while the clock is high must never show.

Example 2

Load, Hold, Hold, Load
Input
clr=1 load=1 din=00, clr=0 load=1 din=80, clr=0 load=0 din=01, clr=0 load=1 din=7e
Output
held_edge1 = 0x0, held_edge2 = 0x80, held_edge3 = 0x80, held_edge4 = 0x7e

Clear wins at edge 1. Edge 2 loads 80, edge 3 holds it, edge 4 loads 7e.

Example 3

Clear Wins over Load
Input
clr=0 load=1 din=55, clr=1 load=1 din=aa, clr=0 load=0 din=0f, clr=0 load=1 din=f0
Output
held_edge1 = 0x55, held_edge2 = 0x0, held_edge3 = 0x0, held_edge4 = 0xf0

Edge 1 loads 55. At edge 2 both clr and load are 1, and clear wins: 00.

Constraints and Contract

  • clr, load and din are known 0/1 values.
  • Keep the module name and the ports.

Hints

Hint 1

A correct register shows, during a cycle, the value stored at the edge that started it. Work that value out for each cycle from the inputs of the cycle before.

Hint 2

Look at the first cycle where load is 1. Does held change at the edge, or 2 ns later, when din changes?

Hint 3

A value that follows din while the clock is high comes from a level-sensitive element, not from an edge.

What the grader checks: The failing run is simulated live with the shipped register. The first bad cycle and every option's first wrong value come from simulations on the same eight-cycle bench. The fix is compared with a JavaScript model on fifteen scripts of four edges. In each, din changes while the clock is high.

15 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Clear, Then Load Twice

Input
clr=1 load=0 din=11, clr=0 load=1 din=3c, clr=0 load=1 din=a5, clr=0 load=0 din=ff
Expected output
held_edge1 = 0x0, held_edge2 = 0x3c, held_edge3 = 0xa5, held_edge4 = 0xa5

Edge 1 clears, edges 2 and 3 load 3c and a5, edge 4 holds a5. The complement of din that arrives while the clock is high must never show.

Run samples executes all 3 public checks. Check all tests runs 15 checks on the server.

Icarus · browser samples / server checks