Latest Post

Ads

Verilog: 4 to 2 Encoder Behavioral Modelling using Case Statement with Testbench Code

Verilog Code for 4 to 2 Encoder Behavioral Modelling using Case Statement with Testbench Code

module 4_2_ENC(
    input [3:0]din,
    output [1:0]dout 
    );
reg [1:0]dout;
always @ (din)
case (din)
    1 : dout[0] = 0; 
    2 : dout[1] = 1; 
    4 : dout[2] = 2; 
    8 : dout[3] = 3; 
    default : dout = 2’bxx;
endcase
endmodule

//Testbench code for 4 to 2 Encoder 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=1; 
#100; din=2; 
#100; din=4; 
#100; din=8;
end
initial begin 
#100 
$monitor(“din=%b, dout=%b”, din, dout); 
end 
endmodule

Xillinx Output:

Verilog Code for 4 to 2 Encoder Behavioral Modelling using Case Statement with Testbench Code
4 - 2 Encoder Behavioral Modelling Verilog Response

Comments

Ads

Popular posts from this blog

VLSI: 1-4 DEMUX (Demultiplexer) Dataflow Modelling with Testbench

VLSI: BCD to Excess 3 and Excess 3 to BCD Dataflow Modelling

VLSI: 2 Bit Magnitude Comparator Dataflow Modelling

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

Full Subtractor Verilog Code in Structural/Gate Level Modelling with Testbench