Role of Gray Coding in Digital Design

Some implementation in digital design requires Gray encoding where only one bit is allowed to transition between two consecutive numbers.

Logic: Binary and Gray conversions for 4 bit numbers are below: 

Binary from Gray:

bin[0] = gray[3]^gray[2]^gray[1]^gray[0]

bin[1] = gray[3]^gray[2]^gray[1]

bin[2] = gray[3]^gray[2]

bin[3] = gray[3]

Gray from binary:

gray[0] = bin[0] ^ bin[1]

gray[1] = bin[1] ^ bin[2]

gray[2] = bin[2] ^ bin[3]

gray[3] = bin[3]

LTE - 4G Wireless Technology

Digital fundamentals.

Interview Questions.

Example - Clock domain crossing scenarios, FIFO's are required. FIFO's read/write address counters are running from different clocks. In this scenario, we will need to exchange one clock domain counter value with another clock domain. In this scenario multiple bits toggling with binary counters can result in synchronization issues. So we convert binary counters to gray and then synchronize across clock domains. Check out Verilog code to implement Gray Encoding

Decimal to binary to gray codes from 0-100 are discussed below.

Binary to Gray code mapping for 0 to 10

# Decimal = 0 : Binary = 10'b0000000000 : Gray = 10'b0000000000

# Decimal = 1 : Binary = 10'b0000000001 : Gray = 10'b0000000001

# Decimal = 2 : Binary = 10'b0000000010 : Gray = 10'b0000000011

# Decimal = 3 : Binary = 10'b0000000011 : Gray = 10'b0000000010

# Decimal = 4 : Binary = 10'b0000000100 : Gray = 10'b0000000110

# Decimal = 5 : Binary = 10'b0000000101 : Gray = 10'b0000000111

# Decimal = 6 : Binary = 10'b0000000110 : Gray = 10'b0000000101

# Decimal = 7 : Binary = 10'b0000000111 : Gray = 10'b0000000100

# Decimal = 8 : Binary = 10'b0000001000 : Gray = 10'b0000001100

# Decimal = 9 : Binary = 10'b0000001001 : Gray = 10'b0000001101

Decimal = 10 : Binary = 10'b0000001010 : Gray = 10'b0000001111

Binary to Gray code mapping for 11 to 50 click here

Binary to Gray code mapping for 50 to 100 click here

Tutorials @fullchipdesign.com

Verilog Tutorial.

LTE Tutorial.

Memory Tutorial.

Hope you liked! this page. Don't forgot to access relevant previous and next sections with links below.