[英]Verilog code compiles but why won't the simulation run?
我的代码包含两个文件。 一个文件包含所有模块,一个文件包含测试平台。 当我尝试在测试台上运行仿真时,在我的模块之一的此行上出现未解决的参考错误:
Add_half (p[3], g[3], in_a[3], in_b[3]);
这条线出现在我的测试平台调用的模块中。
可能是什么问题呢?
这是测试平台的代码。 `时标1ns / 100ps
module CARRYLOOKAHEAD_TB;
reg [3:0] in_a_tb;
reg [3:0] in_b_tb;
reg in_c0_tb;
wire [3:0] s_tb;
wire c4_tb;
CarryLookAheadAdder DUT (.in_a(in_a_tb), .in_b(in_b_tb), .in_c0(in_c0_tb), .out_s(s_tb), .out_c4(c4_tb));
initial
begin
in_a_tb = 4'b0000;
in_a_tb = 4'b0001;
in_c0_tb = 1'b0;
#50
in_a_tb = 4'b0000;
in_a_tb = 4'b0001;
in_c0_tb = 1'b1;
#50
in_a_tb = 4'b0001;
in_a_tb = 4'b0001;
in_c0_tb = 1'b0;
#50
in_a_tb = 4'b1111;
in_a_tb = 4'b0001;
in_c0_tb = 1'b0;
#50
in_a_tb = 4'b1111;
in_a_tb = 4'b0000;
in_c0_tb = 1'b1;
#50 $stop;
#20 $finish;
end
endmodule
这是模块的代码
module Add_half (sum, c_out, a, b);
input a, b;
output c_out, sum;
assign sum = a ^ b;
assign c_out = a & b;
endmodule
这就是测试台所称的
module CarryLookAheadAdder (in_a, in_b, in_c0, out_s, out_c4);
input [3:0] in_a;
input [3:0] in_b;
input in_c0;
output reg [3:0] out_s;
output reg out_c4;
reg [3:0] p;
reg [3:0] g;
reg [3:0] c;
always@(in_a, in_b, in_c0)
begin
out_s[0] = (in_a[0] ^ in_b[0]) ^ in_c0;
Add_half (p[3], g[3], in_a[3], in_b[3]);
Add_half (p[2], g[2], in_a[2], in_b[2]);
Add_half (p[1], g[1], in_a[1], in_b[1]);
Add_half (p[0], g[0], in_a[0], in_b[0]);
out_c4 = c[4];
out_s[3] = p[3] ^ c[3];
out_s[2] = p[2] ^ c[2];
out_s[1] = p[1] ^ c[1];
out_s[0] = p[0] ^ c[0];
end
endmodule
您缺少实例名称。 您的模拟器可能认为该语句是UDP实例,因此在设计详细说明时会给出未解决的参考错误。 编译不会使用定义来解析模块/ UDP实例,因此这些错误不会导致编译失败。
尝试
Add_half add_half_inst(p [3],g [3],in_a [3],in_b [3]);
编辑:Add_half不是函数或任务,不能放在Always块中。 它是一个模块,因此被实例化,而不被调用。 记住,您在这里为逻辑电路建模。
Add_half add_half_0(p[3], g[3], in_a[3], in_b[3]);
Add_half add_half_1(p[3], g[3], in_a[3], in_b[3]);
...
注意,每个实例都有一个唯一的名称。 您要实例化同一电路4次,只需对输入和输出进行接线。 实例名称是必需的,因此可以使用层次结构标识符唯一地解析它们。
由于c为[3:0],因此无法使用
out_c4 = c[4];
有人可能会提到一个循环,但是我认为您现在应该忽略这些循环,即使它们在此处适当。
除了Adam12和GuanoLoco,还有一些一般注意事项:
您为CarryLookAheadAdder模块分配了两次out_s [0]
out_s[0] = (in_a[0] ^ in_b[0]) ^ in_c0;
...
out_s[0] = p[0] ^ c[0];
您不会在任何地方使用“ g”变量输出。 您可能希望这是您的“ c”,因为我猜这是您的随身物品。
除了Adam12的答案中提到的步骤(添加实例名称,移出始终块)之外,您还需要更改连接线上的类型。
reg [3:0] p;
reg [3:0] g;
应该
wire [3:0] p;
wire [3:0] g;
这是因为它们直接连接到模块上的端口。 您只将reg用于always块中分配的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.