Parity
Odd/Even Parity Select 8-bit — L1 Upgrade — L2 Upgrade
8-bit parity checker with selectable odd/even mode, LSB correction, and sticky error flag.
About this block
Simulate it in the Verilog IDE
Odd/Even Parity Select 8-bit — 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 IP core implements an 8-bit parity checker that supports both odd and even parity modes. It calculates a syndrome to detect single-bit errors.
Critical Note: This design employs a heuristic correction strategy. Upon detecting a parity mismatch, it assumes the error is in the Least Significant Bit (LSB) and flips it.
- Use Case: Suitable only when LSB errors are statistically more probable or when the LSB serves as a dedicated parity bit in a broader system context.
- Warning: If the error is in any bit other than the LSB, the data will be corrupted further by this "correction." Do not use for general multi-bit error correction.
The design includes registered outputs and supports active-low asynchronous reset. A sticky error flag latches any detected error for system-level monitoring.
- Parity Modes: Configurable via
parity_modeinput (0: Even, 1: Odd). - Error Detection: Identifies parity mismatches using syndrome calculation (XOR of all bits).
- Heuristic Correction: Automatically flips the LSB (
data_in[0]) if a parity mismatch is detected. - Sticky Flag:
sticky_errorremains high until reset, ensuring no error is missed. - Registered Output: All outputs are registered on the clock edge for timing stability.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Odd/Even Parity Select 8-bit — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: 8-bit parity checker with selectable odd/even mode, LSB 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 module computes the XOR of all 8 input data bits to form a syndrome. It compares the syndrome against the selected parity mode to determine validity.
- Even Parity Mode (
parity_mode=0): The syndrome (XOR of bits) should be0. Ifsyndrome != 0, an error is detected. - Odd Parity Mode (
parity_mode=1): The syndrome (XOR of bits) should be1. Ifsyndrome != 1, an error is detected.
If an error is detected, the LSB of the data is flipped to "correct" it. The sticky error register retains the error state until a reset occurs.
Interface
The following table describes the port interface.
| Port Name | Direction | Width | Description |
|---|---|---|---|
| clk | Input | 1 | Clock input |
| rst_n | Input | 1 | Active-low asynchronous reset |
| rd_en | Input | 1 | Read enable to sample data |
| data_in | Input | 8 | Input data bus |
| parity_mode | Input | 1 | 0 for Even, 1 for Odd parity |
| data_out | Output | 8 | Output data (corrected if error) |
| parity_ok | Output | 1 | High if parity matches mode |
| error_detected | Output | 1 | High if current cycle has error |
| sticky_error | Output | 1 | Latched error flag |
Verification
The testbench covers five key scenarios to ensure correct operation.
| Test Case | Description | Expected Result |
|---|---|---|
| TC1 | Even parity, no error | parity_ok=1, error=0, sticky=0 |
| TC2 | Even parity, error present (LSB flipped) | parity_ok=0, error=1, sticky=1, data_out corrected |
| TC3 | Odd parity, no error | parity_ok=1, error=0, sticky=0 |
| TC4 | Odd parity, error present (LSB flipped) | parity_ok=0, error=1, sticky=1, data_out corrected |
| TC5 | Reset assertion | sticky_error=0 |
All tests passed successfully in the Icarus Verilog simulation environment. The simulation log confirms no mismatches in data, parity, or error flags.
More in Parity
- 4-Bit Parity OK Checker (XOR vs Type) — L1 Upgrade — L2 Upgrade
- 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
- 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