2012-04-02 73 views
4

,如下:連接模塊輸出到我曾嘗試連接模塊輸出到寄存器寄存器

module test 
(
    input rst_n, 
    input clk, 
    output reg [7:0] count 
); 
    always @(posedge clk or negedge rst_n) begin 
    if(!rst_n) begin 
     count <= 7'h0; 
    end else begin 
     if(count == 8) begin 
     count <= count; 
     end else begin 
     count <= count + 1'b1; 
     end 
    end 
    end 
endmodule 

module test_tb; 
    reg clk; 
    reg rst_n; 
    reg [7:0] counter; 

    initial begin 
     clk = 1'b0; 
     rst_n = 1'b0; 
     # 10; 
     rst_n = 1'b1; 
    end 
    always begin 
     #20 clk <= ~clk; 
    end 

    test test1 (
     .rst_n(rst_n), 
     .clk(clk), 
     .count(counter) /* This is the problematic line! */ 
    ); 
endmodule 

我在的ModelSim錯誤「Illegal output or inout port connection for "port 'count'」。即使錯誤與我的代碼相匹配,但我不明白爲什麼從根本上說,我無法將模塊輸出連接到寄存器。

爲什麼我不能在Verilog中將模塊輸出連接到寄存器?

回答

6

您只能在程序always區塊內爲reg賦值。您不能從模塊實例驅動reg。這將是一個連續 assisgnment。

test_tb內使用wire