西北工业大学数字电子技术基础实验报告实验2.docx
《西北工业大学数字电子技术基础实验报告实验2.docx》由会员分享,可在线阅读,更多相关《西北工业大学数字电子技术基础实验报告实验2.docx(19页珍藏版)》请在冰点文库上搜索。
西北工业大学数字电子技术基础实验报告实验2
数字电子技术基础第二次实验报告
一、题目代码以及波形分析
1.设计一款可综合的2选1多路选择器
①编写模块源码
modulemultiplexer(x1,x2,s,f);
inputx1,x2,s;
outputf;
assignf=(~s&x1)|(s&x2);
endmodule
②测试模块
`timescale1ns/1ps
moduletb_multiplexer;
regx1_test;
regx2_test;
regs_test;
wiref_test;
initial
s_test=0;
always#80s_test=~s_test;
initial
begin
x1_test=0;
x2_test=0;
#20
x1_test=1;
x2_test=0;
#20
x1_test=0;
x2_test=1;
#20
x1_test=1;
x2_test=1;
#20
x1_test=0;
x2_test=0;
#20
x1_test=1;
x2_test=0;
#20
x1_test=0;
x2_test=1;
#20
x1_test=1;
x2_test=1;
end
multiplexerUUT_multiplexer(.x1(x1_test),.x2(x2_test),.s(s_test),.f(f_test));
endmodule
③仿真后的波形截图
④对波形的分析
本例目的是令s为控制信号,实现二选一多路选择器。
分析波形图可以知道,s为0时,f输出x1信号;s为1时,f输出x2信号。
所以实现了目标功能。
2.设计一款可综合的2-4译码器
①编写模块源码
moduledec2to4(W,En,Y);
input[1:
0]W;
inputEn;
outputreg[0:
3]Y;
always@(W,En)
case({En,W})
3'b100:
Y=4'b1000;
3'b101:
Y=4'b0100;
3'b110:
Y=4'b0010;
3'b111:
Y=4'b0001;
default:
Y=4'b0000;
endcase
endmodule
②测试模块
`timescale1ns/1ps
moduletb_dec2to4;
reg[1:
0]W_test;
regEn_test;
wire[0:
3]Y_test;
initial
En_test=0;
always#80En_test=~En_test;
initial
begin
W_test=2'b00;
#20
W_test=2'b01;
#20
W_test=2'b11;
#20
W_test=2'b10;
#20
W_test=2'b00;
#20
W_test=2'b01;
#20
W_test=2'b11;
#20
W_test=2'b10;
#20
W_test=2'b00;
end
dec2to4UUT_dec2to4(.W(W_test),.En(En_test),.Y(Y_test));
endmodule
③仿真后的波形截图
④对波形的分析
本例目的是实现可综合的2-4译码器,其中数组W是输入信号,共有两个值,输入一个两位二进制数据,目的是通过译码器将它转换成独热码,数组Y是输出信号,输出四个二进制数据,构成独热码。
En是使能信号,当En为0时,输出的数组Y始终为0,译码器不工作;当En为1时,输出的数组Y为独热码,译码器工作。
根据输出的波形图,可以判断译码器实现了目的。
3.设计一款可综合的8-3编码器
①编写模块源码
moduleenc8to3(W,Y,z);
input[7:
0]W;
outputreg[2:
0]Y;
outputregz;
always@(W)
begin
z=1;
case(W)
8'b10000000:
Y=3'b111;
8'b01000000:
Y=3'b110;
8'b00100000:
Y=3'b101;
8'b00010000:
Y=3'b100;
8'b00001000:
Y=3'b011;
8'b00000100:
Y=3'b010;
8'b00000010:
Y=3'b001;
8'b00000001:
Y=3'b000;
defaultz=0;
endcase
end
endmodule
②测试模块
`timescale1ns/1ps
moduletb_enc8to3;
reg[7:
0]W_test;
wire[2:
0]Y_test;
wirez_test;
initial
begin
W_test=8'b10000000;
#20
W_test=8'b01000000;
#20
W_test=8'b00100000;
#20
W_test=8'b00010000;
#20
W_test=8'b00001000;
#20
W_test=8'b00000100;
#20
W_test=8'b00000010;
#20
W_test=8'b00000001;
#20
W_test=8'b00000000;
end
enc8to3UUT_enc8to3(.W(W_test),.Y(Y_test),.z(z_test));
endmodule
③仿真后的波形截图
④对波形的分析
本例目的是实现可综合的8-3编码器,其中数组W是输入信号,共有八个值,输入八位独热码数据,目的是通过编码器将它转换成三位二进制数据,数组Y是输出信号,输出一个三位二进制数据。
z是判断信号,当输入的数据是八位独热码时,输出的z为1,判断编码器工作;当输入的数据不是独热码时,输出的z为0,判断编码器不工作。
根据输出的波形图,可以判断编码器实现了目的。
4.设计一款可综合的1位二进制比较器
①编写模块源码
modulecomparer(a,b,f0,f1,f2);
inputa,b;
outputregf0,f1,f2;
always@(a,b)
case({a,b})
2'b00:
begin
f0=0;
f1=1;
f2=0;
end
2'b10:
begin
f0=1;
f1=0;
f2=0;
end
2'b01:
begin
f0=0;
f1=0;
f2=1;
end
2'b11:
begin
f0=0;
f1=1;
f2=0;
end
default;
endcase
endmodule
②测试模块
`timescale1ns/1ps
moduletb_comparer;
rega_test;
regb_test;
wiref0_test;
wiref1_test;
wiref2_test;
initial
begin
a_test=0;
b_test=0;
#20
a_test=1;
b_test=0;
#20
a_test=1;
b_test=1;
#20
a_test=0;
b_test=1;
#20
a_test=0;
b_test=0;
end
comparerUUT_comparer(.a(a_test),.b(b_test),.f0(f0_test),.f1(f1_test),.f2(f2_test));
endmodule
③仿真后的波形截图
④对波形的分析
本题目的是实现可综合的1位二进制比较器,其中a和b是输入数据,分别输入一个一位二进制数据,比较器将对它们进行比较。
f0、f1、f2是输出数据,用来表示比较结果,如果a大于b,则f0输出为1;如果a等于b,则f1输出为1;如果a小于b,则f2输出为1。
根据输出的波形图判断,1位二进制比较器实现了目标。
5.设计一款可综合的2+2位简单全加器
①编写模块源码
modulefulladder(carryin,x0,x1,y0,y1,s0,s1,carryout);
inputcarryin,x0,x1,y0,y1;
outputs0,s1,carryout;
adderstage0(carryin,x0,y0,s0,c1);
adderstage1(c1,x1,y1,s1,carryout);
endmodule
moduleadder(cin,x,y,s,cout);
inputcin,x,y;
outputs,cout;
assigns=x^y^cin,
cout=(x&y)|(x&cin)|(y&cin);
endmodule
②测试模块
`timescale1ns/1ps
moduletb_fulladder;
regcarryin_test;
regx0_test;
regx1_test;
regy0_test;
regy1_test;
wires0_test;
wires1_test;
wirecarryout_test;
initial
carryin_test=0;
always#160carryin_test=~carryin_test;
initial
begin
x0_test=0;
x1_test=0;
y0_test=0;
y1_test=0;
#10
x0_test=1;
x1_test=0;
y0_test=0;
y1_test=0;
#10
x0_test=1;
x1_test=1;
y0_test=0;
y1_test=0;
#10
x0_test=0;
x1_test=1;
y0_test=0;
y1_test=0;
#10
x0_test=0;
x1_test=0;
y0_test=1;
y1_test=0;
#10
x0_test=1;
x1_test=0;
y0_test=1;
y1_test=0;
#10
x0_test=1;
x1_test=1;
y0_test=1;
y1_test=0;
#10
x0_test=0;
x1_test=1;
y0_test=1;
y1_test=0;
#10
x0_test=0;
x1_test=0;
y0_test=1;
y1_test=1;
#10
x0_test=1;
x1_test=0;
y0_test=1;
y1_test=1;
#10
x0_test=1;
x1_test=1;
y0_test=1;
y1_test=1;
#10
x0_test=0;
x1_test=1;
y0_test=1;
y1_test=1;
#10
x0_test=0;
x1_test=0;
y0_test=0;
y1_test=1;
#10
x0_test=1;
x1_test=0;
y0_test=0;
y1_test=1;
#10
x0_test=1;
x1_test=1;
y0_test=0;
y1_test=1;
#10
x0_test=0;
x1_test=1;
y0_test=0;
y1_test=1;
#10
x0_test=0;
x1_test=0;
y0_test=0;
y1_test=0;
#10
x0_test=1;
x1_test=0;
y0_test=0;
y1_test=0;
#10
x0_test=1;
x1_test=1;
y0_test=0;
y1_test=0;
#10
x0_test=0;
x1_test=1;
y0_test=0;
y1_test=0;
#10
x0_test=0;
x1_test=0;
y0_test=1;
y1_test=0;
#10
x0_test=1;
x1_test=0;
y0_test=1;
y1_test=0;
#10
x0_test=1;
x1_test=1;
y0_test=1;
y1_test=0;
#10
x0_test=0;
x1_test=1;
y0_test=1;
y1_test=0;
#10
x0_test=0;
x1_test=0;
y0_test=1;
y1_test=1;
#10
x0_test=1;
x1_test=0;
y0_test=1;
y1_test=1;
#10
x0_test=1;
x1_test=1;
y0_test=1;
y1_test=1;
#10
x0_test=0;
x1_test=1;
y0_test=1;
y1_test=1;
#10
x0_test=0;
x1_test=0;
y0_test=0;
y1_test=1;
#10
x0_test=1;
x1_test=0;
y0_test=0;
y1_test=1;
#10
x0_test=1;
x1_test=1;
y0_test=0;
y1_test=1;
#10
x0_test=0;
x1_test=1;
y0_test=0;
y1_test=1;
end
fulladderUUT_fulladder(.carryin(carryin_test),.x0(x0_test),.x1(x1_test),.y0(y0_test),.y1(y1_test),.s0(s0_test),.s1(s1_test),.carryout(carryout_test));
endmodule
③仿真后的波形截图
④对波形的分析
本题目的是实现可综合的2+2位简单全加器,carryin、x0、x1、y0、y1是输入数据,s0、s1、carryout是输出数据,x0、x1构成一个两位二进制数据,y0、y1构成一个两位二进制数据,全加器的功能是把这两个二进制数据相加并输出一个由s0、s1组成的两位二进制数据以及由carryout表示的进位位。
分析波形图可以知道在carryin为0和1时,全加器针对不同的x0、x1、y0、y1均可以输出正确的结果,实现了目标功能。
二、本次实验收获和心得
通过本次实验,对二选一多路选择器、编码器、译码器、比较器、全加器的原理有了更深入的了解,并且提高了自己的verilog编码实践能力,我还学会了针对数组类型的数据写测试代码时,要把数组作为整体test对象。
体会是,只有不断地实践和编码才能提高自己的能力,仅仅停留在理论层面是不够的,应该在课下多进行实践。