CS Electrical And Electronics
@cselectricalandelectronics

Write a verilog code for gray to binary converter using INOUT?

All QuestionsCategory: VerilogWrite a verilog code for gray to binary converter using INOUT?
CS Electrical And Electronics Staff asked 4 years ago

I need code.

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

//GRAY TO BIN USING INOUT

module GRAY_BIN(g,b);
input [3:0] g;
inout [3:0] b;
assign b[3]=g[3];
assign b[2]=b[3]^g[2];
assign b[1]=b[2]^g[1];
assign b[0]=b[1]^g[0];
endmodule

//TB

module Gray_bin_tb;

// Inputs

reg [3:0] g;

// Bidirs

wire [3:0] b;

// Instantiate the Unit Under Test (UUT)

GRAY_BIN uut (
.g(g),
.b(b)
);
initial begin

// Initialize Inputs

g = 0;

// Wait 100 ns for global reset to finish

#100;

// Add stimulus here

g=4’b0001;
#100;
g=4’b0011;
#100;
g=4’b0010;
#100;
g=4’b0110;
#100;
end

endmodule