1、IP描述
比较器的IP,可以比较两路数据是否相等。相等输出为1,不等输出为0的aeb信号是需要测试的量。
2、基础测试
module compare_top( input [7:0] x1, input [7:0] x2, output result ); alteraip_compare U1( .dataa(x1), .datab(x2), .aeb(result) ); endmodule
`timescale 1ns/1ns modulecompare_top_tb; reg [7:0] x1; reg [7:0] x2; wireresult; compare_top U1_tb( .x1(x1), .x2(x2), .result(result) ); initial beginx1=0; x2=0; $monitor($realtime,,"x1=%d,x2=%d,result=%d",x1,x2,result); #1x1=1; x2=0; #1x1=2; x2=2; #1x1=4; x2=8'h4; #1$stop; end endmodule
测试代码和顶层代码如上。
3、结果分析
run -all # 0 x1= 0,x2= 0,result=1# 1 x1= 1,x2= 0,result=0# 2 x1= 2,x2= 2,result=1# 3 x1= 4,x2= 4,result=1# ** Note: $stop : D:/Library/FPGA_altera/A6_LPM_COMPARE/standard_module/compare_top_tb.v(27) # Time: 4 ns Iteration: 0 Instance: /compare_top_tb
测试结果和预期一致。