我试图实现一个简单的verilog代码,如下所示:
module test1(
input ACLK,
input RST,
output test_output1,
output test_output2
);
//wire ACLK;
//wire RST;
reg test_output1;
reg test_output2;
assign test_output1 = ACLK;
always @(posedge ACLK or negedge RST)
begin
if(!RST)
begin
//test_output1 <=0;
test_output2 <=0;
end
else
begin
//test_output1 <=0;
test_output2 <=1;
end
end
endmodule
当我尝试在Xilinx ISE中合成它时,我收到以下错误消息:
=========================================================================
* HDL Compilation *
=========================================================================
Compiling verilog file "test1.v" in library work
ERROR:HDLCompilers:27 - "test1.v" line 30 Illegal redeclaration of 'test_output1'
ERROR:HDLCompilers:27 - "test1.v" line 31 Illegal redeclaration of 'test_output2`
我无法解决此错误。任何帮助都将受到高度赞赏。
答案 0 :(得分:3)
如果在portlist中声明端口的方向,则还必须声明类型。这称为ANSI样式标题。
还有一个非ANSI样式标题,用于分隔端口列表,方向和类型。如果您正在使用IEEE1364-1995约定,则必须使用非ANSI样式,并且不能声明类型(例如output reg test_output2;
是非法的,而output test_output2; reg test_output2;
是合法的)。由于支持IEEE1364-2001 ANSI和非ANSI样式(并且非ANSI允许output reg test_output2;
)。所有现代Verilog仿真器都是SystemVerilog(IEEE1800)仿真器,因此它是设计人员的选择。 (ANSI样式更受欢迎,因为它更少打字)。
ANSI样式标题:
module test1(
input ACLK,
input RST,
output test_output1,
output reg test_output2 );
非ANSI样式标题:
module test1( ACLK, RST, test_output1, test_output2 );
input ACLK;
input RST;
output test_output1;
output test_output2;
reg test_output2;
注意:对于IEEE1364,您无法使用reg
语句驱动assign
,它必须是网络类型。 IEEE1800已经软化了重新启动logic
而不是reg
的规则,但通常如果您要使用assign
那么您应该分配网络(例如wire
)。
答案 1 :(得分:1)
添加以下修改:
您在assign语句中使用了test_output1
,因此它应该是wire类型。
module test1(
input wire ACLK,
input wire RST,
output wire test_output1,
output reg test_output2
);
您已将test_output1
和test_outpu2
声明为输出,它是默认类型为wire ,因此您只需隐式指定wire或reg依据使用,
// reg test_output1;
// reg test_output2;