CS Electrical And Electronics
@cselectricalandelectronics

Write a verilog code for gray to binary?

All QuestionsCategory: VerilogWrite a verilog code for gray to binary?
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

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

//TB

module Gray_BIn_tf;

// Inputs

reg [3:0] g;

// Outputs

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’b1000;
#100;
g=4’b1001;
#100;
g=4’b1001;
#100;
g=4’b1010;
#100;
end

endmodule