实验一:多路选择器
- 设计要求:4选1
- 代码
module selector(a,b,c,d,sl0,sl1,out);
parameter WL = 8;
input [WL-1:0] a,b,c,d;
input sl0,sl1;
output [WL-1:0] out;
reg [WL-1:0] out;
always @ (a or b or c or d or sl0 or sl1) begin
case({sl0,sl1})
2'b00 : out = a;
2'b01 : out = b;
2'b10 : out = c;
2'b11 : out = d;
endcase
end
endmodule
4X4的交叉开关消耗资源成倍的增长了。
- 波形仿真
实验二:交叉开关
- 设计要求:编写一个4X4路交叉开关
- 代码
module switch(in0,in1,in2,in3,sl0,sl1,sl2,sl3,out0,out1,out2,out3); parameter WL = 8; input [WL-1:0] in0,in1,in2,in3; input [1:0] sl0,sl1,sl2,sl3; output [WL-1:0] out0,out1,out2,out3; reg [WL-1:0] out0,out1,out2,out3; always@(in0 or in1 or in2 or in3 or sl0) begin case(sl0) 2'b00:out0 = in0; 2'b01:out0 = in1; 2'b10:out0 = in2; 2'b11:out0 = in3; endcase end always@(in0 or in1 or in2 or in3 or sl1) begin case(sl1) 2'b00:out1 = in0; 2'b01:out1 = in1; 2'b10:out1 = in2; 2'b11:out1 = in3; endcase end always@(in0 or in1 or in2 or in3 or sl2) begin case(sl2) 2'b00:out2 = in0; 2'b01:out2 = in1; 2'b10:out2 = in2; 2'b11:out2 = in3; endcase end always@(in0 or in1 or in2 or in3 or sl3) begin case(sl3) 2'b00:out3 = in0; 2'b01:out3 = in1; 2'b10:out3 = in2; 2'b11:out3 = in3; endcase end endmodule
- RTL View
5.结论:4X4的交叉开关消耗资源成倍的增长了。
实验三:优先编码器
- 设计要求:编写一个8输入的优先编码器
- 代码:
module TEST_3(in,out);
parameter WL=8;
input [WL-1:0] in;
output [2:0] out;
reg out;
always @(in) begin
if(in[0]) out = 3'b001;
else if(in[1]) out = 3'b010;
else if(in[2]) out = 3'b011;
else if(in[3]) out = 3'b100;
else if(in[4]) out = 3'b101;
else if(in[5]) out = 3'b110;
else if(in[6]) out = 3'b111;
else out = 3'b000;
end
endmodule
4-16译码器的资源消耗约是3-8译码器的2倍。
- RTL View
实验四:多路译码器
- 设计要求:编写一个4-16的译码器
- 代码:
module TEST_4(in,out); input [3:0] in; output[15:0] out; reg [15:0]out; always @(in) begin case(in) 4'b0000 : out = 16'b0000_0000_0000_0001; 4'b0001 : out = 16'b0000_0000_0000_0010; 4'b0010 : out = 16'b0000_0000_0000_0100; 4'b0011 : out = 16'b0000_0000_0000_1000; 4'b0100 : out = 16'b0000_0000_0001_0000; 4'b0101 : out = 16'b0000_0000_0010_0000; 4'b0110 : out = 16'b0000_0000_0100_0000; 4'b0111 : out = 16'b0000_0000_1000_0000; 4'b1000 : out = 16'b0000_0001_0000_0000; 4'b1001 : out = 16'b0000_0010_0000_0000; 4'b1010 : out = 16'b0000_0100_0000_0000; 4'b1011 : out = 16'b0000_1000_0000_0000; 4'b1100 : out = 16'b0001_0000_0000_0000; 4'b1101 : out = 16'b0010_0000_0000_0000; 4'b1110 : out = 16'b0100_0000_0000_0000; 4'b1111 : out = 16'b1000_0000_0000_0000; endcase end endmodule
- RTL View
- 结论:4-16译码器的资源消耗约是3-8译码器的2倍。