Codiode

Gray Code to Binary Datapath

MediumVerilog / SystemVerilogBuild

Async FIFO pointers cross clock domains in Gray code, but the occupancy arithmetic on the other side needs binary. Converting back is an XOR chain from the top bit down.

The datapath module performs a purely combinational conversion from a parameterized Gray code input to a standard binary output. In Gray code to binary conversion, the most significant bit (MSB) of the binary output is identical to the MSB of the Gray code input. Each subsequent binary bit is the XOR of the corresponding Gray code bit and the previously calculated binary bit (the one at the next higher index).

Because this conversion sits in the critical timing path of a FIFO controller, it must be evaluated combinationally without requiring additional clock cycles.

Signal Direction Width Description
gray_in input WIDTH Gray code input value
bin_out output WIDTH Binary converted output value
Parameter Type Default Description
WIDTH integer 8 Bit width of the input and output buses

Constraints

  • The module must be completely combinational; do not include clock or reset ports.
  • The design must support any WIDTH strictly greater than 1.
  • The output bin_out must update combinationally immediately when gray_in changes.

Topics

ParameterizedCDCCombinational LogicDatapath

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Datapath Design

Problem 21 of 27 in the Datapath Design track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.