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



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...