Communication application practice: typical programming of Hamming code error correction and Verilog code design
[Copy link]
content:
- Understand the principles of error detection and correction and unpacking;
- Design and write error detection and correction and unpacking programs, and restore original information data programs;
4.1 Error detection and correction
In the communication process, the information channel is encoded to ensure reliability. Error detection and correction is the main manifestation of reliability. Error detection and correction includes two aspects. On the one hand, it checks whether the received data is correct. On the other hand, it can also correct the erroneous data according to a certain algorithm. Therefore, error detection and correction are very necessary in the communication system.
4.1.1 Hamming Code Error Detection and Correction Algorithm
Hamming code is a typical channel coding and a type of block code. It has the ability to detect errors for each code (each time a Hamming code is received, it can be determined whether the code is correct). In addition, it also has 1-bit error correction capability.
If we define S1, S2, S3
S1 = D6 ^ D5 ^ D4^D2 If S1==0, it means that the data of D6, D5, D4, and D2 are all correct. Otherwise, it means that there are errors in this group of data, and the number of erroneous data is uncontrollable.
S2 = D6 ^ D5 ^ D3^D1 If S2==0, it means that the data of D6, D5, D3, and D1 are all correct. Otherwise, it means that there are errors in this group of data, and the number of erroneous data is uncontrollable.
S3 = D6 ^ D4 ^ D3^D0 If S3==0, it means that the data of D6, D4, D3, and D0 are all correct. Otherwise, it means that there are errors in this group of data, and the number of erroneous data is uncontrollable.
From the above analysis, we can see that when S1=0, S2=0, S3=0, it means that the Hamming code is all correct.
- How to correct the error?
All error correction is limited to the case of 1 bit error. If the error is 2 bits or more, Hamming code is powerless.
Conventionally, S1, S2, and S3 are called correctors, which can be used to correct errors in the received Hamming code.
4.1.2 Typical Program Design of Hamming Error Correction
4.1.2.1 Design Block Diagram
Design Block Diagram
4.1.2.2 hmm_crt implementation
- Restore Hamming Code
[
attach]853867[/
attach
]
Code
Design
Program
/
...
///////////////////////////////////////////////////////////////////////////////////////////////////
- Error correction output
always @(posedge clk_d )
case({S1,S2,S3})
3'b011: data<={ hmm[6:4] ,~hmm [3]};
3'b101: data<={ hmm[6:5] ,~hmm [4], hmm [3]};
3'b110: data<={ hmm[6],~hmm [5], hmm [4:3]};
3'b111: data<={ ~hmm[6], hmm [5:3]};
default : data<=hmm[6:3];
endcase
reg flag_hmm;
always @(posedge clk_d or negedge rst_n)
if(~rst_n)flag_hmm <=0;
else if( (cnt ==6) && (flag_seq_rec) ) flag_hmm <=1;else flag_hmm <=0;
///////////////////////////////////////////////////// ///////////////////////////////////////////////////// ////////////////////
4.1.2.3 unpack program implementation
Unpack program implementation
|