2016-05-13 41 views
1

我想实现如下简单的Verilog代码:为什么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 

我收到以下错误消息时我尝试合成它的赛灵思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` 

我无法解决这个错误。任何帮助将不胜感激。

+1

test_output1已被声明为寄存器和导线。 – vim

回答

1

添加以下修改:

  1. 您在赋值语句中使用test_output1所以它应该是类型的线。

    module test1(
        input wire ACLK, 
        input wire RST, 
        output wire test_output1, 
        output reg test_output2 
    ); 
    
  2. 你已经宣布test_output1test_outpu2作为输出,它是由默认类型导线的,所以你只需要隐含指定线或根据使用章,

    // reg test_output1; 
    // reg test_output2; 
    
3

如果声明端口列表中的端口方向,则还必须声明该类型。这被称为ANSI风格的标题。

还有一个非ANSI风格的标题,用于分隔portlist,方向和类型。如果您正在使用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,你不能驾驶regassign声明,它必须是一个网式。 IEEE1800已经软化了重新开始的规则logic而不是reg,但是一般如果你打算使用assign那么你应该分配一个网络(例如wire)。

相关问题