Verilog 使用两个4 CLA';s
当我模拟CLA4Top、CLA8Top和测试时,我不断得到一个错误。 给出了测试平台,并编译了整个项目。对于CLA4Top,我认为“cout”看起来是正确的,但“sum”与预期输出不匹配。我更改了,这是更新的代码: 这是CLA4Top.svVerilog 使用两个4 CLA';s,verilog,system-verilog,digital-logic,questasim,Verilog,System Verilog,Digital Logic,Questasim,当我模拟CLA4Top、CLA8Top和测试时,我不断得到一个错误。 给出了测试平台,并编译了整个项目。对于CLA4Top,我认为“cout”看起来是正确的,但“sum”与预期输出不匹配。我更改了,这是更新的代码: 这是CLA4Top.sv //4 bit carry lookahead adder module CLA4Top(ain, bin, cin, sum, cout); //parameter nBITS = 4; //logic [nBITS - 1 : 0] ain, bin,
//4 bit carry lookahead adder
module CLA4Top(ain, bin, cin, sum, cout);
//parameter nBITS = 4;
//logic [nBITS - 1 : 0] ain, bin, sum;
//logic cin, cout;
input [3:0] ain, bin;
input cin;
output logic [3:0] sum;
output logic cout;
CLA4Bit C1(.*);
test #(4) TB(.*);
endmodule
module CLA4Bit (ain, bin, cin, sum, cout);
timeunit 1ns/1ns;
input [3:0] ain, bin;
input cin;
output logic [3:0] sum;
output logic cout;
wire p0,p1,p2,p3,g0,g1,g2,g3,c1,c2,c3,c4,c0;
assign p0=(ain[0]^bin[0]),
p1=(ain[1]^bin[1]),
p2=(ain[2]^bin[2]),
p3=(ain[3]^bin[3]);
assign g0=(ain[0]&bin[0]),
g1=(ain[1]&bin[1]),
g2=(ain[2]&bin[2]),
g3=(ain[3]&bin[3]);
assign c0=cin,
c1=g0|(p0&cin),
c2=g1|(p1&g0)|(p1&p0&cin),
c3=g2|(p2&g1)|(p2&p1&g0)|(p1&p1&p0&cin),
c4=g3|(p3&g2)|(p3&p2&g1)|(p3&p2&p1&g0)|(p3&p2&p1&p0&cin);
assign sum[0] = ain[0] ^ bin[0] ^ cin,
sum[1] = ain[1] ^ bin[1] ^ c1,
sum[2] = ain[2] ^ bin[2] ^ c2,
sum[3] = ain[3] ^ bin[3] ^ c3;
assign cout=c4;
endmodule
这是CLA8Top.sv
// module with 8 bit adder using 4 bit CLA instances
module CLA8Top(ain, bin, cin, sum, cout);
//parameter nBITS = 8;
input [7:0] ain, bin;
input cin;
output logic [7:0] sum;
output logic cout;
wire c1;
// CLA4Bit c11(ain[3:0],bin[3:0],1'b0,sum[3:0],c1);
CLA4Bit c11(ain[3:0],bin[3:0],cin,sum[3:0],c1);
CLA4Bit c22(ain[7:4],bin[7:4],c1,sum[7:4],cout);
test #(8) TB(.*);
endmodule
这是testbench.sv
// Test bench for Generic N-Bits Adder design module
module test(ain, bin, cin, sum, cout);
timeunit 1ns/1ns;
parameter nBITS = 4;
parameter DELAY = 100;
input [nBITS - 1 : 0] sum;
input cout;
output [nBITS - 1 : 0] ain, bin;
output cin;
logic [nBITS - 1 : 0] ain, bin, sum;
logic cin, cout;
// test variables
logic [nBITS : 0] exp_value;
int i, j, test_count;
bit error;
initial begin
error = 0;
test_count = 0;
cin = 0;
repeat(2) begin
for(i = 0; i < (1 << nBITS); i++) begin
ain = i;
for(j = 0; j < (1 << nBITS); j++) begin
test_count++;
bin = j;
exp_value = ain + bin + cin;
#DELAY;
if({cout, sum} !== exp_value) begin
$display("For inputs: ain = %b, bin = %b, cin = %b :: Actual outputs: cout = %1b, sum = %b :: Expected outputs: cout = %1b, sum = %b", ain, bin, cin, cout, sum, exp_value[nBITS], exp_value[nBITS-1:0]);
error = 1;
end // end for if block
end // end for j for loop
end // end for i for loop
cin = ~cin;
end // end for repeat block
if(error === 0)
$display("***Congratulations, No errors found after %d tests***", test_count);
else
$display("***Sorry, errors found in your code ***");
end // end for initial block
endmodule
//通用N位加法器设计模块测试台
模块测试(ain、bin、cin、sum、cout);
时间单位为1ns/1ns;
参数nBITS=4;
参数延迟=100;
输入[nBITS-1:0]和;
输入输出;
输出[nBITS-1:0]ain,bin;
输出cin;
逻辑[nBITS-1:0]ain、bin、sum;
逻辑cin,cout;
//测试变量
逻辑[n位:0]exp\u值;
int i,j,测试计数;
误码;
初始开始
误差=0;
测试计数=0;
cin=0;
重复(2)开始
对于(i=0;i<(1而言,日志文件显示sum[3]
与预期值不匹配。c3
的等式中存在输入错误。更改:
c3=g2|(p2&g1)|(p2&p1&g0)|(p1&p1&p0&cin),
//
致:
日志文件显示,sum[3]
与预期值不匹配。c3
的公式中有输入错误。更改:
c3=g2|(p2&g1)|(p2&p1&g0)|(p1&p1&p0&cin),
//
致:
是的,所以问题在于CLA4Bit模块,我认为它的和与预期不匹配。我正在查看波形,但当我查看它时,很难知道我在哪里出错。你现在可以忽略CLA8Top.sv。测试台是由讲师提供的,并且已经被证明是有效的。是的,所以问题是h对于CLA4Bit模块,我认为它的总和与预期不符。我正在查看波形,但当我查看它时,很难知道我哪里出了问题。现在可以忽略CLA8Top.sv。测试台是由讲师提供的,并已被证明有效。