我尝试运行以下内容并收到此错误:
这是Verilog代码:
module needle( input referrence,input penalty,output index[7:0]);
//inout input_itemsets;
//input referrence;
//input penalty;
//output index;
parameter max_cols=8;
//
wire index[7:0];
wire referrence;
wire penalty;
//wire input_itemsets;
genvar i,idx;
generate
for( i = max_cols-4 ; i >= 0 ; i=i-1)
for( idx = 0 ; idx <= i ; idx=idx+1)
begin
assign index[i] = (idx + 1) * max_cols + (i + 1 - idx);
//assign index = (idx + 1) * max_cols + (i + 1 - idx);
//input_itemsets[index] <= maximum( input_itemsets[index-1-max_cols]+ referrence[index],
//input_itemsets[index-1] - penalty,
//input_itemsets[index-max_cols] - penalty);
end
endgenerate
endmodule
这是我收到的警告和错误:
WARNING:HDLCompiler:413 - "/home/suriyha/Monajalal/needle_t1/needle.v" Line 39: Result of 4-bit expression is truncated to fit in 1-bit target.
ERROR:HDLCompiler:1401 - "/home/suriyha/Monajalal/needle_t1/needle.v" Line 39: Signal index[3] in unit needle is connected to following multiple drivers:
Driver 0: output signal of instance Power (PWR_1_o_BUF_9).
Driver 1: output signal of instance Ground (GND_1_o_BUF_8).
Driver 2: output signal of instance Ground (GND_1_o_BUF_6).
Driver 3: output signal of instance Ground (GND_1_o_BUF_4).
Driver 4: output signal of instance Ground (GND_1_o_BUF_11).
Module needle remains a blackbox, due to errors in its contents
WARNING:HDLCompiler:1499 - "/home/suriyha/Monajalal/needle_t1/needle.v" Line 21: Empty module <needle> remains a black box.
然而,主要代码是“assign index =(idx + 1)* max_cols +(i + 1 - idx);”但我决定让“索引”成为一个数组来避免这个问题,但是我还在努力。因此,无论index是数组还是仅仅是变量,我还有这个多值问题。
此外,代码的C版本是:
for( idx = 0 ; idx <= i ; idx++){
index = (idx + 1) * max_cols + (i + 1 - idx);
input_itemsets[index]= maximum( input_itemsets[index-1-max_cols]+ referrence[index],
input_itemsets[index-1] - penalty,
input_itemsets[index-max_cols] - penalty);
}
我还想知道我们是否可以拥有一个嵌套循环,就像我们在Verilog版本的C计数器部分中所拥有的那样,或者在这种情况下如何避免“多个驱动程序”问题?
感谢。
答案 0 :(得分:4)
在Verilog代码中,大多数index
位是双驱动(x
)或不驱动(z
)的常量:
index[7:0]:zzzxxxx1
解释如下。外部循环从4到0,这意味着index[7:5]
未被驱动(z
)。内部循环从0到i
,展开到类似以下内容:
assign index[4] = (0 + 1) * max_cols + (4 + 1 - 0);
assign index[4] = (1 + 1) * max_cols + (4 + 1 - 1);
...
assign index[1] = (0 + 1) * max_cols + (1 + 1 - 0);
assign index[1] = (1 + 1) * max_cols + (1 + 1 - 1);
assign index[0] = (0 + 1) * max_cols + (0 + 1 - 0);
因此index[4:1]
是双驱动的(x
),只有index[0]
只有一个驱动程序。
在此处使用测试编译代码:EDA Playground
答案 1 :(得分:2)
output index[7:0]
是一个未压缩的位数组。与此相等的C是bool *index[8]
。我相信你想要output [7:0] index
。
问题:
警告:HDLCompiler:413 - “/home/suriyha/Monajalal/needle_t1/needle.v”第39行:截断4位表达式的结果以适合1位目标。
引用index[i] = (idx + 1) * max_cols + (i + 1 - idx);
。只有左手表达式的lsb ob将被分配给index[i]
(1位值)。右侧受让人的价值应至少为4位值。
错误:HDLCompiler:1401 - “/home/suriyha/Monajalal/needle_t1/needle.v”第39行:单位针中的信号索引[3]连接到以下多个驱动程序:[...]
此错误是由于您使用generate语句的方式。如果您解开for循环,您将看到多个assign index[3] = ...
。我建议用always @(*)
块替换gerenate块。输出应为output reg
,中间值(例如i
和idx
)应为integer
类型,或某些形式为压缩reg
(ex {{1} }})。
其他突出的问题。
reg [7:0] i, idx;
似乎是input_itemsets
。 Verilog中的Inouts与C非常不同。在Verilog中,在任何给定时间都应该有一个驱动程序。冲突的驱动程序将导致X.最好在驱动阶段制作带有样本状态和切换的副本。
您想要的内容可能如下所示:
答案 2 :(得分:0)
我使用生成句子只是为了在块之间建立连接,我看到你分配给index [] idx和i,这不是信号(这些没有驱动程序)......我的意思是那些值不会使索引获取值。你应该在编写verilog代码时思考,如果这意味着在硬件中。我的意思是参数和for不是硬件中的东西 如果你想索引获取值,你必须使用一个信号,它有一个驱动程序(输入,连线)。