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
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.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 4-Bit Parity OK Checker (XOR vs Type) — L1 Upgrade — L2 Upgrade.
- 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.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- 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:
- Combinational Parity Checker: Uses an XOR reduction operator to determine if the input data has even parity.
- Registered Data Path: Synchronously updates the output data and error flags based on the
rd_ensignal.
### 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
casestatement 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 untilrst_nis asserted.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Active-low asynchronous reset |
data_in | Input | 4 | 4-bit data input |
rd_en | Input | 1 | Read enable signal (gates updates) |
parity_ok | Output | 1 | High if parity is valid (even) |
data_out | Output | 4 | Corrected data output |
err | Output | 1 | Sticky error flag (latched until reset) |
Verification
The testbench covers eight specific test cases to ensure comprehensive coverage:
| Test Case | Description | Expected Result | Status |
|---|---|---|---|
| TC1 | No error (even parity) | parity_ok=1, err=0 | PASS |
| TC2 | Single bit error (LSB) | data_out corrected, err=1 | PASS |
| TC3 | Sticky error check | err remains 1 after valid data | PASS |
| TC4 | Reset clears error | err becomes 0 after reset | PASS |
| TC5 | Single bit error (MSB) | data_out corrected | PASS |
| TC6 | Single bit error (bit 1) | data_out corrected | PASS |
| TC7 | Single bit error (bit 2) | data_out corrected | PASS |
| TC8 | No error (odd parity input) | parity_ok=1, data_out unchanged | PASS |
### Simulation Log
After running the simulation, the Log panel should display:
More in Parity
- 8-Bit Even/Odd Parity Bit Generator — L1 Upgrade
- 8-Bit Parity Error Counter with Accumulator — L2 Upgrade
- 8-Bit Parity Generator (Muxed Even/Odd)
- Byte-Strobe Parity Scrub 32-bit — L2 Upgrade
- Even Parity over 16-Bit Bus — L1 Upgrade — L2 Upgrade
- Hamming Distance 8-Bit — L1 Upgrade
- Odd/Even Parity Select 8-bit — L1 Upgrade — L2 Upgrade
- Parity Byte Checker 8-Bit — L1 Upgrade — L2 Upgrade
- Parity Invert-Select 8-bit — L1 Upgrade — L2 Upgrade
- Parity-Protected 8-Bit Register — L2 Upgrade
- SECDED Hamming Check (13,8)
- SECDED Nibble Syndrome (toy) — L2 Upgrade
- Sticky Parity Error Flag 8-Bit — L1 Upgrade
- XOR-Reduce Parity Tree 16-bit