0% found this document useful (0 votes)
29 views21 pages

4-Bit Binary to Gray Code Converter Design

The document outlines the design and verification of a 4-bit binary to Gray code converter using Verilog HDL, including functional verification through UVM and GDS-II layout generation using OpenROAD. Key results include a design area of 220 µm², power consumption of 100 nW, and successful verification with 100% test case pass. The design is fully combinational, ensuring efficient performance in digital applications.

Uploaded by

leomary418
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views21 pages

4-Bit Binary to Gray Code Converter Design

The document outlines the design and verification of a 4-bit binary to Gray code converter using Verilog HDL, including functional verification through UVM and GDS-II layout generation using OpenROAD. Key results include a design area of 220 µm², power consumption of 100 nW, and successful verification with 100% test case pass. The design is fully combinational, ensuring efficient performance in digital applications.

Uploaded by

leomary418
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TOPIC:

a) Design 4-bit binary to gray code converter using the Verilog HDL.
b) Do Functional Verification of the design using UVM.
c) Generate GDS-II layout of the design using OpenROAD-flowscripts tool.
• Report Design Area
• Clock frequency, where slack value is positive but less than 1.
• Report power consumption

NAME: FELIS BERNARD (CAN_33836321)

HIMABINDU K ( CAN_33836955)

SHAIK ALIYA FIRDOSE (CAN_33836939)

SYED ALFIYA (CAN_33836758)

ROLL NUMBER: 1HK21EC029

1HK21EC035

1HK21EC111

1HK21EC131

COLLEGE NAME: HKBK COLLEGE OF ENGINEERING

DEPARTMENT: ELECTRONICS AND COMMUNICATION ENGINEERING

DATE OF SUBMISSION: 12/03/2025

PROJECT: Design 4-bit binary to gray code converter using the Verilog HDL.
1. INTRODUCTION:

Binary and Gray codes are essential in digital systems, especially in applications like
error correction, digital communication, and encoding for sequential circuits. Gray
code is a type of binary numeral system in which two successive values differ by only
one bit. This property minimizes errors in digital systems where multiple bits change
simultaneously in standard binary representation.
A 4-bit Binary to Gray Code Converter is a combinational circuit that converts a 4-bit
binary input into its corresponding 4-bit Gray code output.
TRUTH TABLE OF 4-BIT BINARY TO GRAY CODE CONVERTER
2. SPECIFICATIONS:
• Module Name : binary_to_gray
• Inputs:
• A 4-bit binary number (binary[3:0])
• Outputs:

• A 4-bit Gray code equivalent (gray[3:0])


• Functional Description:
• The converter takes a 4-bit binary input and produces a 4-bit Gray code
output

• The most significant bit (MSB) remains unchanged.


• Each subsequent Gray code bit is obtained using the XOR operation between
Consecutive binary bits.

DESIGN CONSTRAINTS:
When designing a 4-bit Binary to Gray Code Converter, the following design
constraints should be considered:

1. Functional Constraints
•The circuit should correctly implement the binary-to-Gray code conversion based on
XOR logic.
•The output must change only one bit at a time when the input increments (to
maintain Gray code properties).
•The design should be fully combinational, meaning no clock or sequential
elements should be used.

2. Testability Constraints
•The design should be easily testable using a testbench.
•Functional verification should include:
•Corner cases (0000, 1111)
•Random values

•Sequential binary inputs (0000 → 0001 → 0010 → … → 1111)


•The testbench should provide coverage for all possible input cases.
Design Architecture:
1. Architectural Design Approach
The 4-bit Binary to Gray Code Converter is a combinational circuit that converts a 4-bit
binary input into a 4-bit Gray code output. The architecture follows a bitwise XOR
operation for conversion.

2. Design Architecture Components


a. Input and Output
•Inputs:
•A 4-bit binary number (binary[3:0])
•Outputs:
•A 4-bit Gray code equivalent (gray[3:0])
b. Conversion Logic
Each bit of the Gray code output is derived using XOR logic:

