RTL Studio Open IDE

Parity

4-Bit Parity OK Checker (XOR vs Type) — L1 Upgrade — L2 Upgrade

4-Bit Parity OK Checker with XOR reduction, syndrome-based single-bit error correction, and sticky error flag.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

4-Bit Parity OK Checker (XOR vs Type) — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Parity catalog. Even/odd parity generators, checkers, and error-detection helpers. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This Intellectual Property (IP) implements a 4-bit single-bit error correction (SEC) unit. It detects parity errors using XOR reduction, identifies the erroneous bit position via a syndrome-based approach, and corrects the data in real-time. A sticky error flag is provided to track error history until a system reset occurs.

This IP provides robust single-bit error correction for 4-bit data streams. It combines simple even-parity checking with targeted bit-flipping logic. The sticky error flag ensures that error history is preserved across valid data cycles, making this module suitable for memory interfaces, data buses, and communication links where error tracking is critical.

The design is fully synchronous with an asynchronous reset.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for 4-Bit Parity OK Checker (XOR vs Type) — L1 Upgrade — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: 4-Bit Parity OK Checker with XOR reduction, syndrome-based single-bit error correction, and sticky error flag.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Architecture

The design consists of two main parts:

  1. Combinational Parity Checker: Uses an XOR reduction operator to determine if the input data has even parity.
  2. Registered Data Path: Synchronously updates the output data and error flags based on the rd_en signal.

### Logic Flow

  • Parity Check: The XOR of all input bits (^data_in) determines if a mismatch exists (1 for odd parity/error, 0 for even parity/valid).
  • Syndrome Calculation: If a mismatch is detected, a case statement maps the input pattern to a 3-bit syndrome index. This index corresponds to the bit position that needs flipping (e.g., 0001 -> LSB, 1000 -> MSB).
  • Correction: The erroneous bit is flipped by XORing the input data with a mask derived from the syndrome.
  • Sticky Error: A register latches the error state (err = 1) upon detection. This flag remains set until rst_n is asserted.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low asynchronous reset
data_inInput44-bit data input
rd_enInput1Read enable signal (gates updates)
parity_okOutput1High if parity is valid (even)
data_outOutput4Corrected data output
errOutput1Sticky error flag (latched until reset)

Verification

The testbench covers eight specific test cases to ensure comprehensive coverage:

Test CaseDescriptionExpected ResultStatus
TC1No error (even parity)parity_ok=1, err=0PASS
TC2Single bit error (LSB)data_out corrected, err=1PASS
TC3Sticky error checkerr remains 1 after valid dataPASS
TC4Reset clears errorerr becomes 0 after resetPASS
TC5Single bit error (MSB)data_out correctedPASS
TC6Single bit error (bit 1)data_out correctedPASS
TC7Single bit error (bit 2)data_out correctedPASS
TC8No error (odd parity input)parity_ok=1, data_out unchangedPASS

### Simulation Log

After running the simulation, the Log panel should display:

More in Parity

All Parity blocks