B4.4.1 The Total That Came Out Short

EasyDebug20 minIcarus · browser samples / server checksReview the topic

A packet adder reports a wrong total at the end of the first packet. Walk back from the wrong total to the cycle where the sum first went wrong, name the bug, and fix it.

Hardware context: Small designs with one output that comes out wrong: a UART transmitter, a packet adder and a pulse generator. Debugging a failing test from its log.

sum8 adds up the bytes of each packet and reports the total in the clock after the final byte. The bench sends three packets, with idle clocks between some bytes, and compares every total with its own sum.

Run the failing test below and read its log and its waveform. The waveform also shows acc, the sum so far, inside the design.

Step 1: find the first cycle where total, done or acc is not what the specification says, and name the signal. Step 2: choose the cause. Step 3, optional: fix sum8; the fix is graded by the normal rows.

Signals in the Timeline

SignalWidthRole
scenario8input of each check
Full specification
The ports
// sum8: adds up the bytes of a packet. A byte counts when valid is 1; last (with valid) marks the packet's final byte.
// In the clock after the final byte, done is 1 for one clock and total holds the packet's sum; the next packet starts from 0.
module sum8 (input logic clk, rst, valid, last, input logic [7:0] din, output logic [11:0] total, output logic done);
  ...
endmodule

total keeps its value until the next packet ends. While valid is 0, din may hold any value and must be ignored. Cycle N is the stretch after the N-th falling edge of the bench's clock.

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

One Packet of Three Bytes
Input
1, 2, 3 (last)
Output
done_clocks = 1, total1 = 6, total2 = 0, total3 = 0

1 + 2 + 3 = 6, reported once: done is 1 for one clock.

Example 2

Two Packets Back to Back
Input
10, 20 (last), 30, 40 (last)
Output
done_clocks = 2, total1 = 30, total2 = 70, total3 = 0

The second packet starts from 0: 30 + 40 = 70, not 100.

Example 3

A Packet Whose Sum Passes 255
Input
200, 100, 50 (last)
Output
done_clocks = 1, total1 = 350, total2 = 0, total3 = 0

200 + 100 + 50 = 350 needs more than 8 bits; total has 12.

Constraints and Contract

  • Keep the module name, the ports and the name acc.
  • Reset is synchronous and active high.

Hints

Hint 1

Start from the first ERROR line: which packet, which total?

Hint 2

Work out acc by hand for each byte of that packet and compare it with the waveform.

Hint 3

Each cause shows first in a different cycle or on a different signal.

What the grader checks: The failing run is simulated live with the shipped adder. The fix is graded on six scripts of bytes, each after reset. Each row reports the first three totals seen with done, and how many clocks done was 1.

6 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 2 problems on this path

Report a problem with this page

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

One Packet of Three Bytes

Input
1, 2, 3 (last)
Expected output
done_clocks = 1, total1 = 6, total2 = 0, total3 = 0

1 + 2 + 3 = 6, reported once: done is 1 for one clock.

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

Icarus · browser samples / server checks