•gray[3] = binary[3] (MSB remains the same)


•gray[2] = binary[3] ⊕ binary[2]
•gray[1] = binary[2] ⊕ binary[1]
•gray[0] = binary[1] ⊕ binary[0]

3. Design Architecture Breakdown


CIRCUIT DIAGRAM

[Link] CODE FOR 4-BIT BINARY TO GRAY CODE CONVERTER:


4. TESTBENCH CODE

5. TESTBENCH OF VERIFICATION:
To verify the functionality of the converter, we use a testbench that applies different binary
inputs and checks the corresponding Gray code outputs.
Explanation About testbench:
[Link] (binary_to_gray)

•It has a 4-bit binary input.


• It produces a 4-bit Gray code output.
•The conversion is performed using XOR operations.
[Link] (tb_binary_to_gray)

•Instantiates the binary_to_gray module.


•Applies different binary values and checks the outputs.
•Uses $monitor to display the results.

6. SIMULATION RESULT:

7. RESULT AND DISCUSSION:


The 4-bit Binary to Gray Code Converter is successfully designed using Verilog HDL.
•A testbench was provided to verify the design.

• The design is combinational, making it efficient for high-speed applications.


b) Do functional verification of the design using UVM
To perform functional verification of a 4-bit Binary to Gray Code converter using UVM, we
need to define the testbench that verifies the functionality of the converter. The process
includes creating UVM components such as transactions, sequences, drivers, monitors, and
a scoreboard, as well as writing a test to verify that the Binary to Gray Code converter
behaves as expected.

1. Understanding the DUT (Design Under Test)


The DUT is a 4-bit Binary to Gray Code Converter. The logic takes a 4-bit binary number as
input and outputs the corresponding 4-bit Gray code.

• Binary to Gray Code conversion:

o For a given binary number B3 B2 B1 B0, the Gray code G3 G2 G1 G0 is


generated as follows:

▪ G3 = B3

▪ G2 = B3 ⊕ B2

▪ G1 = B2 ⊕ B1

▪ G0 = B1 ⊕ B0

2. UVM Testbench Components


To verify the DUT, we need to create the following UVM components:

• Transaction class: Represents the input/output data (binary and Gray code).

• Driver: Sends the binary input to the DUT.

• Monitor: Observes the DUT’s output (Gray code).

• Scoreboard: Compares the Gray code output with the expected output.

• Sequencer: Controls the sequence of transactions.

• Test: Instantiates the environment and runs the tests.

3. Define the UVM Classes


Below is the UVM testbench for the 4-bit Binary to Gray Code Converter.

Step 1: Define the Transaction Class

The transaction class will hold the binary input and the Gray code output.

systemverilog

Copy

class binary_gray_transaction extends uvm_transaction;

rand bit [3:0] binary_input; // 4-bit binary input

bit [3:0] gray_output; // 4-bit Gray code output

// Constructor

function new(string name = "binary_gray_transaction");

[Link](name);

endfunction

endclass

Step 2: Define the Driver


The driver will take the binary input and send it to the DUT, and also get the Gray code
output.
Step 3: Define the Monitor
The monitor will observe the DUT’s output and provide it to the scoreboard for comparison.
Step 4: Define the Scoreboard
The scoreboard will check if the output matches the expected Gray code.

class binary_gray_scoreboard extends uvm_scoreboard;


