Altifigence Academy

40 / 63 · Lab

Lab: verify serial-data movement and bit order

Use bit patterns and an integer reference model to verify direction, discarded bits and latency after reset.

The circuit and observation conditions

At every rising 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, the lower two bits of the previous q value shift left and din enters bit 0. Apply 1, 0, 1, 1 in sequence and compare their movement.

Before starting

Prepare a Digital Design Studio Desktop project with normal execution permission. Save each example as rtl/top.sv in a separate folder.

SystemVerilog source

SystemVerilog
module top (
    input logic clk,
    input logic rst,
    input logic din,
    output logic [2:0] q
);
    // Old q[1:0] and din are captured together at each rising edge.
    always_ff @(posedge clk)
        if (rst) q <= 3'b000;
        else q <= {q[1:0], din};
endmodule

Running the lab

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

SettingValue
Initial register values (LSB first)[false,false,false]
Reset portrst · Active high · 1 cycle
Maximum cycles / time5 / 5000ps

Input stimulus

json
[
  {
    "inputs": {
      "din": [
        false
      ]
    }
  },
  {
    "inputs": {
      "din": [
        true
      ]
    }
  },
  {
    "inputs": {
      "din": [
        false
      ]
    }
  },
  {
    "inputs": {
      "din": [
        true
      ]
    }
  },
  {
    "inputs": {
      "din": [
        true
      ]
    }
  }
]

Each column below records a rising edge. Inputs are pre-edge; states labeled “after” are post-update. Alignment shows sampling order, not physical propagation delayPropagation delay The time from an input change until the output settles to the correct value. Logical equivalence and timing behavior are separate properties. Learn more. The first column is the resetReset A control that returns state to a specified initial value. Define whether it is synchronous or asynchronous and whether it has priority over other controls. Learn more edge, so its din=0 does not count as stored data. Compare the next four inputs with the JSON order.

Input stimulus and three-bit state movement
View waveform data
Wave data: each character is one interval; a dot holds the previous state; p is a clock cycle.
SignalWaveBus values
edge23452E0 → E1 → E2 → E3 → E4
reset10...
din0101.
q after23452000 → 001 → 010 → 101 → 011

Compare results

5 cycles · q=011. The rising-edge sequence is 000 → 001 → 010 → 101 → 011.

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

Check concatenation with an independent expression

Copying the RTL concatenationConcatenation An operation that joins bit patterns side by side. Its result width is the sum of the operand widths; it is not numerical addition. Learn more as the expected answer can reproduce the same mistake in both places. Try a reference model interpreting the state as an unsignedUnsigned A rule for interpreting a bit pattern as a nonnegative integer. The n-bit range is 0 through 2^n−1 and may differ from the signed interpretation of the same bits. Learn more integer:

Qk+1=(2Qk+dk) mod 8Q_{k+1}=(2Q_k+d_k)\bmod 8

After reset, inputs 1, 0, 1, 1 give 0→1→2→5→30\to1\to2\to5\to3. Written as three-bit binary, these must match the lab waveform. The final step computes 2⋅5+1=112\cdot5+1=11; retaining the low three bits gives 3.

Received bitsInputq after edgeInteger value
0Reset0000
110011
200102
311015
410113

With reset=0 and enable=1, select din=1,0,1,1 and advance the clock after each. q becomes 001,010,101,011. Use this step model to predict behavior, then compare actual RTL results. Enable is included so you can also test the stalls in the extension below.

Predict bit order before running RTL

Synchronous reset takes priority over enable. With enable=0, hold the stored value. q=000; q_next = (2q + din) mod 8

Track one bit to verify direction

After reset, input 1 once and then 0 three times. The sequence is 001 → 010 → 100 → 000. The first 1 must pass through bit 0, bit 1 and bit 2, then disappear. All-zero or all-one patterns alone can hide incorrect direction.

In a three-stage 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, a bit first captured at edge kk reaches the highest bit 2 after edge k+2k+2. Counting from the edge at which an external transmitting register launched it uses a different starting point. State the departure and arrival points in your report.

Extension: shift only valid inputs

Suppose valid is added to the input. Holding q when valid=0 differs from a pipeline that shifts every cycle while forwarding a separate valid bit. The former advances by received-bit count; the latter by elapsed clock cycles. Do not verify both against the same expected sequence.

Try it yourself

After reset, valid bits arrive as 1, 0, 1. There is one valid=0 cycle before and one after the second bit, and invalid cycles hold q. Explain final q and when the first 1 reaches bit 2.

Read the explanation

Only the three valid inputs update state, so final q is 101. The first 1 reaches bit 2 at the edge that stores the third valid input. It needs two additional shifts after first capture, and the two invalid cycles add elapsed time.

Lesson files

shift-top.sv ↓shift-inputs.json ↓

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