LAB2: 4 to 1 Multiplexer using 2to1 Mux - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

206


43
 
1
module tb_MUX4;
2
// Declare variables to be connected to inputs as regs
3
 // declared as regs since we want to change them
4
reg IN0, IN1, IN2, IN3;
5
reg S1, S0;
6
  
7
// Declare output wires since we are not changing them but only observing them
8
wire OUTPUT;
9
  
10
// Instantiate the multiplexer, tie the ports
11
  MUX4 mymux1 (
12
    .f(OUTPUT), 
13
    .w0(IN0), 
14
    .w1(IN1), 
15
    .w2(IN2), 
16
    .w3(IN3), 
17
    .s1(S1), 
18
    .s0(S0)) ;
19
 
20
// Stimulate the inputs, set input lines of mux and 
21
initial 
22
begin
23
  IN0=1; IN1=0; IN2=1; IN3=0; // you may change them as you like
24
 
25
  for(int i=0; i<4; i=i+1 ) // checking all possible values of S1,S0
26
    begin
27
      #5 {S1, S0}=i;// 00,01,10,11
28
    end
29
  
30
   #5 $finish;
31
end
32
  
33
initial 
34
begin
35
 // dumps all values whenever there is a change in any.
36
$monitor( IN0, IN1, IN2, IN3, S1, S0,OUTPUT);
37
// Uncomment the next two lines if you want to see the timing diagram as well
38
$dumpfile("dump.vcd");// vcd=value change dump
39
$dumpvars(1); // dump all variables in the wave form
40
end
41
42
43
endmodule
xxxxxxxxxx
1
27
 
1
module MUX2(f,s,w0,w1);
2
input s,w0,w1;
3
output f;
4
5
 // Using gate level assignement
6
  wire sn, andout0, andout1;
7
  not (sn,s);
8
  and (andout0, sn,w0);
9
  and (andout1, s ,w1);
10
  or(f,andout0,andout1);
11
12
  
13
endmodule
14
15
module MUX4(f,s0,s1,w0,w1,w2,w3);
16
17
  input s0,s1,w0,w1,w2,w3;
18
  output f;
19
  
20
  wire tmp0,tmp1;
21
22
  MUX2 M0 (tmp0, s0,w0,w1);
23
  MUX2 M1 (tmp1, s0,w2,w3);
24
  MUX2 M2 (f, s1,tmp0,tmp1);
25
  
26
endmodule
27
584 views and 0 likes     
 
Simple 4 to 1 Multiplexer
Written in Gate level of abstraction

Simple 4 to 1 Multiplexer
Written in Gate level of abstraction

2110:0