// Expected Gray code output (this could be generated via a function)
function void compare(binary_gray_transaction trx);
bit [3:0] expected_gray;
// Compute the expected Gray code
expected_gray[3] = trx.binary_input[3];
expected_gray[2] = trx.binary_input[3] ^ trx.binary_input[2];
expected_gray[1] = trx.binary_input[2] ^ trx.binary_input[1];
expected_gray[0] = trx.binary_input[1] ^ trx.binary_input[0];
// Compare the output with the expected Gray code
if (trx.gray_output !== expected_gray) begin
uvm_report_error("SCOREBOARD", $sformatf("Mismatch: Binary %b -> Gray %b,
Expected %b", trx.binary_input, trx.gray_output, expected_gray), UVM_LOW);
end else begin
uvm_report_info("SCOREBOARD", $sformatf("Match: Binary %b -> Gray %b",
trx.binary_input, trx.gray_output), UVM_LOW);
end
endfunction
endclass

Step 5: Define the Environment


The environment integrates the driver, monitor, and scoreboard.
systemverilog
Copy
class binary_gray_env extends uvm_env;
// Instantiate the components
binary_gray_driver driver;
binary_gray_monitor monitor;
binary_gray_scoreboard scoreboard;
binary_gray_sequencer sequencer;

function void build();


// Instantiate the components and connect them
driver = binary_gray_driver::type_id::create("driver", this);
monitor = binary_gray_monitor::type_id::create("monitor", this);
scoreboard = binary_gray_scoreboard::type_id::create("scoreboard", this);
sequencer = binary_gray_sequencer::type_id::create("sequencer", this);
endfunction
endclass
Step 6: Define the Test
The test will run different binary values through the converter and check if the Gray code
matches the expected output.
systemverilog
Copy
class binary_gray_test extends uvm_test;
binary_gray_env env;
function void run_phase(uvm_phase phase);
// Create the environment
env = binary_gray_env::type_id::create("env");
// Define a list of binary values to test
binary_gray_transaction trx;
foreach (trx.binary_input) begin
trx.binary_input = $urandom % 16; // Generate a random 4-bit binary number
uvm_report_info("TEST", $sformatf("Applying input: %b", trx.binary_input),
UVM_LOW);
[Link].seq_item_port.start_item(trx);
[Link].seq_item_port.finish_item(trx);
end
endfunction
endclass

4. Connecting the DUT


The actual Binary to Gray Code converter module needs to be connected in the testbench,
and it should have the following interface:
systemverilog
Copy
module binary_to_gray_converter (
input [3:0] binary_input,
output reg [3:0] gray_output
);
always @ (binary_input) begin
gray_output[3] = binary_input[3];
gray_output[2] = binary_input[3] ^ binary_input[2];
gray_output[1] = binary_input[2] ^ binary_input[1];
gray_output[0] = binary_input[1] ^ binary_input[0];
end

endmodule

Simulation Generation:
/project
/src
- binary_to_gray_converter.sv (DUT)
- binary_gray_transaction.sv (UVM transaction)
- binary_gray_driver.sv (UVM driver)
- binary_gray_monitor.sv (UVM monitor)
- binary_gray_scoreboard.sv (UVM scoreboard)
- binary_gray_sequencer.sv (UVM sequencer)
- binary_gray_env.sv (UVM environment)
- binary_gray_test.sv (UVM test)
/sim
- [Link] (ModelSim/Questa or VCS TCL script)
- [Link] (Compilation script)
Testbench:

Summary of the Testbench:

• DUT: The binary_to_gray_converter module that converts a 4-bit binary input to Gray
code.

• Transaction: The binary_gray_transaction class that models input-output pairs.

• Driver: Drives the input binary value to the DUT and captures the output.

• Monitor: Observes the DUT’s output.

• Scoreboard: Compares the DUT output with the expected Gray code and reports
mismatches.

• Sequencer: Controls the flow of transactions.

• Test: Runs the actual tests by applying random binary inputs.

This complete UVM testbench will verify the functionality of the 4-bit Binary to Gray Code
converter.
Generate GDS using OpenROAD tool

In this section, the layout of the RTL code has been generated using the OpenROAD software
tool.

Technology/Platform utilized: sky130hd

Instructions of the [Link]

export DESIGN_NICKNAME = binary_to_gray


export DESIGN_NAME = binary_to_gray
export PLATFORM = sky130hd

export VERILOG_FILES = $(sort


$(wildcard$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/binary_to_gray.v))
export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/[Link]

#export PLACE_PINS_ARGS = -min_distance 4 -min_distance_in_tracks

export CORE_UTILIZATION = 5
#export CORE_ASPECT_RATIO = 1
#export CORE_MARGIN = 2

export PLACE_DENSITY = 0.1


export TNS_END_PERCENT = 100

#export EQUIVALENCE_CHECK ?= 0
#export REMOVE_CELLS_FOR_EQY = sky130_fd_sc_hd tapvpwrvgnd*

#export FASTROUTE_TCL =
$(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/[Link]

#export REMOVE_ABC_BUFFERS = 1
Instructions of the [Link]

current_design binary_to_gray

set clk_name v_clk


#set clk_port_name clk
set clk_period 2.5
set clk_io_pct 0.2

#set clk_port [get_ports $clk_port_name]

create_clock -name $clk_name -period $clk_period

set non_clock_inputs [lsearch -inline -all -not [all_inputs]]

set_input_delay [expr $clk_period * $clk_io_pct] -clock $clk_name $non_clock_inputs


set_output_delay [expr $clk_period * $clk_io_pct] -clock $clk_name [all_outputs]
Layout of the Design
Performance Analysis

Power Measurement:

Group Internal Switching Leakage Total


Power Power Power Power (Watts)

Sequential 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.0%


Combinational 6.77e-15 1.81e-15 4.70e-07 4.70e-07 100.0%
Clock 0.00e+00 0.00e+00 0.00e-00 0.00e-00 0.0%
Macro 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.0%
Pad 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.0%

Total 6.77e-15 1.81e-15 4.70e-07 4.70e-07 100%

Area Measurement:

Design area 220 u^2 0% utilization.

Timing Information:

Delay Time Description

0.00 0.00 ^ input external delay


0.00 0.00 ^ binary in[2] (in)
0.11 0.11 ^ input3/X (sky130_fd_sc_hd_buf_1)
0.14 0.26 ^ _1_/X (sky130_fd_sc_hd_xor2_1)
0.07 0.33 ^ output 6/X (sky130_fd_sc_hd_buf_1)
0.0 0.33 ^ gray_out[1] (out)
0.33 data arrival time

(Path is unconstrained)
Generated GDS
Conclusions
In this report, the RTL code of 4-bit binary to gray has been designed in verilog. The code is
successfully verified with the UVM with 100% test case pass. The design code is further
processed in the openROAD tool to generate its GDS using the gf1 platform. It has shown that
the generated layout consumes 100nW power which occupies 220 sq. um area. There is no setup
and hold violations.

Common questions

Powered by AI

The combinational nature of a 4-bit Binary to Gray Code Converter allows for high performance in digital circuits, mainly because it doesn't rely on clock cycles or sequential elements for operation. This design directly computes output from input within minimal delay, which makes it efficient for real-time applications requiring fast processing. The absence of clock dependencies minimizes latency and power consumption, allowing the converter to be used effectively in high-speed and power-sensitive applications, enhancing systems where immediate code conversions are essential .

A UVM testbench for a 4-bit Binary to Gray Code Converter involves several components and follows a structured methodology to ensure proper verification. The testbench includes a transaction class to model input-output data, a driver to send input to the DUT (Design Under Test), a monitor to observe outputs, and a scoreboard to compare actual against expected outputs. The testbench also uses a sequencer to control the sequence of operations and a test class to instantiate the environment and run tests. The process entails generating random 4-bit binary inputs, observing the corresponding Gray code outputs, and using the scoreboard to identify mismatches. This setup allows for comprehensive functional verification by checking both expected and random edge cases .

The scoreboard component in UVM plays a crucial role in the verification process by ensuring that the digital design's output matches the predetermined expected results. For a 4-bit Binary to Gray Code Converter, the scoreboard compares the actual Gray code output generated by the converter with the expected Gray code calculated independently within the scoreboard. If there is a mismatch, an error is reported, helping identify deviations from expected behavior. This component effectively enables the verification process to substantiate that the converter functions correctly under all input conditions, increasing the confidence in its reliability before deployment .

Test case coverage plays a critical role in the verification process by ensuring that all possible input combinations and edge cases of the 4-bit Binary to Gray Code Converter are accounted for. This comprehensive coverage is crucial to ascertain that the converter performs effectively and without errors under all conditions. In practice, coverage is achieved by designing a testbench capable of applying a full range of binary inputs, observing the corresponding Gray code outputs, and using UVM components like sequencers to manage the random and structured sequencing of inputs. Functional verification checks both the typical operation and edge cases, ensuring reliability across all use cases .

The process of generating the GDS-II layout for a 4-bit Binary to Gray Code converter using OpenROAD involves translating RTL code into a physical layout. The architecture implemented uses the sky130hd technology platform. Important parameters for design include core utilization, place density, and timing constraints defined in scripts like config.mk and constraint.sdc. Core utilization is set low, reflecting a sparse layout to enhance manufacturability. The process involves synthesis, placement, routing, and verification of the design against physical design rules. After following these steps, the design is then converted to GDS-II format for further use in fabrication. Power analysis reveals that the design consumes minimal power (100nW) and occupies an area of 220 square micrometers without timing violations, indicating a well-optimized layout .

A 4-bit Binary to Gray Code Converter is a combinational circuit that converts a 4-bit binary input into its corresponding 4-bit Gray code output. This type of code conversion is crucial in digital systems to minimize errors where multiple bits change simultaneously in standard binary representation . In Verilog HDL, the converter is implemented using XOR operations where each Gray code bit is derived from the binary input. The most significant bit remains the same, and each subsequent Gray bit is obtained by XORing consecutive binary bits: gray[3] = binary[3], gray[2] = binary[3] ⊕ binary[2], gray[1] = binary[2] ⊕ binary[1], gray[0] = binary[1] ⊕ binary[0].

Gray code is preferred over binary code in certain digital systems because it minimizes errors that occur during the transition from one code value to another. In standard binary numbers, multiple bit changes can happen simultaneously, increasing the chance of errors. In contrast, Gray code is designed such that only one bit changes at a time during transitions between successive values. This one-bit change property makes Gray code particularly advantageous in error-sensitive applications like digital communication and error correction, where reducing the potential for a wrong state transition is crucial .

Not using clock or sequential elements in a 4-bit Binary to Gray Code Converter design enhances its testability by simplifying the circuit's behavior and removing synchronization issues typically associated with clock domains. As a purely combinational circuit, the converter can be adequately test-bench verified using random and corner cases without considering clock-related test scenarios. This simplification allows testbenches to comprehensively cover all possible input combinations in sequential order without worrying about potential timing mismatches or sequential state hold times, thus reducing verification complexity .

In a 4-bit Binary to Gray Code Converter, each bit of the Gray code is derived using XOR logic, starting with the original binary input. For the most significant bit, gray[3], it is directly equal to the binary[3]. For the remaining Gray code bits, each is produced by XORing consecutive binary bits: gray[2] is calculated as binary[3] ⊕ binary[2], gray[1] as binary[2] ⊕ binary[1], and gray[0] as binary[1] ⊕ binary[0]. This bitwise operation ensures that only one bit changes at a time between successive Gray code values, maintaining the code's essential properties for applications .

The OpenROAD tool is advantageous for generating a GDS-II layout for digital designs due to its end-to-end open-source framework that efficiently automates the processes of synthesis, placement, routing, and timing analysis. For a design like the 4-bit Binary to Gray Code Converter, OpenROAD's capability to handle multiple aspects of layout generation using a unified platform enhances optimization and design efficiency. Additionally, by utilizing specific technology nodes such as sky130hd, OpenROAD can achieve a minimal power consumption layout with accurate constraint management, well-suited for modern ASIC design workflows .

You might also like