banner

Design verilog code for the combinational circuit MUX2x1 in data flow modelling and simulate it on iverilog and GTKWave open simulator.

Design:

//***** design under test******
// design module
module mux2(
input [1:0]i,
input s,
output o);

// intermediate signals
wire x,y,ns;

// design the dataflow
assign ns = ~s;
assign x= ns & i[0];
assign y= s & i[1];
assign o = x|y;

endmodule

//******* test bench*********
// test bench module
module tb();
reg [1:0]i;
reg s;
wire o;

//instance of the desing in  test bench
mux2 m0(i[1:0],s,o);

//dumping the variable
initial begin
    $dumpfile("mux2.vcd");
    $dumpvars(-1,m0);
end

//generating test signals
initial begin
    s=1'b0;i=2'b00;#10;
    s=1'b1;i=2'b01;#10;
    s=1'b0;i=2'b10;#10;
    s=1'b1;i=2'b11;#10;
    s=1'b0;i=2'b11;#10;
    s=1'b1;i=2'b10;#10;
    s=1'b1;i=2'b01;#10;
    s=1'b0;i=2'b11;#10;
    s=1'b0;i=2'b01;#10;
    s=1'b1;i=2'b10;#10;
    $finish;
end
endmodule

Waveform:

No comments:

Post a Comment

Design verilog code for the combinational circuit MUX4x1 in structural style modelling by taking instance of MUX2X1 and simulate it on iverilog and GTKWave open simulator.

Design and test bench: //***** design under test****** // design top module module mux4( //input interface input [3:0]i, input[1:0]s, input ...