Gray Code to Binary Datapath
Clock domain crossing (CDC) circuits, such as asynchronous FIFOs, rely on Gray code to safely transfer multi-bit pointers across asynchronous boundaries. Once safely synchronized into the receiving clock domain, these Gray code pointers must be converted back to standard binary format to calculate FIFO occupancy and evaluate full/empty conditions.
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
WIDTHstrictly greater than 1. - The output
bin_outmust update combinationally immediately whengray_inchanges.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real 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.