Latest Post

Verilog: Binary to Gray Converter Behavioral Modelling using Case Statement with Testbench Code

Verilog Code for Binary to Gray Converter Behavioral Modelling using Case Statement with Testbench Code

module Bin_Gry(
    input [3:0]din,
    output [3:0]dout
    );
reg [3:0]dout; 

always @ (din)
    begin 
        case (din)
           0 : dout = 0; 
           1 : dout = 1;
           2 : dout = 3; 
           3 : dout = 2; 
           4 : dout = 6; 
           5 : dout = 7; 
           6 : dout = 5; 
           7 : dout = 4; 
           8 : dout = 12; 
           9 : dout = 13; 
           10 : dout = 15; 
           11 : dout = 14; 
           12 : dout = 10; 
           13 : dout = 11; 
           14 : dout = 9; 
           15 : dout = 8; 
           default: dout = 4’b xxxx;  
        endcase
end  
endmodule

//Testbench code for Binary to Gray Converter Behavioral Modelling using Case Statement

initial begin
// Initialize Inputs 
din = 0;
// Wait 100 ns for global reset to finish#100;
// Add stimulus here 
#100; din = 4;
#100; din = 15;
#100; din = 8; 
end
initial begin 
#100 
$monitor(“din = %b, dout = %b, din, dout); 
end 
endmodule

Xillinx Output:

Verilog Code for Binary to Gray Converter Behavioral Modelling using Case Statement with Testbench Code
Binary to Gray Converter Behavioral Modelling Verilog Code

Comments

Popular posts from this blog

Samir Palnitkar Solution Manual Free Download PDF of Verilog HDL

VLSI: 8-3 Encoder Dataflow Modelling with Testbench

VLSI: 4-1 MUX Dataflow Modelling with Testbench

Verilog: 4 - 2 Encoder Structural/Gate Level Modelling with Testbench

1 to 4 DEMUX (Demultiplexer) Verilog CodeStructural/Gate Level Modelling with Testbench