2020年2月27日 星期四

Quartus II 與 ModelSim 使用方法 Verilog 邏輯閘層次 Gate Level 基本邏輯閘 實際範例

Quartus II 與 ModelSim 使用方法 Verilog 邏輯閘層次 Gate Level 基本邏輯閘 (2)

實際範例

一位元全加器 
程式碼:
module Full_Adder( A, B, Cin, Sum, Cout );

    input A, B, Cin;
    output Sum, Cout;

    wire W1, W2, W3;

    xor xor1( W1, A, B );
    and and1( W2, W1, Cin );
    and and2( W3, A, B );
    xor xor2( Sum, W1, Cin );
    or  or1( Cout, W2, W3 );

endmodule

1) 程式碼與測試平台程式碼
//========================
module basic_gate( A, B, Cin, Sum, Cout );

    input A, B, Cin;
    output Sum, Cout;

    wire W1, W2, W3;

    xor xor1( W1, A, B );
    and and1( W2, W1, Cin );
    and and2( W3, A, B );
    xor xor2( Sum, W1, Cin );
    or  or1( Cout, W2, W3 );

endmodule

// 時間單位 100ns, 時間精確度10 ps `timescale 100ns/10ps module Test_bench; // input A, B, Cin; // output Sum, Cout; wire Sum, Cout; reg A=1'b0; reg B=1'b0; reg Cin=1'b0; basic_gate DUT ( .A(A), .B(B), .Cin(Cin), .Sum(Sum), .Cout(Cout) ); // initial程序結構區塊, 產生A、B輸入信號波形 initial begin $monitor( A, B, Cin, Sum, Cout ); #100; // 100ns A=1'b0; B=1'b0 ; Cin=1'b1 ; // “001” #100; // 200ns A=1'b0 ; B=1'b1 ; Cin=1'b0 ; // “010” #100; // 300ns A=1'b0 ; B=1'b1 ; Cin=1'b1 ; // “011" #100; // 400ns A=1'b1 ; B=1'b0 ; Cin=1'b0 ; // “100" #100; // 500ns A=1'b1 ; B=1'b0 ; Cin=1'b1 ; // “101" #100; // 600ns A=1'b1 ; B=1'b1 ; Cin=1'b0 ; // “110" #100; // 700ns A=1'b1 ; B=1'b1 ; Cin=1'b1 ; // “111" end initial begin #800; // 模擬終止時間 400 ns $stop; end endmodule






Modelsim-Altera的設定  Tools -> Option



沒有留言:

張貼留言

習題解答 (5/6)

  第五章 習題解答 一、 錯誤偵測技術 1. 何謂循環冗餘檢查法 (CRC)? 是一種根據傳輸資料產生簡短固定位數校驗碼的演算法。發送端將資料除以一個特定的多項式,得到的「餘數」即為 CRC 碼並隨資料發送;接收端以同樣多項式除之,若餘數為 0 則代表資料傳輸正確。 2. 何...