need help in multiplexer in FPGA

Status
Not open for further replies.

dil01

Newbie level 1
Joined
Feb 25, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
12
i need help understanding this verilog code..

in this code first 2X1 multiplexer is made using gate level model..

then they have used the instance of 2X1 mux to create 4X1 multiplexer..

i dont understand how they have used 2x1 mux in 4x1 generation and then used 2x1 and 4x1 mux to generate 8x1 multiplexer..

can someone plz help and make me understand the code..


Code starts from here


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module 2-1mux(x,b,a,s);
input a,b,s;
output x;
wire w1,w2,w3;
not(w1,s);
and(w2,w1,a);
and(w3,s,b);
or(x,w2,w3);
endmodule
module 4-1mux(x,data,sel);
input [3:0] data;
input [1:0] sel;
output x;
2-1mux ins1(w1,data[3],data[2],sel[1]);
2-1mux ins2(w2,data[1],data[0],sel[1]);
2-1mux ins3(x,w1,w2,sel[0]);
 
endmodule
module 8-1mux(x,data,sel);
input [7:0] data;
input [2:0] sel;
output x;
4-1mux ins1(w1,data[7:4],sel[2:1]);
4-1mux ins2(w2,data[3:0],sel[2:1]);
2-1mux ins3(x,w1,w2,sel[0]);
 
endmodule

 
Last edited by a moderator:

Who ever wrote that code you're reviewing isn't very experience using Verilog. They have an invalid name for their modules, they aren't using 2001 port declarations, and they aren't instantiating with named port mapping.

Maybe showing you the behavioral description will make it easier to see.

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module mux_4to1(
  output        x,
  input   [3:0] data,
  input   [1:0] sel
);
 
  wire d_3to2, d_1to0;
 
  always @ * begin
 
    case (sel[1])  // 2-to-1 mux
      1'b0 : d_1to0 = data[0];
      1'b1 : d_1to0 = data[1];
    endcase
 
    case (sel[1])  // 2-to-1 mux
      1'b0 : d_3to2 = data[2];
      1'b1 : d_3to2 = data[3];
    endcase
 
  end
 
  // select between the 2-to-1 muxes
  assign x = sel[0] ? d_3to2 : d_1to0;
 
endmodule
 
 
module mux_8to1 (x
  output        x,
  input   [7:0] data,
  input   [2:0] sel
);
 
  always @ * begin
 
    case (sel[2:1])  // 4-to-1 mux
      2'b00 : d_3to0 = data[0];
      2'b01 : d_3to0 = data[1];
      2'b10 : d_3to0 = data[2];
      2'b11 : d_3to0 = data[3];
    endcase
 
    case (sel[2:1])  // 4-to-1 mux
      2'b00 : d_7to4 = data[4];
      2'b01 : d_7to4 = data[5];
      2'b10 : d_7to4 = data[6];
      2'b11 : d_7to4 = data[7];
    endcase
 
  end
 
  // select between the two 4-to-1 muxes
  assign x = sel[0] ? d_7to4 : d_3to0;
 
endmodule

 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…