如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim)
源自於
Abstract在Quartus II雖然可以用Vector Waveform的方式作電路模擬,不過這僅限於簡單的模擬,該如何用ModelSim-Altera配合testbench來做較複雜的電路模擬呢?
Introduction
使用環境:Quartus II 7.2 SP3 + ModelSim-Altera 6.1g
使用環境:Quartus II 7.2 SP3 + ModelSim-Altera 6.1g
在(筆記) 如何設計邊緣檢測電路? (SOC) (Verilog),我們使用了Quartus II內建的vector waveform來模擬,可以使用GUI介面來指定波形,非常方便,對於小電路來說,這種拖拖拉拉的方式還算順手,但大電路還是得靠Verilog來寫testbench,然後配合ModelSim做模擬。本篇使用(筆記) 如何設計邊緣檢測電路? (SOC) (Verilog)的上升沿檢測電路(posedge detection circuit),並加上testbench搭配ModelSim-Altera做模擬。
Step 1:
posedge_detection_tb.v / Verilog
posedge_detection_tb.v / Verilog
1 /* 2 (C) OOMusou 2008 http://oomusou.cnblogs.com
3
4 Filename : posedge_detection_tb.v5 Compiler : ModelSim-Altera 6.1g6 Description : testbench of posedge_detection.v7 Release : 07/09/2008 1.08 */
9
10 `timescale 1ns/10ps11 module posedge_detection_tb;12
13 reg clk;14 reg rst_n;15 reg i_data_in;16 wire o_rising_edge;17
18 posedge_detection u0 (19 .clk(clk),20 .rst_n(rst_n),21 .i_data_in(i_data_in),22 .o_rising_edge(o_rising_edge)23 );24
25 parameter clkper = 100;26 initial begin27 clk = 1'b0;
28 end29
30 always begin31 #(clkper / 2) clk = ~clk;32 end33
34 initial begin35 rst_n = 1'b1;
36 i_data_in = 1'b0;
37 38 #75;39 i_data_in = 1'b1;
40 41 #100;42 i_data_in = 1'b0;
43 44 #125;45 i_data_in = 1'b1;
46 47 #75;48 i_data_in = 1'b0;
49 50 #175;51 i_data_in = 1'b1;
52 53 #25;54 i_data_in = 1'b0;
55 end56
57 endmodule
3
4 Filename : posedge_detection_tb.v5 Compiler : ModelSim-Altera 6.1g6 Description : testbench of posedge_detection.v7 Release : 07/09/2008 1.08 */
9
10 `timescale 1ns/10ps11 module posedge_detection_tb;12
13 reg clk;14 reg rst_n;15 reg i_data_in;16 wire o_rising_edge;17
18 posedge_detection u0 (19 .clk(clk),20 .rst_n(rst_n),21 .i_data_in(i_data_in),22 .o_rising_edge(o_rising_edge)23 );24
25 parameter clkper = 100;26 initial begin27 clk = 1'b0;
28 end29
30 always begin31 #(clkper / 2) clk = ~clk;32 end33
34 initial begin35 rst_n = 1'b1;
36 i_data_in = 1'b0;
37 38 #75;39 i_data_in = 1'b1;
40 41 #100;42 i_data_in = 1'b0;
43 44 #125;45 i_data_in = 1'b1;
46 47 #75;48 i_data_in = 1'b0;
49 50 #175;51 i_data_in = 1'b1;
52 53 #25;54 i_data_in = 1'b0;
55 end56
57 endmodule
使用testbench描述出如下在vector waveform中的波形
Step 2:
設定Quartus II使用ModelSim-Altera模擬
設定Quartus II使用ModelSim-Altera模擬
Assignments -> Settings -> Category :EDA Tool Settings -> Simulation:
Tool name:ModelSim-Altera
選取Run gate-level simulation automatically after compilation
Format for output netlist:Verilog
Time scale:1 us
Tool name:ModelSim-Altera
選取Run gate-level simulation automatically after compilation
Format for output netlist:Verilog
Time scale:1 us
Step 3:
設定testbench
設定testbench
在同一頁的NativeLink settings選擇Compile test bench,按下TestBenches..加入posedge_detection_tb.v。比較詭異的是,Test bench name、Top level module in test bench與Design instance name in test bench無法自己抓到,必須自己填。
Step 4:
編譯並模擬
編譯並模擬
Processing -> Start Compilation
沒有留言:
張貼留言