banner

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

Design and test bench:

//*******Design under test******
//Design part
module mux4X1(
input [3:0] i,
input [1:0] e,
input [1:0] s,
output o
);

// intermediate signals
wire x1,x2,x3,x4,s1b,s2b;

// complement of selection lines
not u0 (s1b,s[0]);
not u2 (s2b,s[1]);
//4X1 mux structure
and u1 (x1,s1b,s2b,i[0],e[0],e[1]);
and u3 (x2,s2b,s[0],i[1],e[0],e[1]);
and u4 (x3,s[1],s1b,i[2],e[0],e[1]);
and u5 (x4,s[0],s[1],i[3],e[0],e[1]);
or u6 (o,x1,x2,x3,x4);
endmodule

//***** test bench module******
// creating test environment for DUT
module tb_mux4X1( );
reg [3:0]i;
reg [1:0]s;
reg [1:0]e;
wire o;

// taking instance of the mux4X1
mux4X1 m41(i[3:0],e[1:0],s[1:0],o);

initial
    begin
        $dumpfile("mux4X1_d.vcd");
        $dumpvars(-1,m41);
    end

always
    begin
        // only one input will activate at a time
        i=4'h1;e=2'b11;s=2'b00;#10; // s=0 and i=1 line 0 high
        i=4'h2;e=2'b11;s=2'b01;#10; // s=1 and i=2 iine 1 high
        i=4'h4;e=2'b11;s=2'b10;#10; // s=2 and i=4 line 2 high
        i=4'h8;e=2'b11;s=2'b11;#10; // s=3 and i=8 line 3 high

        // random selection and activation of input
        i=4'h2;e=2'b11;s=2'b01;#10;
        i=4'h3;e=2'b11;s=2'b10;#10;
        i=4'h7;e=2'b11;s=2'b11;#10;
        i=4'h9;e=2'b11;s=2'b10;#10;
        i=4'h4;e=2'b11;s=2'b01;#10;
        i=4'hE;e=2'b11;s=2'b00;#10;

        //finish
        $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 ...