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

All QuestionsCategory: VerilogWrite a verilog code for gray to binary converter using INOUT?
Chetan Shidling Staff asked 5 years ago

I need code.

1 Answers
Chetan Shidling Staff answered 5 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