Xilinx ISE14.1用Verilog語言實現一個半加器並測試


<一>建立一個工程

      注:Xilinx ISE的安裝在此不再過多說明,網上有參考資料

1.打開軟件進入如下界面

 

2.創建工程

File-->New Project

 

 3.創建文件(我取名為firstTry)

右鍵選擇New Source;

設置參數

 

4.編寫代碼

module half_add(     input a,     input b,     output sum,     output cout     );

           assign sum = a^b;

           assign cout = a&b;

endmodule

5.測試代碼

選擇項目並且右鍵(New Source)

 

測試代碼如下:

module half_addtest;

 // Inputs

 reg a;  

reg b;

 // Outputs  

wire sum;  

wire cout;

 // Instantiate the Unit Under Test (UUT)  

half_add uut (   .a(a),   .b(b),   .sum(sum),   .cout(cout)  );

 initial begin  

 // Initialize Inputs   

a = 0;  

b = 0;

  // Wait 100 ns for global reset to finish   

//#100; 這句最好暫時不用          

// Add stimulus here      

#0.001 a = ~a;   

#0.001 b = ~b;   

#0.001 a = ~a;  

 #0.001 b = ~b;   

#0.001 a = ~a;   

#0.001 b = ~b;   

#0.001 a = ~a;   

#0.001 b = ~b;   

 end      

endmodule

測試步驟:

 

6.測試代碼分析

#0.001 a = ~a;   

注意:#N中的N是以ns為單位的,而在測試截圖中的時間單位是ps,其中 1ns = 1000 ps;

說到這里也知道測試代碼中的#100為什么不要了的原因

這句話2就是從執行這句代碼起,等待0.001ns后a取反,然后結合測試截圖就可以理解了。

7.生成頂層文件

雙擊Synthesize中的View RTL Schematic 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM