G4.3.1 The Decoder with a Dead Output

EasyDebugIcarus · browser samples / server checksReview the topic

Trace a relay that never closes to the first cycle where a 3-to-8 decoder shows a wrong output, and name the cause.

Hardware context: Relay boards, a repair board and a controller with active-low device lines, all driven by 3-to-8 decoders. Find the first wrong output of a relay decoder and name the bug.

A test rig closes one of eight relays at a time through a 3-to-8 decoder. Relay k closes when en = 1 and a = k. On the first run the operator reports that relay 5 never clicks. The test ends with: ERROR: relay 5 closed 0 times; the commands called for 2. The bench is correct. The bug is in the decoder.

Run the failing test to see its log and waveform. In each cycle the bench sends one command, waits for the decoder to settle and counts the relays that closed.

Step 1: find the first cycle where y shows a value a correct decoder would not. Step 2: choose the cause from four possible bugs; each is real and fails in a different cycle. Step 3 is optional: fix the decoder and run the tests (lesson G4.3).

Signals in the Timeline

SignalWidthRole
script32input of each check
Full specification
The decoder's ports
module relay_dec (
  input  logic [2:0] a,         // which relay
  input  logic       en,        // 1: close the addressed relay
  output logic [7:0] y          // y[k] = 1 closes relay k
);
  ...
endmodule
RuleCorrect decoder
en = 0y = 00000000: no relay closes.
en = 1Exactly one bit of y is 1: bit a.
memoryNone: y depends only on this cycle's en and a.
Cycleena
003
111
212
314
415
505
617
715
816
900

Cycle N is the stretch where the cycle counter shows N. The fix tests apply eight (en, a) commands, one per nanosecond, and record y after each.

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

Every Address, Enabled
Input
en=1 a=0; en=1 a=1; en=1 a=2; en=1 a=3; en=1 a=4; en=1 a=5; en=1 a=6; en=1 a=7
Output
y_step0 = 'b00000001, y_step1 = 'b00000010, y_step2 = 'b00000100, y_step3 = 'b00001000, y_step4 = 'b00010000, y_step5 = 'b00100000, y_step6 = 'b01000000, y_step7 = 'b10000000

With en = 1, address k sets only bit k of y: 00000001 for 0 up to 10000000 for 7.

Example 2

Every Address, Disabled
Input
en=0 a=0; en=0 a=1; en=0 a=2; en=0 a=3; en=0 a=4; en=0 a=5; en=0 a=6; en=0 a=7
Output
y_step0 = 'b00000000, y_step1 = 'b00000000, y_step2 = 'b00000000, y_step3 = 'b00000000, y_step4 = 'b00000000, y_step5 = 'b00000000, y_step6 = 'b00000000, y_step7 = 'b00000000

With en = 0 no relay closes, whatever the address.

Example 3

Addresses Whose Bits Read the Same Backwards
Input
en=1 a=0; en=1 a=2; en=1 a=5; en=1 a=7; en=0 a=2; en=1 a=5; en=0 a=7; en=1 a=0
Output
y_step0 = 'b00000001, y_step1 = 'b00000100, y_step2 = 'b00100000, y_step3 = 'b10000000, y_step4 = 'b00000000, y_step5 = 'b00100000, y_step6 = 'b00000000, y_step7 = 'b00000001

Addresses 0, 2, 5 and 7 read the same from either end. Each still sets its own bit when enabled.

Constraints and Contract

  • en and a are known 0/1 values.
  • Keep the module name and the ports.

Hints

Hint 1

Work out y yourself for each cycle from the table: en = 0 gives all zeros, en = 1 sets bit a. Compare with the waveform from cycle 0 on.

Hint 2

The first wrong cycle is not always the cycle that the error message talks about. Four different bugs would each go wrong in a different cycle.

Hint 3

In the first wrong cycle, ask what y shows instead: nothing at all, a different relay, or two relays. Each answer points to a different cause.

What the grader checks: The failing run is simulated live with the shipped decoder. The correct and each buggy decoder run on the same ten-cycle bench. That gives the first bad cycle and the first wrong value of every option. The optional fix is compared with a model written in JavaScript on five directed and eight seeded scripts of eight commands.

13 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 4 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

Every Address, Enabled

Input
en=1 a=0; en=1 a=1; en=1 a=2; en=1 a=3; en=1 a=4; en=1 a=5; en=1 a=6; en=1 a=7
Expected output
y_step0 = 'b00000001, y_step1 = 'b00000010, y_step2 = 'b00000100, y_step3 = 'b00001000, y_step4 = 'b00010000, y_step5 = 'b00100000, y_step6 = 'b01000000, y_step7 = 'b10000000

With en = 1, address k sets only bit k of y: 00000001 for 0 up to 10000000 for 7.

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

Icarus · browser samples / server checks