16-bit Hamming Decoder Circuit Design
1. Introduction
Hamming code is a type of error detection and correction (ECC, Error Correction Code) that can detect and correct single-bit errors. It is widely used in digital communication and storage systems. In this blog, we will design a 16-bit Hamming decoder circuit and analyze its working principle.
2. Basics of Hamming Code
Hamming code uses parity bits to achieve error detection and correction. For k-bit data, we need to add r parity bits, so that the total number of encoded bits n = k + r satisfies:
[ 2^r \geq k + r + 1 ]
For 16-bit data (k=16), we need 5 parity bits (r=5), resulting in a total encoded data length of 21 bits (16+5).
Parity bits are typically placed at positions that are powers of 2 (i.e., 1, 2, 4, 8, 16) and are computed based on specific parity rules.
3. Encoding Method for 16-bit Hamming Code
Assuming the original 16-bit data is D1, D2, …, D16, we add 5 parity bits P1, P2, P4, P8, P16 and compute their values based on the following rules:
- P1 parity bit checks all positions where the binary index includes 1.
- P2 parity bit checks all positions where the binary index includes 2.
- P4 parity bit checks all positions where the binary index includes 4.
- P8 parity bit checks all positions where the binary index includes 8.
- P16 parity bit checks all positions where the binary index includes 16.
These parity bits are computed using the XOR (exclusive OR) operation.
4. 16-bit Hamming Decoder Circuit Design
(1) Error Detection
Upon receiving 21-bit Hamming code, the receiver recalculates 5 parity bits and compares them with the received parity bits:
- If all parity bits match, the data is error-free.
- If some parity bits do not match, the error bit position is determined by summing the binary indices of the mismatched parity bits.
(2) Error Correction
Once the error bit position is identified, it can be corrected by flipping the bit (changing 0 to 1 or 1 to 0).
5. Logical Circuit Implementation
(1) Main Components
- XOR gates: Used to compute parity bits.
- Adder: Determines the error bit position.
- Memory: Stores received data.
- Control Circuit: Executes error detection and correction logic.
(2) Circuit Design Process
- Input the 21-bit Hamming code, extracting data and parity bits.
- Compute parity bits using XOR and compare them with received parity bits.
- If errors are found, determine the erroneous bit position and flip it.
- Output the corrected 16-bit data.
(3) Verilog Code Example (Core Parity Check)
module hamming_decoder (
input [20:0] encoded_data,
output reg [15:0] decoded_data,
output reg error_detected
);
wire [4:0] syndrome;
assign syndrome[0] = encoded_data[0] ^ encoded_data[2] ^ encoded_data[4] ^ encoded_data[6] ^ encoded_data[8] ^ encoded_data[10] ^ encoded_data[12] ^ encoded_data[14] ^ encoded_data[16] ^ encoded_data[18] ^ encoded_data[20];
assign syndrome[1] = encoded_data[1] ^ encoded_data[2] ^ encoded_data[5] ^ encoded_data[6] ^ encoded_data[9] ^ encoded_data[10] ^ encoded_data[13] ^ encoded_data[14] ^ encoded_data[17] ^ encoded_data[18];
assign syndrome[2] = encoded_data[3] ^ encoded_data[4] ^ encoded_data[5] ^ encoded_data[6] ^ encoded_data[11] ^ encoded_data[12] ^ encoded_data[13] ^ encoded_data[14] ^ encoded_data[19] ^ encoded_data[20];
assign syndrome[3] = encoded_data[7] ^ encoded_data[8] ^ encoded_data[9] ^ encoded_data[10] ^ encoded_data[11] ^ encoded_data[12] ^ encoded_data[13] ^ encoded_data[14];
assign syndrome[4] = encoded_data[15] ^ encoded_data[16] ^ encoded_data[17] ^ encoded_data[18] ^ encoded_data[19] ^ encoded_data[20];
always @(*) begin
error_detected = (syndrome != 5'b00000);
if (error_detected)
encoded_data[syndrome] = ~encoded_data[syndrome];
decoded_data = {encoded_data[20:16], encoded_data[14:8], encoded_data[6:5], encoded_data[3:2]};
end
endmodule
6. Conclusion
Through the above approach, we have implemented a 16-bit Hamming decoder circuit capable of detecting and correcting single-bit errors, making it useful in digital communication and storage systems.
If you have any questions or need further details on Verilog coding or circuit design, feel free to reach out! 😊