FPGA-based example of FPGA-based conversion of binary and Gray Code

Source: Internet
Author: User

[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

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.