[Serialization] FPGA OpenGL series instances
Conversion of binary and Gray Codes Using Tilde
Gray Code features: There is only one difference between two adjacent code groups.
Common binary codes and gray codes can be converted to each other. The following is a brief introduction.
8-bit binary code to Gray Code
Binary Code Conversion to Gray code: From the rightmost one, one is different from the other on the left, or is used as the value of the gray code, the leftmost digit remains unchanged (equivalent to 0 on the leftmost part ).
1 Modele bin2gry (Gry, BIN)
2 Parameter length = 8 ;
3 Output [length- 1 : 0 ] Gry;
4 Input [length- 1 : 0 ] Bin;
5
6 Reg [length- 1 : 0 ] Gry;
7 Integer I;
8
9 Always @ (BIN)
10 Begin
11 For (I = 0 ; I <length- 1 ; I ++)
12 Gry [I] = bin [I] ^ bin [I + 1 ];
13 Gry [I] = bin [I];
14 End
15 Endmodule
8-bit gray code to binary code
Gray code to binary code: from the second place on the left, the decoded value of each bit is "different or" from the decoded value on the left ", as the decoded value (the leftmost one remains unchanged ).
1 Modele gry2bin (Gry, BIN)
2 Parameter length = 8 ;
3 Output [length- 1 : 0 ] Gry;
4 Input [length- 1 :0 ] Bin;
5
6 Reg [length- 1 : 0 ] Bin;
7 Integer I;
8 Always @ (Gry)
9 Begin
10 Bin [length- 1 ] = Gry [length- 1 ];
11 For (I = length- 2 ; I> = 0 ; I --)
12 Bin [I] = bin [I + 1 ] ^ Gry [I];
13 End
14 Endmodule