2013-06-20 21 views
-1

我寫了一個簡單的測試臺和門。我的代碼和測試工作正常。現在我想要做的是「我試圖爲我的案例實施一個while循環」。我沒有得到語法錯誤,但沒有看到任何輸出。任何人都可以告訴我的錯誤嗎?在測試臺和門的循環。沒有輸出

timescale 1ns/100ps 


int count=0; 
module and_gate_test; 

    // Inputs 
    reg in1_t; 
    reg in2_t; 

    // Outputs 
    wire out_t; 

    // Instantiate the Unit Under Test (UUT) 
    and_gate and_gate_1 (in1_t,in2_t,out_t); 


    initial 
    begin 
     // Initialize Inputs 
     //case 0 
     while(count==100){ 
     in1_t <= 0; 
     in2_t <= 0; 
     #1 $display ("out_t=%b",out_t); 
       //case 1 
     in1_t <= 1; 
     in2_t <= 1; 
     #1 $display ("out_t=%b",out_t); 

     //case2 
     in1_t <= 0; 
     in2_t <= 1; 
     #1 $display ("out_t=%b",out_t); 

     //case3 
     in1_t <= 1; 
     in2_t <= 0; 
     #1 $display ("out_t=%b",out_t); 

     count++; } 
     // Add stimulus here 

    end 

endmodule 
+0

可能更適合http://electronics.stackexchange.com(記住,Verilog的是硬件合成語言,而不是一種編程語言)。 [更多信息](http://meta.stackexchange.com/questions/90472/how-far-am--allowed-to-take-verilog-and-vhdl-questions)。 –

+2

@JonathonReinhart是正確的,你也可以在[electonicsSE](http://electronics.stackexchange.com/)上得到很好的答案,但HDL問題往往會在這裏得到很好的答案。 – Morgan

回答

-1

while(count == 100)?!

[........ 8 more chars]。

+0

@downvoter:不是我在乎,但你大概沒有注意到我給出了21個字的正確答案,然後有人走了過來,並在半小時後在165個字符中說了同樣的話。他們爲此獲得了兩項讚譽。 – EML

2

嘿,我想你可能想

while(count <= 100) 

你從來沒有進入while循環,因爲你是從零開始因此

while(count==100) 

從不計算真正

+0

是的,那是因爲我嘗試了所有可能的組合。它並不適用while(count <= 100)。我認爲我們需要添加數學庫來完成count ++或爲while循環添加庫。沒有任何想法。 – user2312332

+0

你應該做count = count +1 另外,我會建議使用阻塞任務「=」,而不是非阻塞在這裏「<=」這是有很多原因,如果你想進一步閱讀在cumming的論文「殺死verilog風格」 –

1

while循環Alex Rellim說,你永遠不會執行你使用的計數,因爲計數永遠不會等於100。它應該像

while(count<=100)

和也算++不會Verilog的工作。使用

count = count + 1

,而不是數++。

而while循環應該有開始和結束,而不是花括號。

1

兩個問題:

  1. 咖喱括號(EI {}),用於while循環需要由beginend分別
    • 模擬器來替換有一個錯誤,如果它不產生語法錯誤和當前代碼不符合Verilog或SystemVerilog允許的用法。

  2. int count=0;需要在模塊
    • 內:int是SystemVerilog的。如果要嚴格遵循IEEE標準1364,則使用integer.如果要使用IEEE Std 1800,則int是正確的。int默認爲32'd0,而integer默認爲32'dX

  3. while(count==100)如果使用==則由於count作爲零初始化整個循環將被跳過應while(count<=100)while(count<100)
    • 替代解決方案爲一個循環:使用 的for(integer count=0; count<100; count++)代替while(count<100)