使用环境:QUARTus II 7.2 SP3 + ModelSim-ALTEra 6.1g
本篇使用上升沿检测电路(posedge detection circuit),并加上testbench搭配ModelSim-Altera做模拟。
Step 1:
posedge_detection_tb.v / Verilog
1 /*
2 (C) OOMusou 2008
3
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 */
9
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中的波形
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
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无法自己抓到,必须自己填。
Step 4:
编译并模拟
Processing -> Start Compilation
本文关键字:暂无联系方式电脑-单片机-自动控制,电子学习 - 基础知识 - 电脑-单片机-自动控制