Altifigence Academy

25 / 63 · Lab

Lab: exhaustive MUX testing and registered-output analysis

Apply the same inputs to combinational and registered paths, and verify results against the truth table and sampling times.

The circuit and observation conditions

When sel is 0, y equals a; when sel is 1, y equals b. sampled_y stores y at a rising clock edgeRising edge The instant at which the clock changes from 0 to 1. Distinguish it from a level, which refers to the entire interval during which CLK=1. Learn more. Even if inputs change, sampled_y holds until the next rising edge.

Before starting

Prepare a Digital Design Studio Desktop project with permission to run it normally. Save each example as rtl/top.sv in a separate folder.

First make a and b different. Verify y=a for sel=0 and y=b for sel=1, then compare against each row of the input file.

Change the selected path directly

y = sel ? b : a

SystemVerilog source

SystemVerilog
module top (
    input logic clk,
    input logic a,
    input logic b,
    input logic sel,
    output logic y,
    output logic sampled_y
);
    assign y = sel ? b : a;
    // Explicit observation register: y remains purely combinational.
    // The register makes this design eligible for logic-netlist-1 simulation.
    always_ff @(posedge clk) sampled_y <= y;
endmodule

Running the lab

In New analysis, select Two-state single-clock v1. Set Clock port to clk and period to 1000ps. Use the following settings, run Preflight, then Run RTL simulation, and compare results.

SettingValue
Initial register values (LSB first)[false]
Reset portLeave empty
Maximum cycles / time8 / 8000ps

Each column below corresponds to one item in the input file. Expected combinational y is 0,0,0,1,1,0,1,1. This diagram predicts the function in input order; it does not include sampled_y update times.

All eight input-JSON combinations at a glance
View waveform data
Wave data: each character is one interval; a dot holds the previous state; p is a clock cycle.
SignalWaveBus values
a0...1...
b0.1.0.1.
sel01010101
y expected0..1.01.

Input stimulus

json
[
  {
    "inputs": {
      "a": [
        false
      ],
      "b": [
        false
      ],
      "sel": [
        false
      ]
    }
  },
  {
    "inputs": {
      "a": [
        false
      ],
      "b": [
        false
      ],
      "sel": [
        true
      ]
    }
  },
  {
    "inputs": {
      "a": [
        false
      ],
      "b": [
        true
      ],
      "sel": [
        false
      ]
    }
  },
  {
    "inputs": {
      "a": [
        false
      ],
      "b": [
        true
      ],
      "sel": [
        true
      ]
    }
  },
  {
    "inputs": {
      "a": [
        true
      ],
      "b": [
        false
      ],
      "sel": [
        false
      ]
    }
  },
  {
    "inputs": {
      "a": [
        true
      ],
      "b": [
        false
      ],
      "sel": [
        true
      ]
    }
  },
  {
    "inputs": {
      "a": [
        true
      ],
      "b": [
        true
      ],
      "sel": [
        false
      ]
    }
  },
  {
    "inputs": {
      "a": [
        true
      ],
      "b": [
        true
      ],
      "sel": [
        true
      ]
    }
  }
]

Compare results

8 cycles · y=1 · sampled_y=1. At 3000ps, check that y=1 while sampled_y=0.

This lab uses 0/1 single-clock RTL. It does not include a #delay, initial or X/Z testbench. A lesson-completion mark records learning progress; it does not represent an actual simulation result.

Write down predictions first

Before running the simulator, calculate combinational output yy for the input sequence yourself. The expected sequence is 0,0,0,1,1,0,1,10,0,0,1,1,0,1,1. It covers all eight input combinations and provides stronger evidence than a single correct final value.

The registerRegister A circuit that stores multiple bits of state. The synchronous registers in this course store their specified inputs at a clock edge. Learn more output updates at the rising edge, not when the stimulus changes. Record the combinational output just before the edge separately from the register output just after it.

qk+1=sk‾ak+skbkq_{k+1}=\overline{s_k}a_k+s_kb_k

Here the inputs sampled at edge kk define post-edge state qk+1q_{k+1}. sampled_y is that state. Even when values appear at the same time coordinate, check the event order between applying inputs and updating the register.

Three checks to distinguish the defects

  1. Reversed selection: before changing the expression to sel ? a : b, predict which vector first fails. Vectors with a=ba=b cannot detect this error.
  2. Confused observation points: explain why comparing sampled_y, rather than y, immediately against the combinational answer makes even a correct circuit appear to fail.
  3. Input-independence check: change only the unselected input and confirm that yy holds. Changes to the selected input must be reflected in yy.

For each failure, record input, observation time, expected value and actual value on one line. “The waveform looks wrong” does not distinguish a selection error from a one-cycle delay.

Extension exercise

Widening the data to four bits gives 24+4+1=5122^{4+4+1}=512 combinational inputs. Exhaustive checking is still practical, but begin with 0, the maximum value, 0101, 1010 and walking-one patterns to quickly reveal bit-position errors. Update the settings and input file together with the widened circuit.

Try it yourself

After capturing a=0,b=1,s=0a=0,b=1,s=0 at a rising edge, change only ss to 1 before the next edge. Find yy after logic delay and sampled_y before and after the next rising edge.

Read the explanation

The combinational output is y=1y=1. sampled_y holds 0 until the next rising edge, then stores 1. This assumes the input remains stable for the required sampling interval.

Lesson files

mux-top.sv ↓mux-inputs.json ↓

Your choice applies to this browser. Change it any time using the footer.