This implementation of the (7,4) Hamming Code allows for the same input to be used for encoding and decoding, with dynamic selection of the mode using the MSB of the input.
<img width="971" alt="Screenshot 2024-11-04 at 8 06 56 PM" src="https://github.com/user-attachments/assets/71be084c-4f85-4fc6-86ad-8c6ae5e9c4c8">
The Hamming (7,4) encoder is a linear error-correcting code that encodes 4 data bits into 7 bits by adding 3 parity bits, which can detect and correct a single-bit error.
<img width="779" alt="Screenshot 2024-11-04 at 8 07 53 PM" src="https://github.com/user-attachments/assets/8bf81d45-43ef-4c8a-b536-a7fe87e19901">
Parity Format
{p1 p2 p3}
Data Format
{d1 d2 d3 d4}
An 8-bit input "ui" with the following format (note the form is {7 6 5 4 3 2 1 0})
Input Pins<br>
An 8-bit output "uo" with the following format (note the form is {7 6 5 4 3 2 1 0})
Output Pins<br>
Encode Mode is selected by setting the MSB of the input (bit 7) LOW (0).
If encode mode is chosen, the encoder will use bits 3:0 as the four data bits to be encoded, and produce a 7-bit encoded output.
Bit 6:4 are not involved in any encoding.
Encode Mode Input Format
{selector, X, X, X, d1, d2, d3, d4}
Encode Mode Output Format
{p1, p2, d1, p3, d2, d3, d4}
The decoder checks the received 7-bit word for errors and corrects a single-bit error if detected. The process involves recalculating the parity bits and comparing them with the received parity.
<img width="1232" alt="Screenshot 2024-11-04 at 8 07 32 PM" src="https://github.com/user-attachments/assets/fd14ada7-9285-40ca-9cd0-64065ebc415d">
Decode Mode is selected by setting the MSB of the input (bit 7) HIGH (1).
If decode mode is chosen, the decoder will use bits 7:0, both the data and parity bits, and produce a 7-bit decoded output. The decoded output will be the originally encoded input as long as there were less than 2 flipped bits between encoder output and decoder input.
Decode Mode Input Format
{p1, p2, d1, p3, d2, d3, d4}
Decode Mode Output Format
{p1, p2, d1, p3, d2, d3, d4}
The syndrome indicates the position of an error (if any):
The syndrome {S2, S1, S0} gives the error location:
Testing can be done by applying known data inputs with LOW as the value of the 7th bit (encode mode), and ensuring that the output is the expected encoding value (see table of expected outputs in encode mode).
Similarly, known encoded values can by used as input, with the 7th bit as HIGH (decode mode), and we can ensure that the output is the exact same as the original encoded value, even if we flip 1 bit. This should be done for each of the 7 bits for all encoded values
TBD based on implementation.
# | Input | Output | Bidirectional |
---|---|---|---|
0 | LSB/Bit 0 for 4-bit Encoder Input OR LSB/Bit 0 for 7-bit Decoder Input | LSB/Bit 0 for 7-bit Encoder OR Decoder Output | |
1 | Bit 1 for 4-bit Encoder Input OR Bit 1 for 7-bit Decoder Input | Bit 1 for 7-bit Encoder OR Decoder Output | |
2 | Bit 2 for 4-bit Encoder Input OR Bit 2 for 7-bit Decoder Input | Bit 2 for 7-bit Encoder OR Decoder Output | |
3 | MSB/Bit 3 for 4-bit Encoder Input OR Bit 3 for 7-bit Decoder Input | Bit 3 for 7-bit Encoder OR Decoder Output | |
4 | Bit 4 for 7-bit Decoder Input | Bit 4 for 7-bit Encoder OR Decoder Output | |
5 | Bit 5 for 7-bit Decoder Input | Bit 5 for 7-bit Encoder OR Decoder Output | |
6 | MSB/Bit 6 for 7-bit Decoder Input | MSB/Bit 6 for 7-bit Encoder OR Decoder Output | |
7 | Mode Selector (0 => Encode, uses ui[3:0]; 1 => Decode, uses ui[6:0]) | Mode Selector (0 => Encode; 1 => Decode) |