Professional Documents
Culture Documents
Multiplex Ers
Multiplex Ers
18251A04C0
Software : Edaplayground
Program:
//4to1 mux:
//Test bench
module behtb4_1mux;
// Inputs
reg [3:0] a;
reg [1:0] s;
// Outputs
wire y;
beh4_1mux uut (
.a(a),
.s(s),
.y(y)
);
Initial
begin
$dumpfile(“dump.vcd”);
$dumpvars();
// Initialize Inputs
a = 0;
s = 0;
#100;s=2'b00;a[0]=1;
#100;s=2'b01;a[1]=0;
#100;s=2'b01;a[1]=1;
#100;s=2'b10;a[2]=0;
#100;s=2'b10;a[2]=1;
#100;s=2'b11;a[3]=0;
#100;s=2'b11;a[3]=1;
end
endmodule
CODE:
input [3:0] a;
input [1:0] s;
output reg y;
always @(a or s)
begin
case(s)
2'b00: y=a[0];
2'b01: y=a[1];
2'b10: y=a[2];
2'b11: y=a[3];
default: y=0;
endcase
end
endmodule
//8to1 mux
//TESTBENCH
// or browse Examples
module behtb8_1mux;
// Inputs
reg [7:0] a;
reg [2:0] s;
// Outputs
wire y;
beh8_1mux uut (
.a(a),
.s(s),
.y(y)
);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
// Initialize Inputs
a = 0;
s = 0;
#10;s=3'b000;a[0]=1;
#10;s=3'b001;a[1]=0;
#10;s=3'b001;a[1]=1;
#10;s=3'b010;a[2]=0;
#10;s=3'b010;a[2]=1;
#10;s=3'b011;a[3]=0;
#10;s=3'b011;a[3]=1;
#10;s=3'b100;a[4]=0;
#10;s=3'b100;a[4]=1;
#10;s=3'b101;a[5]=0;
#10;s=3'b101;a[5]=1;
#10;s=3'b110;a[6]=0;
#10;s=3'b110;a[6]=1;
#10;s=3'b111;a[7]=0;
end
endmodule
CODE:
input [7:0] a;
input [2:0] s;
output reg y;
always @(a or s)
begin
case(s)
3'b000: y = a[0];
3'b001: y = a[1];
3'b010: y = a[2];
3'b011: y = a[3];
3'b100: y = a[4];
3'b101: y = a[5];
3'b110: y = a[6];
3'b111: y = a[7];
default: y = 0;
endcase
end
endmodule
//DEMULTIPLEXERS
//1to4
//TESTBENCH
// or browse Examples
module behtb1_4demux;
// Inputs
reg a;
reg [1:0] s;
// Outputs
wire [3:0] y;
beh1_4demux uut (
.y(y),
.a(a),
.s(s)
);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
// Initialize Inputs
a = 1;
s = 0;
#10;s=2'b00;
#10;s=2'b01;
#10;s=2'b10;
#10;s=2'b11;
// Add stimulus here
end
endmodule
CODE:
input a;
input [1:0] s;
always @(y or s)
begin
case(s)
default: y=0;
endcase
end
endmodule
//1to8
//TESTBENCH
// or browse Examples
module behtb1_8demux;
// Inputs
reg a;
reg [2:0] s;
// Outputs
wire [7:0] y;
beh1_8demux uut (
.y(y),
.a(a),
.s(s)
);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
// Initialize Inputs
a = 1;
s = 0;
#10;s=3'b000;
#10;s=3'b001;
#10;s=3'b010;
#10;s=3'b011;
#10;s=3'b100;
#10;s=3'b101;
#10;s=3'b110;
#10;s=3'b111;
end
endmodule
CODE:
input a;
input [2:0] s;
always @(y or s)
begin
case(s)
default: y=0;
endcase
end
endmodule
Result: the 4to1,8to1 mux and 1to4,1to8 demux are realised in behavioral style in verilog using
edaplayground