如何使用Debussy与ModelSim做Co-Simulation

如题所述

第1个回答  2014-12-31
本文介绍如何使用Debussy与ModelSim做Co-Simulation,并使用Verilog、VHDL以及Verilog搭配VHDL交叉一起simulation。
Introduction
使用环境:Debussy 5.4 v9 + ModelSim SE 6.3e
我之前一直使用Debussy + NC-Verilog做simulation,Debussy (Verdi)可以说是HDL的Source Insight,是trace与debug的神兵利器,NC-Verilog也是Verilog simulator中速度最快的,可是最近因工作需要,拿到的一包code却是用Verilog写RTL,用VHDL写testbench,所以必须2种语言一起做simulation,我在NC-Verilog一直无法成功让两种语言一起simulation。ModelSim虽然支援Verilog + VHDL co-simulation,但用惯Debussy的我还是无法忘怀其方便的trace code方式,所以若能让ModelSim也能dump出Debussy所需要的fsdb档案,这样就太完美了。
接下来会分4个方式讨论
1.RTL与testbench皆使用Verilog
2.RTL与testbench皆使用VHDL
3.RTL使用VHDL,testbench使用Verilog
4.RTL使用Verilog,testbench使用VHDL
1.RTL与testbench皆使用Verilog
Step 1:
设定ModeSim使用Verilog PLI (因为testbench使用Verilog)
将C:\Novas\Debussy\share\PLI\modelsim_pli\WINNT\novas.dll复制到C:\Modeltech_6.3e\win32\下
修改C:\Modeltech_6.3e\modelsim.ini,将Veriuser部分修改成如下所示:
; List of dynamically loaded objects for Verilog PLI applications
; Veriuser = veriuser.sl
; use by verilog
Veriuser = novas.dll
; use by vhdl
; Veriuser = novas_fli.dll

modelsim.ini是个read only档,要修改前记得修改其属性才能存档。
Step 2:
RTL部分 (以4 bit counter为例)
counter.v / Verilog

1 /*
2 (C) OOMusou 2011 http://oomusou.cnblogs.com
3
4 Filename : counter.v
5 Simulator : ModelSim 6.3e, Debussy 5.4 v9
6 Description : ModelSim with debussy
7 Release : 01/31/2010 1.0
8 */
9
10 module counter (
11 clk,
12 rst_n,
13 cnt
14 );
15
16 input clk;
17 input rst_n;
18 output [3:0] cnt;
19
20 reg [3:0] cnt;
21
22 always@(posedge clk, negedge rst_n) begin
23 if (~rst_n)
24 cnt <= 4'h0;
25 else
26 cnt <= cnt + 1'b1;
27 end
28
29 endmodule

Step 3:
Testbench部分
counter_tb.v / Verilog

1 /*
2 (C) OOMusou 2011 http://oomusou.cnblogs.com
3
4 Filename : counter_tb.v
5 Compiler : ModelSim 6.3e, Debussy 5.4 v9
6 Description : ModelSim with debussy
7 Release : 01/31/2010 1.0
8 */
9
10 module counter_tb;
11
12 reg clk;
13 reg rst_n;
14 wire [3:0] cnt;
15
16 // 50MHz
17 always #(10) clk = ~clk;
18
19 initial begin
20 #0;
21 clk = 1'b0;
22 rst_n = 1'b0;
23
24 #5;
25 rst_n = 1'b1;
26 #195;
27 $finish;
28 end
29
30 initial begin
31 $fsdbDumpfile("counter.fsdb");
32 $fsdbDumpvars(0, counter_tb);
33 end
34
35 counter u_counter (
36 .clk(clk),
37 .rst_n(rst_n),
38 .cnt(cnt)
39 );
40
41 endmodule

19行

initial begin
#0;
clk = 1'b0;
rst_n = 1'b0;

#5;
rst_n = 1'b1;

#195;
$finish;
end

一搬来说,若在NC-Verilog做simulation,我们会在testbench内指定结束simulation的时间,不过在ModelSim里,simulation时间是由ModelSim script控制,在testbench内写$finish并没有用,所以会省略$finish时间入下。

initial begin
#0;
clk = 1'b0;
rst_n = 1'b0;

#5;
rst_n = 1'b1;
end

Step 4:
ModelSim script部分
vsim.do
vlib work
vlog counter.v
vlog counter_tb.v
vsim counter_tb
run 200ns
q
其中
vlib work

建立work library。
vlog counter.v
vlog counter_tb.v
编译RTL:counter.v 与 testbench:counter_tb.v,vlog为modelsim的Verilog compiler。
vsim counter_tb

以counter_tb为top module进行simulation。
run 200ns

命令ModelSim执行200 ns的simulation。
q

离开ModelSim
Step 5:
执行ModelSim的批次档
mod.bat
vsim -c -do sim.do

-c 表示ModelSim将以console mode执行,因为在Debussy + ModelSim时,只把ModelSim当成NC-Verilog使用,并没有用到ModelSim的GUI模式。
-do 表示执行ModelSim script。
执行结果

D:\0Clare\VerilogLab\ModelSim\counter_verilog>vsim -c -do sim.do
Reading C:/Modeltech_6.3e/tcl/vsim/pref.tcl

# 6.3e

# do sim.do
# ** Warning: (vlib-34) Library already exists at "work".
# Model Technology ModelSim SE vlog 6.3e Compiler 2008.02 Feb 2 2008
# -- Compiling module counter
#
# Top level modules:
# counter
# Model Technology ModelSim SE vlog 6.3e Compiler 2008.02 Feb 2 2008
# -- Compiling module counter_tb
#
# Top level modules:
# counter_tb
# vsim counter_tb
# ** Note: (vsim-3813) Design is being optimized due to module recompilation...
# ** Note: (vsim-3865) Due to PLI being present, full design access is being specified.
# Loading C:\Modeltech_6.3e\win32/novas.dll
# // ModelSim SE 6.3e Feb 2 2008
# //
# // Copyright 1991-2008 Mentor Graphics Corporation
# // All Rights Reserved.
# //
# // THIS WORK CONTAINS TRADE SECRET AND
# // PROPRIETARY INFORMATION WHICH IS THE PROPERTY
# // OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS
# // AND IS SUBJECT TO LICENSE TERMS.
# //
# Loading work.counter_tb(fast)
# Loading work.counter(fast)
# Novas FSDB Dumper for ModelSim, Release 5.4v9 (Win95/NT) 05/04/2005
# Copyright (C) 1996 - 2004 by Novas Software, Inc.
# *Novas* Create FSDB file 'counter.fsdb'
# *Novas* Start dumping the scope(counter_tb), layer(0).
# *Novas* End of dumping.
# ** Note: $finish : counter_tb.v(27)
# Time: 200 ns Iteration: 0 Instance: /counter_tb

转载仅供参考,版权属于原作者。祝你愉快,满意请采纳哦
相似回答