Abstract
在Quartus II雖然可以用Vector Waveform的方式作電路模擬,不過這僅限於簡單的模擬,該如何用ModelSim-Altera配合testbench來做較複雜的電路模擬呢?

Introduction
使用環境:Quartus II 7.2 SP3 + ModelSim-Altera 6.1g

我們使用了Quartus II內建的vector waveform來模擬,可以使用GUI介面來指定波形,非常方便,對於小電路來說,這種拖拖拉拉的方式還算順手,但大電路還是得靠Verilog來寫testbench,然後配合ModelSim做模擬。本篇使用​​​​的上升沿檢測電路(posedge detection circuit),並加上testbench搭配ModelSim-Altera做模擬。

Step 1:
posedge_detection_tb.v / Verilog

1 /* 

2 (C) OOMusou 2008 http://oomusou.cnblogs.com

4 Filename    : posedge_detection_tb.v

5 Compiler    : ModelSim-Altera 6.1g

6 Description : testbench of posedge_detection.v

7 Release     : 07/09/2008 1.0

8 */

10 `timescale 1ns/10ps

11 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 begin

27   clk = 1'b0;

28 end

29 

30 always begin

31   #(clkper / 2) clk = ~clk;

32 end

33 

34 initial begin

35   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 end

56 

57 endmodule

使用testbench描述出如下在vector waveform中的波形

(原創) 如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim)_上升沿

Step 2:
設定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

(原創) 如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim)_d3_02

Step 3:
設定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無法自己抓到,必須自己填。

(原創) 如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim)_sed_03

(原創) 如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim)_上升沿_04

Step 4:
編譯並模擬

Processing -> Start Compilation

(原創) 如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim)_上升沿_05

See Also