NCVerilog设计秘诀与点评
每天多学一点:Verilog编写技巧(一)

每天多学一点:Verilog编写技巧(一)来源:网路素材好的设计者一般都要对电路要实现的功能有清晰的认识,对数据流很清楚,知道数据如何从一个点移动到另一个点,这就是所谓的“勾划”(walk-through)。
一旦设计蓝图在脑海中变得清晰,此后釆用Verilog编写数据路径和控制逻辑就会变得思路清晰。
脑海中的模拟正如大多数人玩过的象棋游戏,我们都知道提前谋划是何等重要,要在下一次移动棋子之前考虑好此后的几步棋应该怎么走,以确保不会出错,不被对手捕捉到机会。
电路设计过程与下棋非常相似。
当设计状态机、数据路径或者控制逻辑时,我们知道它们的功能。
在进行设计仿真之前,我们需要思考代码在不同输入和边界条件下如何工作。
如果用心去做好这一步工作,并且分析可能出现的问题,验证工作将会变得非常高效。
另外,这一步也给我们建立了自信,使我们确信整个设计非常扎实,可以很好地工作。
否则很可能出现的情况是在验证阶段反复发现问题并进行电路修改,不断进行补救T.作,并且最终也不能确定设计足否还隐含着没有被发现的问题。
哪种风格—数据流或算法描述组合逻辑有两种方式—使用wire(对应数据流描述方式)或者使用reg(对应算法描述方式)。
这两种方式都能实现相同的逻辑功能,综合后得到相同的门电路,具体使用哪一种方式可以根据个人喜好。
数据流—短表达式举例wire [7:0] regl0_nxt;assign regl0_nxt = wren ? data_in : regl0;算法—短表达式举例reg [7:0] regl0_nxt;always @(*) beginreglO_nxt = reglO;if (wren)regl0_nxt = data_in;end当表达式非常简单时,一般更倾向于使用数据流风格来实现,此时代码行数很少。
然而,当表达式很长并且与很多条件有关时,数据流风格阅读起来较为费力。
此时可以使用算法风格,可以采用if-else 语句进行描述,以易于阅读和减少错误发生。
数字设计中的Verilog语法调整技巧

数字设计中的Verilog语法调整技巧数字设计是现代电子领域中的重要技术之一,Verilog作为一种硬件描述语言,在数字设计中扮演着至关重要的角色。
Verilog语法的准确使用和调整是数字设计过程中的关键一环,下面将从几个方面介绍数字设计中的Verilog语法调整技巧。
首先,在编写Verilog代码时,合理的模块化设计是至关重要的。
通过将整个设计划分为多个模块,可以提高代码的复用性和可维护性。
在模块化设计中,可以使用模块实例化的方式来调用其他模块进行功能实现。
此外,在模块内部也可以进一步进行代码块的划分,提高代码的清晰度和可读性。
其次,对于Verilog语法中的信号赋值,需要合理地选择适合的赋值方式。
在Verilog中,有非阻塞赋值和阻塞赋值两种方式。
对于时序逻辑的描述,通常使用非阻塞赋值,以保证设计在时钟信号的作用下按时序执行;而对于组合逻辑的描述,通常使用阻塞赋值。
正确选择赋值方式可以有效避免由于信号赋值顺序导致的逻辑错误。
另外,在Verilog语法中,对于always块的使用也需要注意一些技巧。
always块是描述Verilog代码的执行顺序的重要部分,其中的敏感列表决定了代码块的执行触发条件。
在编写always块时,需要确保敏感列表中覆盖了所有的输入信号,以避免遗漏导致的逻辑错误。
另外,在时序逻辑设计中,需要使用posedge(上升沿触发)或negedge(下降沿触发)来确保时钟信号的正确触发。
此外,当涉及到多位宽信号的处理时,需要注意Verilog语法中的位操作技巧。
Verilog中提供了丰富的位操作符号,如与(&)、或(|)、异或(^)等,可以方便地实现多位宽信号的逻辑运算。
同时,也可以通过拼接符号{ }来对多位宽信号进行连接或分割,非常适合处理复杂的数据结构。
最后,在Verilog代码的调试和优化过程中,合理利用仿真工具是至关重要的。
通过仿真工具可以实时观察信号波形,验证代码的正确性和功能实现情况。
Verilog 学习经验

在逻辑方面,我觉得比较重要的规范有这些:1.设计必须文档化。
要将设计思路,详细实现等写入文档,然后经过严格评审通过后才能进行下一步的工作。
这样做乍看起来很花时间,但是从整个项目过程来看,绝对要比一上来就写代码要节约时间,且这种做法可以使项目处于可控、可实现的状态。
2.代码规范。
a.设计要参数化。
比如一开始的设计时钟周期是30ns,复位周期是5个时钟周期,我们可以这么写:parameter CLK_PERIOD = 30;parameter RST_MUL_TIME = 5;parameter RST_TIME = RST_MUL_TIME * CLK_PERIOD;...rst_n = 1'b0;# RST_TIME rst_n = 1'b1;...# CLK_PERIOD/2 clk <= ~clk;如果在另一个设计中的时钟是40ns,复位周期不变,我们只需对CLK_PERIOD进行重新例化就行了,从而使得代码更加易于重用。
b.信号命名要规范化。
1) 信号名一律小写,参数用大写。
2) 对于低电平有效的信号结尾要用_n标记,如rst_n。
3) 端口信号排列要统一,一个信号只占一行,最好按输入输出及从哪个模块来到哪个模块去的关系排列,这样在后期仿真验证找错时后方便很多。
如:module a(//inputclk,rst_n, //globle signalwren,rden,avalon_din, //related to avalon bussdi, //related to serial port input//outputdata_ready,avalon_dout, //related to avalon bus...);4) 一个模块尽量只用一个时钟,这里的一个模块是指一个module或者是一个entity。
在多时钟域的设计中涉及到跨时钟域的设计中最好有专门一个模块做时钟域的隔离。
Verilog设计小技巧

Verilog(FPGA/CPLD)设计小技巧(来自Xilinx)这是一个在设计中常犯的错误列表这些错误常使得你的设计不可靠或速度较慢为了提高你的设计性能和提高速度的可靠性你必须确定你的设计通过所有的这些检查可靠性**为时钟信号选用全局时钟缓冲器BUFG• 不选用全局时钟缓冲器的时钟将会引入偏差 。
**只用一个时钟沿来寄存数据• 使用时钟的两个沿是不可靠的因为时钟的某沿或者两个沿会漂移; 如果时钟有漂移而且你只使用了时钟的一个沿你就降低了时钟边沿漂移的风险。
• 这个问题可以这样来解决就是允许CLKDLL自动纠正时钟的占空比以达百分之五十的占空比否则强烈建议你只使用一个时钟沿**除了用CLKDLL或DCM产生的时钟外不要在内部产生时钟.• 这包括产生门控时钟和分频时钟• 作为替代可以建立时钟使能或使用CLKDLL或DCM来产生不同的时钟信号。
• 对于一个纯同步设计建议你在任何可能的情况下只使用一个时钟**不要在内部产生异步的控制信号 例如复位信号或者置位信号• 内部产生的异步控制信号会产生毛刺• 作为替代可以产生一个同步的复位/置位信号这个信号的译码要比需要作用的时刻提前一个时钟周期**不要使用没有相位关系的多个时钟• 你也许并不总能避免这个条件在这些情况下确定你已使用了适当的同步电路来跨越时钟域**不要使用没有相位关系的多个时钟• 再次你也许并不总能避免这个条件相反许多设计都需要这样在这 些情况下确定你已适当地约束了跨越时钟域的路径**不要使用内部锁存器• 内部锁存器会混淆时序而且常常会引入另外的时钟信号• 内部锁存器在透明门打开时可以被看成是组合逻辑但在门被锁存时 可以被看成是同步元件这将会混淆时序分析• 内部锁存器常常会引入门控时钟门控时钟会产生毛刺使得设计变得不可靠性能**逻辑级的时延不要超过时序预算的百分之五十• 每个路径逻辑级时延可以在逻辑级时序报告或布局后时序报告中找到详细分析了每个路径之后时序分析器将生成每个路径时延的统计量检查一下总共的逻辑级时延超过了你的时序预算的百分之五十吗?**IOB 寄存器• IOB寄存器提供了最快的时钟到输出和输入到时钟的时延• 首先有一些限制对于输入寄存器在从管脚到寄存器间不能有组合逻 辑存在对于输出寄存器在寄存器和管脚之间也不能有组合逻辑存在对于三态输出在IOB 中的所有的寄存器必须使用同一个时钟信号和复位信号而且IOB三态寄存器必须低电平有效才能放到IOB中三态缓冲器低电平有效所以在寄存器和三态缓冲器之间不需要一个反相器• 你必须使软件能够选用IOB寄存器你可以设置全局实现选项为输入 输出或输入输出选择IOB寄存器缺省值为关(off)。
数字设计中的Verilog编程技巧

数字设计中的Verilog编程技巧在数字设计中,Verilog是一种常用的硬件描述语言,广泛应用于数字集成电路设计和仿真中。
Verilog编程技巧对于提高设计效率、优化性能和减少错误至关重要。
下面我将介绍几种Verilog编程技巧,帮助您更好地应用Verilog进行数字设计。
首先,合理使用模块化设计。
在Verilog中,模块是设计的基本单元,将复杂系统划分为多个模块可以提高可维护性和复用性。
因此,在设计过程中应该遵循模块化设计原则,将功能模块化、分层和相互独立。
其次,正确使用参数化。
在Verilog中,参数化是指通过参数来描述模块或信号的行为。
合理使用参数可以提高代码的灵活性和可复用性。
通过定义参数,可以轻松地调整模块的行为,使得代码更加通用和易扩展。
此外,熟练掌握Verilog中的时序控制。
时序控制是Verilog设计中的关键部分,用于描述时序逻辑和时序行为。
在设计过程中,需要注意时钟的约束和时序分析,确保设计的正确性和稳定性。
可以使用时钟域划分、时钟同步等技术来解决时序问题。
另外,注意Verilog中的模拟和仿真。
在数字设计中,模拟和仿真是验证设计正确性的重要步骤。
Verilog提供了Simulator工具,可以进行行为级仿真和波形仿真。
通过模拟和仿真可以验证设计是否符合预期,发现和修复设计中的问题。
最后,关注Verilog中的调试和优化。
在设计过程中,经常需要进行调试和优化,以确保设计满足性能和功耗要求。
Verilog提供了一些调试和优化技术,如添加断点、查看波形、进行逻辑分析等。
通过调试和优化可以找到设计中的问题,并对设计进行改进。
总的来说,Verilog编程技巧对于数字设计至关重要。
通过合理的模块化设计、参数化、时序控制、模拟和仿真、调试和优化,可以提高设计效率、优化性能和减少错误。
希望以上介绍的Verilog编程技巧能够帮助您在数字设计中取得更好的结果。
祝您在Verilog编程中取得成功!。
一个新手的verilog学习经验分享

一个新手的verilog学习经验分享来源:网络素材我学verilog语言进行FPGA设计也就半年时间,很多的东西就是在网上学到的,现在想说说自己对使用verilog进行FPGA设计的一些体会,我水平不高,主要是为新手朋友们介绍自己的一点经验少走点弯路。
1、verilog语言学习verilog最重要的不是语法,“因为10%的语法就能完成90%的工作”,verilog语言常用语言就是always@(),if~else,case,assign这几个了,不用去专研繁杂的语法,有些问题等你碰到了查查书就好了。
这里推荐夏雨闻老师的《verilog数字系统设计教程》,一本很适合新手的好书。
2、硬件原则虽然verilog语言很象c语言,但它和c语言还是有本质的区别的,因为verilog进行的是硬件设计,你写出来的东西是实实在在电路,所以要有数字电路的知识是肯定的。
数字电路就是由时序电路(触发器)和组合逻辑电路(各种逻辑门)构成的,用verilog写的程序在FPGA实现就是触发器和逻辑门,所以最重要的就是“你对你写的语言生成的电路心中有数”,做到这一点你就不会有写出来的程序不能综合的麻烦,电路的冗余逻辑肯定也是最少的。
还要注意一点就是verilog程序是并行的,不是象c那样是顺序执行的,这是因为fpga硬件可配置,可形成不同的任务单元同时工作;而单片机这种基于通用目的,硬件结构也固定了,它处理任务只能一件一件顺序的进行。
3、同步原则在进行FPGA设计的时候,同步原则应该是最重要的原则之一了,因为异步电路的不可控性,很可能有毛刺产生,而在芯片内部的任何一点毛刺都会一级一级的传递下去,最终影响系统的稳定性。
同步原则用一句话来总结就是“不要试图产生自己的时钟”,最好一个设计或者一个模块只使用同一个时钟,这样所有的触发器都在同一个时钟沿跳变,当然最稳定了,系统也能跑到很高的速度。
一个小技巧就是多使用触发器的使能端和取沿电路。
Verilog语言设计归纳总结

使用Verilog语言进行FPGA设计的总结1.在使用case或casex结构进行同步状态机构建时,最后一定要有default状态,在这个状态中主要设计的是纠错程序,这个非常重要,通过这个状态可以把状态机因状态位错误而进入无效或错误的状态中拉回来,或跳出这次操作强制进入下一次操作的初始状态。
2.在使用else-else if ……-else结构时,各个条件之间必须完全是明确地互斥,任何两条件在任何时候都必须不能同时满足。
这个很重要,此重要性,虽在仿真阶段没什么大问题,但当综合成门电路以后在现实的硬件上进行运行时,就会暴露出很多缺陷,影响稳定性问题以及兼容性问题。
3.①在进行同步时序逻辑设计时,对由其他非主时钟信号沿触发的事件,采用信号沿跟踪寄存器,来及时判断沿的发生,当然这样会产生误差,最大会有一个主时钟周期;②判断沿发生的另一种方法是,使用主时钟发生两个一个周期相同的时钟信号,第二个时钟要落后于第一个时钟一个周期,当第一个时钟为高而第一个时钟为低时,说明在此之前第一个时钟有一个上升沿,第二种方法依然会有一个主时钟周期的误差。
4.在把测试模块包括在内的顶层模块的编写中,需要使用“include”来把各个子模块包含进来(被包含的文件名要写完全路径),不需要有输入输出端口列表,也不需要在模块中使用input和output进行声明,但在模块中,必须对需要引用的下层模块的输入输出变量进行声明,不管输入还是输出变量都声明成wire类型,如果不声明则均默认成位宽为1位的变量;在不包括测试模块的顶层模块中,要有输入输出列表,把所有子模块的对外输入输出在列表中体现,并且使用input和output进行声明,其中output也必须默认成wire类型的,而子模块间的输入输出变量使用wire进行一下声明就可以了,但必须要有。
5.在同步状态机设计中,要在前一状态为下一状态的关键变量进行赋值,以使在进入下一状态时,获得稳定的条件。
Ncverilog 命令使用详解

Ncverilog 命令使用详解我们知道,由于NC-Verilog使用了Native Compile Code 的技术来加强电路模拟的效率,因此在进行模拟时必须经过compile(ncvlog 命令)以及elaborate(n celab命令)的步骤。
编译之后,针对每一个HDL设计单元会产生中间表达。
接着elaborate命令会建立整个电路的结构,产生可以用来模拟的资料。
最后使用ncsim命令来进行模拟。
三命令模式命令如下:ncvlog -f run.fncealb tb -access wrcncsim tb -gui第一个命令中,run.f是整个的RTL代码的列表,值得注意的是,我们需要把tb 文件放在首位,这样可以避免出现提示timescale的错误。
第二个命令中,access选项是确定读取文件的权限。
其中的tb是你的tb文件内的模块名字。
第三个命令中,gui选项是加上图形界面值得注意的是,在这种模式下仿真,是用“ - ”的。
而下边要说的ncverilog是采用“ + ”的。
单命令模式ncverilog +access+wrc rtl +gui在这里,各参数与三命令模式相同。
注意“ + ”。
在本文里将详细讲述ncverilog 的各种常用的参数,对于三命令模式,请读者自己查看资料。
+cdslib+... 设定你所仿真的库所在+define+macro ... 预编译宏的设定+errormax+整数当错误大于设定时退出仿真+incdir+path 设定include的路径+linedebug 允许在代码中设定line breakpoint+log+logfile 输出到名为logfile的文件中+status 显示内存和CPU的使用情况+work 工作库+access+w/r/c 读取对象的权限,缺省为无读(-w)无写(-r)无连接(-c)+gui 显示图形交互界面+input script_file 输入脚本文件+licqueque 如无licence等待licence+run 如果在GUI交互界面下, 启动后将自动开始仿真+loadpli1=... 动态加入PLI+timescale 设定仿真单位和精度+nocopyright 不显示版权信息。
第四章、VerilogHDL设计技巧.

第四章、Verilog HDL设计技巧本章通过一些简单的实例演示一下如何在verilog hdl中实现看似不可能实现的技巧,主要包括1.双向端口的使用2.PWM波形的产生3.常见几种分频器的设计4.巧用存储器定义语句实现存储器设计5.基于存储器的DDS设计6.有限状态机本章讲述一些常用的verilog设计方法和技巧,可以加速实际的工程应用,提高效率。
双向端口双向端口在应用过程中常常用到,如在进行和存储器的接口设计时。
由于存储器的数据线是双向信号,故FPGA的端口也必须用双向端口才能够连接。
Verilog HDL中的双向端口关键字为inout,如inout dat,则表示dat为一个双向(既可以输入也可以输出)的端口。
在硬件中为了更好的处理端口,大多数情况下都是使用单向端口,即input或者output。
这样更容易对电路的逻辑进行描述。
双向端口也往往转换成两个单向的端口进行操作。
仔细分析一下,当一个端口作为双向端口时,实际上是分时的输入和输出,也就是说,当内部逻辑需要双向端口作为输入时,这时候是用双向的输入功能,反之,用输出功能。
假设”内部需要”为一个变量,暂且命名为dir,则,双向端口转化为两个单向端口的电路就可以如下图所示。
图中,实线框是整个的逻辑设计电路模块,io为此模块的双向端口。
虚线框为将双向端口转化为两个单向端口的子模块,两个三角形的电路为三态门,上面的三态门低电平使能,下面的三态门高电平使能。
当需要将io端作为输入时候,即dir为高(假设为高电平时使用io 端的输入功能),上面的三态门被关闭,下面的三态门打开,于是信号的流向从io口经过下面的三态门由a端输出,那么这个时候其他逻辑部分就可以使用a端的信号进行运算处理;反之,当内部的其他逻辑需要输出信号至io双向端口时,可以置dir为低电平,上面的三态门被打开,下面的三态门被关闭,这样b端口的信号经由上面的三态门输出至io端。
这样,虚线框中的子模块就完成了双向端口转化为两个独立的单向端口(a和b)的功能。
verilog设计经验浅谈

因为Verilog是一种硬件描述语言,所以在写Verilog语言时,首先要有所要写的module在硬件上如何实现的概念,而不是去想编译器如何去解释这个module. 比如在决定是否使用reg定义时,要问问自己物理上是不是真正存在这个register, 如果是,它的clock是什么? D端是什么?Q端是什么?有没有清零和置位?同步还是异步?再比如上面讨论的三态输出问题,首先想到的应该是在register的输出后面加一个三态门,而不是如何才能让编译器知道要“赋值”给一个信号为三态。
同样,Verilog中没有“编译”的概念,而只有综合的概念。
verilog设计经验浅谈1,敏感变量的描述完备性V erilog中,用always块设计组合逻辑电路时,在赋值表达式右端参与赋值的所有信号都必须在always@(敏感电平列表)中列出,always中if语句的判断表达式必须在敏感电平列表中列出。
如果在赋值表达式右端引用了敏感电平列表中没有列出的信号,在综合时将会为没有列出的信号隐含地产生一个透明锁存器。
这是因为该信号的变化不会立刻引起所赋值的变化,而必须等到敏感电平列表中的某一个信号变化时,它的作用才表现出来,即相当于存在一个透明锁存器,把该信号的变化暂存起来,待敏感电平列表中的某一个信号变化时再起作用,纯组合逻辑电路不可能作到这一点。
综合器会发出警告。
Example1:input a,b,c;reg e,d;always @(a or b or c)begine=d&a&b; /*d没有在敏感电平列表中,d变化时e不会立刻变化,直到a,b,c中某一个变化*/d=e |c;endExample2:input a,b,c;reg e,d;always @(a or b or c or d)begine=d&a&b; /*d在敏感电平列表中,d变化时e立刻变化*/d=e |c;end2, 条件的描述完备性如果if语句和case语句的条件描述不完备,也会造成不必要的锁存器。
Verilog中的一些语法和技巧

1、.2、.3、Reg型的数据类型默认初始值为X。
reg型数据可以赋正值也可以赋负值,但是当一个reg型数据是一个表达式的操作数的时候,他的值被当做无符号数及正值。
4、在数据类型中?和Z均表示高阻态。
5、Reg型只表示被定义的信号将用在“always”模块内,并不是说reg型一定是寄存器或触发器的输出。
虽然reg型信号常常是寄存器或触发器的输出但是并不一定总是这样。
6、Verilog语言中没有多维数组的存在。
Memory型数据类型是通过扩展reg型数据的弟子和范围来生成的。
其格式如下reg[n-1:0]存储器名[m-1:0];7、在除法和取余的运算中结果的符号和第一个操作数的符号位是相同的。
8、不同长度的数据进行运算:两个长度不同的数据进行位运算时,系统会自动地将两者按有端对齐,位数少的操作数会在相应的高位用0填满以便连个操作数安慰进行操作。
9、= = =与!= = =和= =与!= =的区别:后者称为逻辑等是运算符,其结果是2个操作数的值决定的。
由于操作书中某些位可能不定值x和高阻态z结果可能是不定值x。
而 = = =和!= = =运算符对操作数的比较时对某些位的高阻态z和不定值x也进行比较,两个操作数必须完全一致,其结果才是1,否则是0.10、非阻塞和阻塞赋值方式:非阻塞赋值方式(如a<=b)上面语句所赋得变量值不能立即被下面语句所用,(2)快结束后才能完成这次赋值操作 3在编写克综合的时序逻辑模块时这是最常用的赋值方法。
阻塞赋值(如a=b)赋值语句执行完后,块才结束 2 b的值在赋值语句完成后立即执行 3在时序逻辑使用中,可能产生意想不到的结果。
11、模块的描述方式:(RTL为寄存器传输级描述)“(1)数据流描述方式:数据流行描述主要用来描述组合功能,具体用“assign”连续赋值语句来实现。
分为两种a、显式连续赋值语句;连线型变量类型[连线型变量为快]连线型变量名Assign #(延时量)连线型变量名=赋值表达式;显式连续赋值语句包含了两条语句;第一条是对连线型变量的进行类型说明的说明语句;第二句是对这个已得到声明的连线型变量进行连续赋值语句。
可维护,可移植的verilog工程设计技巧

可维护、可移植的verilog工程设计技巧TIDERIP——新手上路A随着集成电路发展的脚步,28nm技术已经大规模应用在FPGA领域,FPGA开发者面临着日趋庞大的系统设计。
笔者也在这段时间开始接触带有硬核ARM的Cyclone V,Quartus 也华丽丽地升级到了13.1版本。
随着硬件平台及开发环境的更迭,项目版本的更新,深深感觉到代码的可维护性,可移植性异常重要,所以写下这篇笔记,笔者接触FPGA的时间并不长,水平有限,就当做抛砖引玉吧。
一,工程设计层次化,结构化要编写可维护、可移植的工程首先要对设计进行层次化、结构化设计。
不要急于Coding,先整理思路,做好体系结构和模块的划分。
一个设计任务需要按照功能或者类别分成若干个可独立操作的模块,每个模块又可以细分下去,这样可以由若干名工程师同时设计,当然也可以选用商业模块。
通过这样的逐次分解与模块的例化,整个工程能以设计树的方式绘出。
如图1所示:Top 顶层模块模块A 模块B 模块C模块A1 模块A2 模块B1 模块C1 模块C2这样的设计在后期维护以及移植的时候可以根据具体要求更新部分模块,尽量少地改变其他部分的代码和时序。
(由于FPGA结构的原因,即使修改部分模块,也会对整体的布局布线造成改变,需要对时序进行约束,而这又是另外一个课题了)二,模块及例化设计要做到可维护,可移植,对底层模块的要求较高,要求尽量做到功能独立、可重入。
功能独立便于移植裁剪、系统维护的时候可以只对部分模块进行修改。
而模块的重入性越高,维护和移植的时候修改的代码量就越小,只对底层模块修改即可,上层行为级模块可不做修改。
Verilog中以例化的方式调用其他功能模块,与C语言等软件函数调用不同的是,硬件描述语言的例化是实实在在的电路,同一个功能模块的多次例化分别是独立的实体,而不是软件函数简单的复用。
所以,上面的两种设计技巧只是从coding的方面考虑问题,而FPGA 向来要求从硬件的角度去考虑问题,底层模块的修改,意味电路结构,布局布线,时序都发生了变化,可维护性和可移植性在硬件的角度需要更多考虑。
《NCverilog教程》课件

覆盖率
覆盖率是测试验证中的一个重要概念, 它描述了测试用例覆盖了多少代码。覆 盖率可以分为多种类型,如语句覆盖率 、分支覆盖率、条件覆盖率等。
VS
断言
断言是Verilog中用于描述程序行为的一 种方式。断言可以用于检查程序中的某些 条件是否满足,如果不满足则产生错误。 断言通常用于验证程序的正确性。
详细描述:通过中等难度的实例,帮助学习者深入理解 Verilog的编程原理和技巧,提高编程能力。
详细描述:通过中等难度的实例,让学习者实践编写较 复杂的Verilog代码,掌握高级编程技巧和方法。
复杂实例解析
在此添加您的文本17字
总结词:高级应用
在此添加您的文本16字
详细描述:通过复杂的Verilog代码实例,介绍Verilog在 硬件设计中的应用和实践,包括数字系统设计、硬件测试 等。
05
NCVerilog调试与优化
Chapter
调试工具与技巧
调试工具
使用NCVerilog的调试工具,如仿真 器、调试器等,可以帮助开发者定位 和解决代码中的问题。
调试技巧
在调试过程中,可以采用断点、单步 执行、变量监视等技巧,以便更好地 观察和了解代码的执行情况。
优化策略与技巧
优化策略
优化NCVerilog代码时,可以采用一些常见的优化策 略,如流水线化、并行化、减少计算复杂度等。
它基于Verilog语言,并扩展了其功能 ,支持高性能的数字系统设计。
NCVerilog的特点
支持高性能数字系统设计
NCVerilog提供了高性能的硬件描述语言,支 持大规模数字系统的设计和实现。
高效仿真和综合
NCVerilog具有高效的仿真和综合工具,能够 快速验证和实现设计。
个人总结Verilog代码编写的25条经验

个人总结Verilog代码编写的25条经验1、对所有的信号名、变量名和端口名都用小写,这样做是为了和业界的习惯保持一致;对常量名和用户定义的类型用大写;2、使用有意义的信号名、端口名、函数名和参数名;3、信号名长度不要太长;4、对于时钟信号使用clk 作为信号名,如果设计中存在多个时钟,使用clk 作为时钟信号的前缀;5、对来自同一驱动源的信号在不同的子模块中采用相同的名字,这要求在芯片总体设计时就定义好顶层子模块间连线的名字,端口和连接端口的信号尽可能采用相同的名字;6、对于低电平有效的信号,应该以一个下划线跟一个小写字母b 或n 表示。
注意在同一个设计中要使用同一个小写字母表示低电平有效;7、对于复位信号使用rst 作为信号名,如果复位信号是低电平有效,建议使用rst_n;8、当描述多比特总线时,使用一致的定义顺序,对于verilog 建议采用bus_signal[x:0]的表示;9、尽量遵循业界已经习惯的一些约定。
如*_r 表示寄存器输出,*_a 表示异步信号,*_pn 表示多周期路径第n 个周期使用的信号,*_nxt 表示锁存前的信号,*_z 表示三态信号等;10、在源文件、批处理文件的开始应该包含一个文件头、文件头一般包含的内容如下例所示:文件名,作者,模块的实现功能概述和关键特性描述,文件创建和修改的记录,包括修改时间,修改的内容等;11、使用适当的注释来解释所有的always 进程、函数、端口定义、信号含义、变量含义或信号组、变量组的意义等。
注释应该放在它所注释的代码附近,要求简明扼要,只要足够说明设计意图即可,避免过于复杂;12、每一行语句独立成行。
尽管VHDL 和Verilog 都允许一行可以写多个语句,当时每个语句独立成行可以增加可读性和可维护性。
同时保持每行小于或等于72 个字符,这样做都是为了提高代码得可读性;13、建议采用缩进提高续行和嵌套语句得可读性。
缩进一般采用两个空格,如西安交通大学SOC 设计中心2 如果空格太多则在深层嵌套时限制行长。
NCVerilog设计秘诀与点评

NCVerilog设计秘诀与点评NCverilogNCVerilog设计秘诀与点评1. * S) ]8 E. K" x% ZThis approach allows completely transparent mixed language, mixed-level, and mixed cycle-event simulations. It also lays the foundation for mixed signal simulations. ' y+ l3 s- ? E, q + C' J9 o+ Y4 C' w c2.External Interface:(1) VHDL: VHPI,OMI(2) Verilog: PLI, VPI, OMI% F9 z9 W1 G( J( [$ y(Modelsim和VCS也有这个功能)(PLI用的比较多,仿真器一般自带常用的PLI。
)8 s: s: o: u' _. a( y3 k( Z$ y(如果需要添加FSDB支持,需要将debussy提供的libpli.dll和libpli.lib 拷贝到tools/lib下面)_/ Z {; m X9 X+ ]; t E7 Y3. After elaboration, Single executable code stream, Affirma NC Simulator; ) P# J) n. h% [" D4.Code Coverage5. Verilog supported: $ e: Y1 k( @: f1 h/ j(1) OVI 2.0; 3 `8 t0 [- N0 i- o(2) IEEE 1364;(3) Verilog-XL implementation;6. NC-Verilog use: Library.Cell:View 0 [" {/ k" r, Z/ _4 }cds.lib: This file contains statements that define your libraries and that map logical library names to physical directory paths. 7 S f8 ~# `$ n8 L# h4 j% O+ Whdl.var:This file defines which library is the work library. ( c3i7 y6 e/ Y# T, F* q7. You can write a setup.loc file to change the directories to search or to change the order of precedence to use when searching for the cds.lib and hdl.var files. & T& R$ o6 ]5 ?1 O+ f, [2 a8. (仿真器的“构成-步骤”:ncvlog-parse,ncelab-elaborate,ncsim-simulate). {6 n/ o( s% [% u0 w" Q S& Y Single-step invocation: ncverilog : a parser called ncvlog; an elaborator called ncelab to build the model, and then invokes the ncsim simulator to simulate the model.Multi-step invocation: invoke ncvlog, ncelab, and ncsim separately. => : G0 K3 k- p: o) AThe cell binding mechanism is the major difference between the two invocation methods.9.ncpack:change the properties of a database to make it read-only or add-only. . E0 l& n1 q2 h) /; p" y3 `9 Yinca.architecture.lib_version.pakinca.sun4v.091.pakncls utility: list the objects contained in the library system,10. Library files protect:(1) file locking mechanism: ncpack -unlock, to unlock a file(2) signal handling mechanism ensures that any unexpected event, 0 _! X8 i. A( g! F+ S, C9 P5 r$ J: o0 T0 q) |11. cdsdoc:To invoke the Cadence documentation window 3 a+ e1 M) k3 ?* j# x: L) M% Jtool_name -helpnchelp [options] tool_name message_code ******* ; o' Q' y. D2 q# H p6 M0 d" hncsim> help [help_options] [command | all [command_options]]11. ; R* X" ^& [! O; A- lNCLaunch is a graphical user interfacenclaunch 3 e$ Q+ J: l3 S; c. O6 F( VSimVision Waveform Viewer,7 e" _1 i' r: y1 D' M* u/ Z12.Many of these options have a corresponding plus option that you ( J$ [8 b% o' t) Ucan use on the ncverilog command.ncvlog -ieee1364 => ncverilog +ncieee1364 4 h D; J8 [ |# _! ~6 aWhen you run ncverilog, the parser is invoked with the -update optionby default. 2 M8 O* k& L$ Y' F) p1 u2 [: ~8 h& f2 d13. ncverilog:(1) +debug. This option turns on read access to all objects in the design. , o' h5 y' Z/ ?1 R=> ncelab -access +r(2) +ncaccess+. Use this option to selectively turn on different kinds of access. * @0 g% D8 Y9 E, c$ g( /2 ve.x.: +ncaccess+r, +ncaccess+r+w - M/ q/ s5 F2 i" e0 b(3) +ncafile+access_file: to specify an access file, # [) j) K8 A' q5 O, Q# G- O/ Q6 Y2 n9 ^2 ]5 cThree access: ) I7 G$ M5 Y$ H1 G$ lEnabling Read, Write, or Connectivity Access to Simulation Objects.14. % d7 l7 A& ?$ R4 m' Rncsim -licqueue: license queue 9 w9 j4 U# W# H6 O( D% K(当license不足的时候,用这个语句可以确保有人退出的时候,你能及时获得license)" A. F8 I* b' B" IThe NC-Verilog simulator command language is based on T cl.TCL input file: +ncinput+filename or +tcl+filename;15.ncverilog.args in the snap.nc directory: command-line options of ncverilog ( r: Q8 N' D2 h6 p- y1 ^ C(所以前一次的命令在彼处有保存): g& D# d* w" E6 T7 P# s! F) v, V2 ccds.lib and hdl.var file in the INCA_libs directory. ! a. k( m; f' N8 k5 W4 ?% ]3 `2 J% S# g5 }- [7 ?All tools share a common log file named ncverilog.log.(查看log文件从而掌握运行时情况是最重要的debug方法之一)& g" t/ g$ D5 f8 y) @) L9 E: s9 s9 `" r: ]/ S0 FDesign units in files specified directly on the command line are compiled into the work library, and design units specified in -y libraries or -v library files are compiled into libraries that have the same names.9 X2 M$ u: `; i: Y( `Writes the SNAPSHOT variable to the hdl.var file in the snap.ncdirectory to store the name of the snapshot used in this run.3 }$ O0 o; L/ l# J---The SNAPSHOT variable in the hdl.var file is used to determine what snapshot wascreated the last time this directory was used.16. The next time you invoke ncverilog, it compares the current set of command-line options to the options stored in the ncverilog.args file. All of the plus options and dash options must be the same and in the same order for the options to be evaluated as equal. $ u6 o5 b2 r9 [8 h% V" B4 ~8 G. w3 x" `; q17. ' T9 N' n: _1 }# r* T( P2 ~4 }. OThe ncverilog +ncuid+ncuid_name option enables functionality in ncverilog that lets you run multiple simulations using the same intermediate objects and the same storage locations. The +ncuid+ option enables this functionality by providing a unique ID name for each simulation. : t7 ?) k* k+ j' S6 /0 G0 y/ y( M% y z18. (命令行参数含义)1 z2 R$ f0 `' B5 /, e+ F8 l+ b1 Gncverilog -h +all+cdslib+path+checkargs: Display a list of the arguments used on the command line. . m/ k: M7 H B6 i; F* T0 B+compile: Run ncvlog to compile the design, but do not invoke ncelab to elaborate the design or ncsim to simulate.+debug:Turn on read access to all objects in the design. 2 y z" K! i; V/ F9 YThis option is the same as +ncaccess+r. & ~( f4 e( F; y `: P( X +elaborate:Run ncvlog and ncelab % g0 C; a( p8 k3 a" L: z$ I +expand: Expand all vectors.+hdlvar+path-h ! J; Z7 a* t/ t3 A* u$ G: d9 x4 n5 n+import:Prepare this Verilog design for import to VHDL.+mixedlang:Search the library structure for a VHDL bindingfor instances that correspond to VHDL import. 9 v" J) q; a% S3 D1 y' H/ @5 n% Z+name+name: Use the specified name for the snapshot and for the INCA_libs/snap.nc directory. 0 v3 i1 h3 i6 O8 ]/ J +ncelabargs+string:Pass the specified ncelab command options to the elaborator before invoking it. 4 c1 q! G8 e3 t0 Y! B; l0 S3 H+ncelabexe+path_to_ncelab+ncerror+warning_code:Increase the severity level of the specified warning message from warning to error. 1 Q* ]$ C/ x7 a* u+ b7 }) s3 V +ncfatal+{warning_code | error_code}: Increase the severity level of the specified warning message or error message from warning or error to fatal.+nclibdirname+directory_name: to change INCA_libs+ncls_all:List all of the objects in all libraries.+ncls_dependents:Show the dependents for each object. & j2 j/ g- s, w0 D: V, Y+ncls_snapshots: List all snapshot (SSS) objects.+ncls_source:Show the source file dependents of each object.+ncsimargs+string $ Q8 F9 W4 M- X. {/ y+ncsimexe+path_to_ncsim+ncuid+ncuid_name+ncvlogargs+string ' X1 _0 O/ Z* l6 `: O7 X+noautosdf:Do not perform automatic SDF annotation. % o. {* Z {1 m+noupdate: prevents the writing of intermediate objects for design units that are up-to-date. + W7 p( g+ e2 G+ ` +ppe:Invoke the Post Processing Environment (PPE). 6 J) |4 _6 f- x -R: Invoke the simulator (ncsim) to simulate the snapshot in the INCA_libs/worklib directory. & Q% `, ^6 B( c [-r snapshot: Load the specified snapshot.+sdf_orig_dir:Put the compiled SDF file in same location as the original SDF file.+work+library_name:Use the specified library as the work library. ( K9 Z6 @0 ^8 G" [6 J-c Compile and elaborate only. //same to Verilog-XL & {0 M! O. P+ x& I 4 A; h( w% N& F* h0 T% m* C' W20. , S. ]4 b( g6 e* e& p3 A( kncverilog:+tcl+filename,+ncinput+filename:The NC-Verilog simulator command language is based on Tcl.21.The compiled SDF file:dcache.sdf.test1.X). " E% r2 L4 /9 [# n0 W: L6 QSnapshots are always named lib.cell:ncuid_name22. $test$plusargs% ncverilog -R +userarg 0 ~9 `! {7 j3 u2 L- r% ncverilog -R +some_other_userarg 3 |$ I& c7 q; w/ C% E5 v: E. N0 e3 S1 g- ?( T& O) b4 U7 T0 }( v23. // To understand the concept of Snapshot ; l! V9 e$ [1 L1 T- h! Ex% ncverilog source.v +ncuid+test1 # O: f( s1 r9 P' ~/ r$ V% ncverilog source.v +ncuid+test2Two snapshots are generated in the INCA_libs/worklib directory: worklib.top:test1 and worklib.top:test2.you generate two snapshots using the following command lines: $ o- p% |7 Q w: }1 c! J, /% ncverilog source.v +elaborate ) I+ a' J5 e: z+ o, E+ f% ncverilog source.v +elaborate +ncaccess+r+nclibdirname+MYINCA_libs +name+debug + ]' r8 L, R) ?$ V+ K- v => T o simulate this snapshot: 6 z9 A# a4 A% k6 d4 l! j % ncverilog -R +nclibdirname+MYINCA_libs +name+debug [+simulator_options]/doc/6e7742356.html,ing -r to Simulate a Saved Snapshot:% ncverilog -f verilog.vc +elaborate & F4 o" W* T9 |! q3 c% ncverilog -R -sncsim> run 1000ncsim> save save1ncsim> exit * [5 x& f, q7 T8 e//To simulate the saved snapshot, specify the snapshot name with the -r option,% ncverilog -r worklib.save1:v // or: ncverilog -r save1 2 q% {4 h) v5 c4 S/ @; ?' j=> Simulation Environment: + O! ^/ |' X; v" I* M: ^. ^' eIf you want to restore the full Tcl debug environment when you restart with a saved snapshot, make sure that you save the environment with the save -environment filename command. This command creates a Tcl script that captures the current breakpoints, databases, probes, aliases, and predefined Tcl variable values. You can then use the +ncinput+ option when you invoke ncverilog to execute the script, or you can invoke ncverilog in interactive mode with the -s option and then use the Tcl source command to source the script.. c$ k$ t1 S [3 l1 {ncsim> save -environment ckpt1.tcl * X) d3 ^2 B7 l& F$ /% U" G% R/ d! K$ ancverilog -s -r worklib.top:ckpt1 +ncinput+ckpt1.tclNote: If you set a breakpoint that triggers, for example, every10 ns (that is, at time 10, 20, 30, and so on) and restart with a snapshot saved at time 15, the breakpoint triggers at 20, 30, and so on, not attime 25, 35, and so on. * }( ?9 L7 P3 t( B0 M# A* }4 ^- r: B8 z& C' Z2 M6 l, G( Z25. 6 x. X" d# {+ M. s6 ?-R: The -R option lets you simulate the same snapshot multiple times using different simulatorcommand-line options.6 ?0 ~& I/ a8 D$ {$ D; /- {. Q-r: You can use the -r option to load a snapshot. - F) R+ o9 q;g) ]- M! E8 G2 j26.SDF versions 1.0, 2.0, 2.1, and 3.0. For versions 2.0 and above, use the SDFVERSION statement in the header of the SDF file to specify the version. # S1 p% O5 p; V& H+ C3 {; H. X- ESDF annotation is performed during elaboration. The elaborator recognizes $sdf_annotate system tasks in the design source files, ! I1 y+ @9 y! t; Nto override the default automatic SDF annotation mechanism and force annotation by using the +sdf_cmd_file+filename option , y. P+ j.d) a8 K3 u. i# M# v2 H" @& B3 }, }2 X9 E4 A( F- y8 LSDF: The NC-Verilog simulator reads only compiled SDF files.(1) text SDF file, cpu.sdf, ' L; W2 ~9 G. V" v6 B(2) compiled file: cpu.sdf.X.ncsdfc utility to automatically compile the SDF file.+ j: T" ]& Z$ ~9 BUsing $test$plusargs to Selectively Perform Annotations:if ($test$plusargs( preroute )) 4 b1 v2 R% W3 /% j+ V$sdf_annotate( preroute.sdf , m1);else if ($test$plusargs( postroute )) 8 s1 G& ^9 e6 R z$sdf_annotate( postroute.sdf , m1);The ncsdfc utility always compiles the SDF file with a precision of 1 fs. The elaborator annotates each module using the precision of the module or the precision set by using the ncelab -sdf_precision command_line option. 8 ? t- C7 L; `. /! o1 ?! ?8 H! E& P3 o. k. l0 s( V30.Turning Off SDF Annotation: * o. @% q/ d# Y; W3 h% Q. s0 x6 V (1) Use the +noautosdf option on the ncverilog command line. . J& W% b- H8 f I9 w(2) Comment out the $sdf_annotate system task(s) in the Verilog source file.31.+sdf_cmd_file+filename32.You can use the -ieee1364 command-line option when you compile the design with ncvlog and elaborate the design with ncelab to check your code forcompatibility with the IEEE standard. + P1 H( o" |, W! l6 E* H$ P3 y33. IEEE 1364 - 1995 Verilog: array of instances, bufif0 ar[3:0] (out, in, en); // array of tri-state buffers However, an array of instances must have a continuous range.34. Set up your environment: 2 ^* I- E* X {0 x! R% s( pcds.lib , Z9 o- j- k4 [. qhdl.varsetup.loc35. 7 R. K) ~: H# R/ F2 O+ U4 BVerilog: module, macromodule, or UDPVHDL: entity, architecture, package, package body, or configuration % s1 I% z- V# h, `7 V: J% h: |3 T+ r: h+ k. z) e/ {36. * O4 h; _4 V7 Tinternal intermediate objects: ' B) g" w" R- b. u( W+ tlibrary database file (.pak file) * C- K6 v+ c% L( /! M8 p+ n5 A7 s" Y) h: U6 f1 G37.cds.lib: 9 w; /& m0 ?9 I3 r8 @DEFINE worklib ../worklib ' C' m0 G. D: {0 r" i# JDEFINE lib_std /usr1/libs/std_lib6 s+ n9 n/ X+ i7 g3 t7 X$ b- F% u1 wYou can have more than one cds.lib file.Use the INCLUDE or SOFTINCLUDE statements to include a cds.lib file within a cds.lib If you are doing a pure VHDL or a mixed-language simulation, you must use the INCLUDE or SOFTINCLUDE statement in the cds.lib (System provide one) SOFTINCLUDE is the same as the INCLUDE statement, except that no error messages are printed if the file does not exist.8 z/ q* Y% w# u7 {$ m0 z, V38. Binding One Library to Multiple Directories:DEFINE iclib ./ic_lib 3 W( R- c; Y4 X3 ~ASSIGN iclib TMP ./ic_tmp_lib...UNASSIGN iclib TMP ; F5 i, U- T6 P& {0 D38. -- can be used to check the content of the cds.lib # Q- o/u# /5 k& w4 Q0 j% nchelp -cdslib 6 A8 {, W5 @9 }( {# C) H- s39. hdl.lib ; d' ]3 a# x0 J( y1 Y# fDEFINE WORK worklibDEFINE VERILOG_SUFFIX (.v, .vg, .vb)NCVLOGOPTS -messages -errormax 10 -update 1 O- G. l, i" B! q* N6 | U40. hdl.var% nchelp -hdlvar ; m3 H7 [' E _9 q; t8 a41. view & snapshot(1) The file mychip.v gets compiled into the default module view:worklib.mychip:module.It is created after compile, (ncvlog)(2) The elaborator generates a simulation snapshot for the design. * K+ I, j+ /5 C; a8 `) N" ZIntermediate objects created during the elaboration phase are stored in the .pak file.The snapshot is also a Lib.Cell:View. 9 q1 W" Y" S1 N; P. @3 y! Z9 p3 x+ }source =>(compile)=> module =>(elaborate) => snapshot => simulation, , M. /) R. `( g1.Verilog和Ncverilog命令使用库文件或库目录ex). ncverilog -f run.f -v lib/lib.v -y lib2 +libext+.v //一般编译文件在run.f中, 库文件在lib.v中,lib2目录中的.v文件系统自动搜索使用库文件或库目录,只编译需要的模块而不必全部编译2.Verilog Testbench信号记录的系统任务:1). SHM数据库可以记录在设计仿真过程中信号的变化. 它只在probes有效的时间内记录你set probe on的信号的变化.ex). $shm_open("waves.shm"); //打开波形数据库$shm_probe(top, "AS"); // set probe on "top",第二个参数: A -- signals of the specific scropeS -- Ports of the specified scope and below, excluding library cellsC -- Ports of the specified scope and below, including library cellsAS -- Signals of the specified scope and below, excluding library cellsAC -- Signals of the specified scope and below, including library cells还有一个M ,表示当前scope的memories, 可以跟上面的结合使用, "AM" "AMS" "AMC"什么都不加表示当前scope的ports;$shm_close //关闭数据库2). VCD数据库也可以记录在设计仿真过程中信号的变化. 它只记录你选择的信号的变化.ex). $dumpfile("filename"); //打开数据库$dumpvars(1, top.u1); //scope = top.u1, depth = 1第一个参数表示深度, 为0时记录所有深度; 第二个参数表示scope,省略时表当前的scope.$dumpvars; //depth = all scope = all$dumpvars(0); //depth = all scope = current$dumpvars(1, top.u1); //depth = 1 scope = top.u1$dumpoff //暂停记录数据改变,信号变化不写入库文件中$dumpon //重新恢复记录3). Debussy fsdb数据库也可以记录信号的变化,它的优势是可以跟debussy结合,方便调试.如果要在ncverilog仿真时,记录信号, 首先要设置debussy:a. setenv LD_LIBRARY_PATH :$LD_LIBRARY_PATH(path for debpli.so file (/share/PLI/nc_xl//nc_loadpli1))b. while invoking ncverilog use the +ncloadpli1 option.ncverilog -f run.f +debug +ncloadpli1=debpli:deb_PLIPtrfsdb数据库文件的记录方法,是使用$fsdbDumpfile和$fsdbDumpvars系统函数,使用方法参见VCD注意: 在用ncverilog的时候,为了正确地记录波形,要使用参数: "+access+rw", 否则没有读写权限3. ncverilog编译的顺序: ncverilog file1 file2 ....有时候这些文件存在依存关系,如在file2中要用到在file1中定义的变量,这时候就要注意其编译的顺序是从后到前,就先编译file2然后才是file2.4. 信号的强制赋值force首先, force语句只能在过程语句中出现,即要在initial 或者always 中间. 去除force 用release 语句.initial begin force sig1 = 1'b1; ... ; release sig1; endforce可以对wire赋值,这时整个net都被赋值; 也可以对reg赋值.我们知道,由于NC-Verilog使用了Native Compile Code 的技术来加强电路模拟的效率,因此在进行模拟时必须经过compile(ncvlog 命令)以及elaborate(ncelab命令)的步骤。
verilog实用的小技巧

verilog实⽤的⼩技巧
(之后还会持续的更新)
移位操作的实现:
verilog有⼀种⾮常简单的移位操作实例如下:
reg [3:0] source;
reg out;
{out,source[3:0]}={source[3:0],1'b0};//向左移位。
且不循环
{source[3:0],out}={1'b0,source[3:0]}//向右移位,且不循环
{out,source[3:0]}={source[3:0],source[3]};//向左循环移位
切记不能使⽤多驱动对同⼀个⽹线进⾏赋值:
编译verilog时往往会出现如下错误:Error (10028): Can't resolve multiple constant drivers for net "cnt[24]" at TIME_Ctr.v(37),这是初学者往往遇到的错误,这是受C语⾔代码的影响所造成的。
也就是⼀个
变量往往在多个always语句中赋值,会产⽣竞争与冒险的⾏为,所以我们写在⼀个always语句中也只对⼀个变量赋值。
verilog不同于其他的编程语⾔的特点(并发性)要时刻的铭记于⼼。
在编写testbench的注意事项
1. 仿真调⽤模块时应尽可能的⽤按端⼝进⾏赋值。
2. 仿真的模块的输⼊应为reg类型,输出应该为线⽹类型,这点要注意这和函数的形参传值不⼀样,这个是相当于是⽤外部寄存器或是线
⽹来链接这个模块,这点要⾮常的注意!(其实顶层在调⽤⼦模块的时候也是⼀个道理)
3. clock仿真的时候⼀定要赋予初始值要不然就会保持⾼阻态的状态。
提高NCverilog仿真效率技巧

提高NC-Verilog仿真效率的技巧(转)上一篇/ 下一篇 2010-04-25 22:43:50查看( 1374 ) / 评论( 2 ) / 评分( 0 / 0 )本文回顾了一些NC-Verilog的命令行选项,并说明这些选项如何影响仿真效率。
同时,我们也展示了一些技巧,以帮助用户的NC- Verilog在最大效率下仿真一个设计和测试平台。
文中的命令行选项语法采用单步启动的方式(ncverilog +<options>),这些选项也适合多步启动模式(ncvlog, ncelab, 或ncsim)。
安装最新发布的软件首先确认你是否安装了最新的Cadence LDV版本。
自动1996年发布第一版NC-Verilog以来,我们的研发队伍一直把仿真器的仿真效率作为重点来研究。
在后来推出的新版本里,不断按各种设计风格优化仿真器,因此使用最新版本是最有利的。
直到2002年2月,最新版本是LDV 3.4(s1)。
使用NC-Verilog内置的profilerNC-Verilog在仿真引擎内开发了一个profiler工具。
该工具每秒中断仿真器100次,并将终端时的结构记录下来,生成一个日志文件。
日志文件里列出了被中断次数最多的模块、代码行和结构类型。
这些信息可以帮助你诊断是哪些代码或模块在仿真时耗费了最多的时间。
通过修改这些模块,就能提升仿真效率。
Profiler功能很容易启动,并对仿真只产生非常小的影响。
% ncverilog +ncprofile <other_options> or% ncsim –profile snapshot_name <other_options>在仿真结束时,profiler会创建一个日志文件(ncprof.out),文件里列出了profile运行的细节。
关于如何利用profiler日志文件,可参考Cadence在线文档(Cadence NC-Verilog Simulator Help, Version 3.4, Chapter 14)。
Ncverilog 的一些经验

Ncverilog 的一些经验1.Verilog和Ncverilog命令使用库文件或库目录ex). ncverilog -f run.f -v lib/lib.v -y lib2 +libext+.v //一般编译文件在run.f中, 库文件在lib.v中,lib2目录中的.v文件系统自动搜索使用库文件或库目录,只编译需要的模块而不必全部编译2.Verilog Testbench信号记录的系统任务:1). SHM数据库可以记录在设计仿真过程中信号的变化. 它只在probes有效的时间内记录你set probe on的信号的变化.ex). $shm_open("waves.shm"); //打开波形数据库$shm_probe(top, "AS"); // set probe on "top",第二个参数: A -- signals of the specific sc ropeS -- Ports of the specified s cope and below, excluding library cellsC -- Ports of the specified s cope and below, including library cellsAS -- Signals of the specifie d scope and below, excluding library cellsAC -- Signals of the specifie d scope and below, including library cells还有一个 M ,表示当前scope的m emories, 可以跟上面的结合使用, "AM" "AMS" "AMC"什么都不加表示当前scope的por ts;$shm_close //关闭数据库2). VCD数据库也可以记录在设计仿真过程中信号的变化. 它只记录你选择的信号的变化.ex). $dumpfile("filename"); //打开数据库$dumpvars(1, top.u1); //scope = top.u1, depth = 1第一个参数表示深度, 为0时记录所有深度; 第二个参数表示scope,省略时表当前的scope.$dumpvars; //depth = all scope = all$dumpvars(0); //depth = all scope = current $dumpvars(1, top.u1); //depth = 1 scope = top. u1$dumpoff //暂停记录数据改变,信号变化不写入库文件中$dumpon //重新恢复记录3). Debussy fsdb数据库也可以记录信号的变化,它的优势是可以跟debus sy结合,方便调试.如果要在ncverilog仿真时,记录信号, 首先要设置debussy:a. setenv LD_LIBRARY_PATH :$LD_LIBRARY_PATH(path for debpli.so file (/share/PLI/nc_xl//nc_loadpli1)) b. while invoking ncverilog use the +ncloadpli1 option.ncverilog -f run.f +debug +ncloadpli1=debpli:deb_PLIPtr fsdb数据库文件的记录方法,是使用$fsdbDumpfile和$fsdbDumpvars系统函数,使用方法参见VCD注意: 在用ncverilog的时候,为了正确地记录波形,要使用参数: "+acces s+rw", 否则没有读写权限3. ncverilog编译的顺序: ncverilog file2 file1 ....有时候这些文件存在依存关系,如在file2中要用到在file1中定义的变量,这时候就要注意其编译的顺序是从后到前,就先编译file2然后才是file1.4. 信号的强制赋值force首先, force语句只能在过程语句中出现,即要在initial 或者 always 中间. 去除force 用 release 语句.initial begin force sig1 = 1'b1; ... ; release sig1; end force可以对wire赋值,这时整个net都被赋值; 也可以对reg赋值.ncverilog使用ncverilog是shell版的,nclaunch是以图形界面为基础的,二者调用相同内核;ncverilog的执行有三步模式和单步模式,在nclaunch中对应multiple step和single stepncverilog的三步模式为:ncvlog(编译) ncelab(建立snapshot文件) ncsim(对snapshot文件进行仿真)基于shell的ncverilog操作(尤其是单步模式)更适合于大批量操作ncverilog的波形查看配套软件是simvision,其中包含原理图、波形、信号流等查看方式三命令模式:ncvlog -f run.fncelab tb -access wrcncsim tb -gui第一个命令中,run.f是整个的RTL代码的列表,值得注意的是,我们需要把tb文件放在首位,这样可以避免出现提示timescale的错误注意:ncvlog执行以后将产生一个名为INCA_libs的目录和一个名为worklib的目录第二个命令中,access选项是确定读取文件的权限。
个人总结FPGA设计中Verilog编程的27条经验

个人总结FPGA设计中Verilog编程的27条经验个人总结Verilog编程27条经验1.强烈建议用同步设计;2.在设计时总是记住时序问题;3.在一个设计开始就要考虑到地电平或高电平复位、同步或异步复位、上升沿或下降沿触发等问题,在所有模块中都要遵守它;4.在不同的情况下用if和case,最好少用if的多层嵌套(1层或2层比较合适,当在3层以上时,最好修改写法,因为这样不仅可以reduce area,而且可以获得好的timing);5.在锁存一个信号或总线时要小心,对于整个design,尽量避免使用latch,因为在DFT时很难test;6.确信所有的信号被复位,在DFT时,所有的FlipFlop都是controllable;7.永远不要再写入之前读取任何内部存储器(如SRAM);8.从一个时钟到另一个不同的时钟传输数据时用数据缓冲,他工作像一个双时钟FIFO(是异步的),可以用Async SRAM搭建Async FIFO;9.在VHDL中二维数组可以使用,它是非常有用的。
在VERILOG 中他仅仅可以使用在测试模块中,不能被综合;10.遵守register-in register-out规则;11.像synopsys的DC的综合工具是非常稳定的,任何bugs都不会从综合工具中产生12.确保FPGA版本与ASIC的版本尽可能的相似,特别是SRAM 类型,若版本一致是最理想的,但是在工作中FPGA版本一般用FPGA自带的SRAM,ASIC版本一般用厂商提供的SRAM;13.在嵌入式存储器中使用BIST;14.虚单元和一些修正电路是必需的;15.一些简单的测试电路也是需要的,经常在一个芯片中有许多测试模块;16.除非低功耗不要用门控时钟,强烈建议不要在design中使用gate clock;17.不要依靠脚本来保证设计。
但是在脚本中的一些好的约束能够起到更好的性能(例如前向加法器);18.如果时间充裕,通过时钟做一个多锁存器来取代用MUX;19.不要用内部tri-state, ASIC需要总线保持器来处理内部tri-state,如IOcell;20.在top level中作pad insertion;21.选择pad时要小心(如上拉能力,施密特触发器,5伏耐压等),选择合适的IO cell;22.小心由时钟偏差引起的问题;23.不要试着产生半周期信号;24.如果有很多函数要修正,请一个一个地作,修正一个函数检查一个函数;25.在一个计算等式中排列每个信号的位数是一个好习惯,即使综合工具能做;26.不要使用HDL提供的除法器;27.削减不必要的时钟。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
NCverilogNCVerilog设计秘诀与点评1. * S) ]8 E. K" x% ZThis approach allows completely transparent mixed language, mixed-level, and mixed cycle-event simulations. It also lays the foundation for mixed signal simulations. ' y+ l3 s- ? E, q+ C' J9 o+ Y4 C' w c2.External Interface:(1) VHDL: VHPI,OMI(2) Verilog: PLI, VPI, OMI% F9 z9 W1 G( J( [$ y(Modelsim和VCS也有这个功能)(PLI用的比较多,仿真器一般自带常用的PLI。
)8 s: s: o: u' _. a( y3 k( Z$ y(如果需要添加FSDB支持,需要将debussy提供的libpli.dll和libpli.lib 拷贝到tools/lib下面)_/ Z {; m X9 X+ ]; t E7 Y3. After elaboration, Single executable code stream, Affirma NC Simulator; ) P# J) n. h% [" D4.Code Coverage ???5. Verilog supported: $ e: Y1 k( @: f1 h/ j(1) OVI 2.0; 3 `8 t0 [- N0 i- o(2) IEEE 1364;(3) Verilog-XL implementation;6. NC-Verilog use: Library.Cell:View 0 [" {/ k" r, Z/ _4 }cds.lib: This file contains statements that define your libraries and that map logical library names to physical directory paths. 7 S f8 ~# `$ n8 L# h4 j% O+ Whdl.var:This file defines which library is the work library. ( c3 i7 y6 e/ Y# T, F* q7. You can write a setup.loc file to change the directories to search or to change the order of precedence to use when searching for the cds.lib and hdl.var files. & T& R$ o6 ]5 ?1 O+ f, [2 a8. (仿真器的“构成-步骤”:ncvlog-parse,ncelab-elaborate,ncsim-simulate). {6 n/ o( s% [% u0 w" Q S& YSingle-step invocation: ncverilog : a parser called ncvlog; an elaborator called ncelab to build the model, and then invokes the ncsim simulator to simulate the model.Multi-step invocation: invoke ncvlog, ncelab, and ncsim separately. => : G0 K3 k- p: o) AThe cell binding mechanism is the major difference between the two invocation methods.9.ncpack:change the properties of a database to make it read-only or add-only. . E0 l& n1 q2 h) /; p" y3 `9 Yinca.architecture.lib_version.pakinca.sun4v.091.pakncls utility: list the objects contained in the library system,10. Library files protect:(1) file locking mechanism: ncpack -unlock, to unlock a file(2) signal handling mechanism ensures that any unexpected event, 0 _! X8 i. A( g! F+ S, C9 P5 r$ J: o0 T0 q) |11. cdsdoc:To invoke the Cadence documentation window 3 a+ e1 M) k3 ?* j# x: L) M% Jtool_name -helpnchelp [options] tool_name message_code ******* ; o' Q' y. D2 q# H p6 M0 d" hncsim> help [help_options] [command | all [command_options]]11. ; R* X" ^& [! O; A- lNCLaunch is a graphical user interfacenclaunch 3 e$ Q+ J: l3 S; c. O6 F( VSimVision Waveform Viewer,7 e" _1 i' r: y1 D' M* u/ Z12.Many of these options have a corresponding plus option that you ( J$ [8 b% o' t) Ucan use on the ncverilog command.ncvlog -ieee1364 => ncverilog +ncieee1364 4 h D; J8 [ |# _! ~6 aWhen you run ncverilog, the parser is invoked with the -update optionby default. 2 M8 O* k& L$ Y' F) p1 u2 [: ~8 h& f2 d13. ncverilog:(1) +debug. This option turns on read access to all objects in the design. , o' h5 y' Z/ ?1 R=> ncelab -access +r(2) +ncaccess+. Use this option to selectively turn on different kinds of access. * @0 g% D8 Y9 E, c$ g( /2 ve.x.: +ncaccess+r, +ncaccess+r+w - M/ q/ s5 F2 i" e0 b(3) +ncafile+access_file: to specify an access file, # [) j) K8 A' q5 O, Q# G- O/ Q6 Y2 n9 ^2 ]5 cThree access: ) I7 G$ M5 Y$ H1 G$ lEnabling Read, Write, or Connectivity Access to Simulation Objects.14. % d7 l7 A& ?$ R4 m' Rncsim -licqueue: license queue 9 w9 j4 U# W# H6 O( D% K(当license不足的时候,用这个语句可以确保有人退出的时候,你能及时获得license)" A. F8 I* b' B" IThe NC-Verilog simulator command language is based on Tcl.TCL input file: +ncinput+filename or +tcl+filename;15.ncverilog.args in the snap.nc directory: command-line options of ncverilog ( r: Q8 N' D2 h6 p- y1 ^ C(所以前一次的命令在彼处有保存): g& D# d* w" E6 T7 P# s! F) v, V2 ccds.lib and hdl.var file in the INCA_libs directory. ! a. k( m; f' N8 k5 W4 ?% ]3 `2 J% S# g5 }- [7 ?All tools share a common log file named ncverilog.log.(查看log文件从而掌握运行时情况是最重要的debug方法之一)& g" t/ g$ D5 f8 y) @) L9 E: s9 s9 `" r: ]/ S0 FDesign units in files specified directly on the command line are compiled into the work library, and design units specified in -y libraries or -v library files are compiled into libraries that have the same names.9 X2 M$ u: `; i: Y( `Writes the SNAPSHOT variable to the hdl.var file in the snap.ncdirectory to store the name of the snapshot used in this run. 3 }$ O0 o; L/ l# J---The SNAPSHOT variable in the hdl.var file is used to determine what snapshot wascreated the last time this directory was used.16. The next time you invoke ncverilog, it compares the current set of command-line options to the options stored in the ncverilog.args file. All of the plus options and dash options must be the same and in the same order for the options to be evaluated as equal. $ u6 o5 b2 r9 [8 h% V" B4 ~8 G. w3 x" `; q17. ' T9 N' n: _1 }# r* T( P2 ~4 }. OThe ncverilog +ncuid+ncuid_name option enables functionality in ncverilog that lets you run multiple simulations using the same intermediate objects and the same storage locations. The +ncuid+ option enables this functionality by providing a unique ID name for each simulation. : t7 ?) k* k+ j' S6 /0 G0 y/ y( M% y z18. (命令行参数含义)1 z2 R$ f0 `' B5 /, e+ F8 l+ b1 Gncverilog -h +all+cdslib+path+checkargs: Display a list of the arguments used on the command line. . m/ k: M7 H B6 i; F* T0 B+compile: Run ncvlog to compile the design, but do not invoke ncelab to elaborate the design or ncsim to simulate.+debug:Turn on read access to all objects in the design. 2 y z" K! i; V/ F9 YThis option is the same as +ncaccess+r. & ~( f4 e( F; y `: P( X+elaborate:Run ncvlog and ncelab % g0 C; a( p8 k3 a" L: z$ I+expand: Expand all vectors.+hdlvar+path-h ! J; Z7 a* t/ t3 A* u$ G: d9 x4 n5 n+import:Prepare this Verilog design for import to VHDL.+mixedlang:Search the library structure for a VHDL binding for instances that correspond to VHDL import. 9 v" J) q; a% S3 D1 y' H/ @5 n% Z+name+name: Use the specified name for the snapshot and for the INCA_libs/snap.nc directory. 0 v3 i1 h3 i6 O8 ]/ J+ncelabargs+string:Pass the specified ncelab command options to the elaborator before invoking it. 4 c1 q! G8 e3 t0 Y! B; l0 S3 H+ncelabexe+path_to_ncelab+ncerror+warning_code:Increase the severity level of the specified warning message from warning to error. 1 Q* ]$ C/ x7 a* u+ b7 }) s3 V +ncfatal+{warning_code | error_code}: Increase the severity level of the specified warning message or error message from warning or error to fatal.+nclibdirname+directory_name: to change INCA_libs+ncls_all:List all of the objects in all libraries.+ncls_dependents:Show the dependents for each object. & j2 j/ g- s, w0 D: V, Y+ncls_snapshots: List all snapshot (SSS) objects.+ncls_source:Show the source file dependents of each object.+ncsimargs+string $ Q8 F9 W4 M- X. {/ y+ncsimexe+path_to_ncsim+ncuid+ncuid_name+ncvlogargs+string ' X1 _0 O/ Z* l6 `: O7 X+noautosdf:Do not perform automatic SDF annotation. % o. {* Z {1 m+noupdate: prevents the writing of intermediate objects for design units that are up-to-date. + W7 p( g+ e2 G+ `+ppe:Invoke the Post Processing Environment (PPE). 6 J) |4 _6 f- x -R: Invoke the simulator (ncsim) to simulate the snapshot in the INCA_libs/worklib directory. & Q% `, ^6 B( c [-r snapshot: Load the specified snapshot.+sdf_orig_dir:Put the compiled SDF file in same location as the original SDF file.+work+library_name:Use the specified library as the work library. ( K9 Z6 @0 ^8 G" [6 J-c Compile and elaborate only. //same to Verilog-XL & {0 M! O. P+ x& I 4 A; h( w% N& F* h0 T% m* C' W20. , S. ]4 b( g6 e* e& p3 A( kncverilog:+tcl+filename,+ncinput+filename:The NC-Verilog simulator command language is based on Tcl.21.The compiled SDF file:dcache.sdf.test1.X). " E% r2 L4 /9 [# n0 W: L6 QSnapshots are always named lib.cell:ncuid_name22. $test$plusargs% ncverilog -R +userarg 0 ~9 `! {7 j3 u2 L- r% ncverilog -R +some_other_userarg 3 |$ I& c7 q; w/ C% E5 v: E. N0 e3 S1 g- ?( T& O) b4 U7 T0 }( v23. // To understand the concept of Snapshot ; l! V9 e$ [1 L1 T- h! Ex% ncverilog source.v +ncuid+test1 # O: f( s1 r9 P' ~/ r$ V% ncverilog source.v +ncuid+test2Two snapshots are generated in the INCA_libs/worklib directory: worklib.top:test1 and worklib.top:test2.you generate two snapshots using the following command lines: $ o- p% |7 Q w: }1 c! J, /% ncverilog source.v +elaborate ) I+ a' J5 e: z+ o, E+ f% ncverilog source.v +elaborate +ncaccess+r +nclibdirname+MYINCA_libs +name+debug + ]' r8 L, R) ?$ V+ K- v => To simulate this snapshot: 6 z9 A# a4 A% k6 d4 l! j% ncverilog -R +nclibdirname+MYINCA_libs +name+debug [+simulator_options]ing -r to Simulate a Saved Snapshot:% ncverilog -f verilog.vc +elaborate & F4 o" W* T9 |! q3 c% ncverilog -R -sncsim> run 1000ncsim> save save1ncsim> exit * [5 x& f, q7 T8 e//To simulate the saved snapshot, specify the snapshot name with the -r option,% ncverilog -r worklib.save1:v // or: ncverilog -r save1 2 q% {4 h) v5 c4 S/ @; ?' j=> Simulation Environment: + O! ^/ |' X; v" I* M: ^. ^' eIf you want to restore the full Tcl debug environment when you restart with a saved snapshot, make sure that you save the environment with the save -environment filename command. This command creates a Tcl script that captures the current breakpoints, databases, probes, aliases, and predefined Tcl variable values. You can then use the +ncinput+ option when you invoke ncverilog to execute the script, or you can invoke ncverilog in interactive mode with the -s option and then use the Tcl source command to source the script.. c$ k$ t1 S [3 l1 {ncsim> save -environment ckpt1.tcl * X) d3 ^2 B7 l& F$ /% U" G% R/ d! K$ ancverilog -s -r worklib.top:ckpt1 +ncinput+ckpt1.tclNote: If you set a breakpoint that triggers, for example, every 10 ns (that is, at time 10, 20, 30, and so on) and restart with a snapshot saved at time 15, the breakpoint triggers at 20, 30, and so on, not attime 25, 35, and so on. * }( ?9 L7 P3 t( B0 M# A* }4 ^- r: B8 z& C' Z2 M6 l, G( Z25. 6 x. X" d# {+ M. s6 ?-R: The -R option lets you simulate the same snapshot multiple times using different simulatorcommand-line options.6 ?0 ~& I/ a8 D$ {$ D; /- {. Q-r: You can use the -r option to load a snapshot. - F) R+ o9 q; g) ]- M! E8 G2 j26.SDF versions 1.0, 2.0, 2.1, and 3.0. For versions 2.0 and above, use the SDFVERSION statement in the header of the SDF file to specify the version. # S1 p% O5 p; V& H+ C3 {; H. X- ESDF annotation is performed during elaboration. The elaborator recognizes $sdf_annotate system tasks in the design source files, ! I1 y+ @9 y! t; Nto override the default automatic SDF annotation mechanism and force annotation by using the +sdf_cmd_file+filename option , y. P+ j.d) a8 K3 u. i# M# v2 H" @& B3 }, }2 X9 E4 A( F- y8 LSDF: The NC-Verilog simulator reads only compiled SDF files.(1) text SDF file, cpu.sdf, ' L; W2 ~9 G. V" v6 B(2) compiled file: cpu.sdf.X.ncsdfc utility to automatically compile the SDF file.+ j: T" ]& Z$ ~9 BUsing $test$plusargs to Selectively Perform Annotations:if ($test$plusargs( preroute )) 4 b1 v2 R% W3 /% j+ V$sdf_annotate( preroute.sdf , m1);else if ($test$plusargs( postroute )) 8 s1 G& ^9 e6 R z$sdf_annotate( postroute.sdf , m1);The ncsdfc utility always compiles the SDF file with a precision of 1 fs. The elaborator annotates each module using the precision of the module or the precision set by using the ncelab -sdf_precision command_line option. 8 ? t- C7 L; `. /! o1 ?! ?8 H! E& P3 o. k. l0 s( V30.Turning Off SDF Annotation: * o. @% q/ d# Y; W3 h% Q. s0 x6 V (1) Use the +noautosdf option on the ncverilog command line. . J& W% b- H8 f I9 w(2) Comment out the $sdf_annotate system task(s) in the Verilog source file.31.+sdf_cmd_file+filename32.You can use the -ieee1364 command-line option when you compile the design with ncvlog and elaborate the design with ncelab to check your code forcompatibility with the IEEE standard. + P1 H( o" |, W! l6 E* H$ P3 y33. IEEE 1364 - 1995 Verilog: array of instances, bufif0 ar[3:0] (out, in, en); // array of tri-state buffers However, an array of instances must have a continuous range.34. Set up your environment: 2 ^* I- E* X {0 x! R% s( pcds.lib , Z9 o- j- k4 [. qhdl.varsetup.loc35. 7 R. K) ~: H# R/ F2 O+ U4 BVerilog: module, macromodule, or UDPVHDL: entity, architecture, package, package body, or configuration % s1 I% z- V# h, `7 V: J% h: |3 T+ r: h+ k. z) e/ {36. * O4 h; _4 V7 Tinternal intermediate objects: ' B) g" w" R- b. u( W+ tlibrary database file (.pak file) * C- K6 v+ c% L( /! M8 p+ n5 A7 s" Y) h: U6 f1 G37.cds.lib: 9 w; /& m0 ?9 I3 r8 @DEFINE worklib ../worklib ' C' m0 G. D: {0 r" i# JDEFINE lib_std /usr1/libs/std_lib6 s+ n9 n/ X+ i7 g3 t7 X$ b- F% u1 wYou can have more than one cds.lib file.Use the INCLUDE or SOFTINCLUDE statements to include a cds.lib file within a cds.lib If you are doing a pure VHDL or a mixed-language simulation, you must use the INCLUDE or SOFTINCLUDE statement in the cds.lib (System provide one)SOFTINCLUDE is the same as the INCLUDE statement, except that no error messages are printed if the file does not exist.8 z/ q* Y% w# u7 {$ m0 z, V38. Binding One Library to Multiple Directories:DEFINE iclib ./ic_lib 3 W( R- c; Y4 X3 ~ASSIGN iclib TMP ./ic_tmp_lib...UNASSIGN iclib TMP ; F5 i, U- T6 P& {0 D38. -- can be used to check the content of the cds.lib # Q- o/ u# /5 k& w4 Q0 j% nchelp -cdslib 6 A8 {, W5 @9 }( {# C) H- s39. hdl.lib ; d' ]3 a# x0 J( y1 Y# fDEFINE WORK worklibDEFINE VERILOG_SUFFIX (.v, .vg, .vb)NCVLOGOPTS -messages -errormax 10 -update 1 O- G. l, i" B! q* N6 | U40. hdl.var% nchelp -hdlvar ; m3 H7 [' E _9 q; t8 a41. view & snapshot(1) The file mychip.v gets compiled into the default module view:worklib.mychip:module.It is created after compile, (ncvlog)(2) The elaborator generates a simulation snapshot for the design. * K+ I, j+ /5 C; a8 `) N" ZIntermediate objects created during the elaboration phase are stored in the .pak file.The snapshot is also a Lib.Cell:View. 9 q1 W" Y" S1 N; P. @3 y! Z9 p3 x+ }source =>(compile)=> module =>(elaborate) => snapshot => simulation, , M. /) R. `( g1.Verilog和Ncverilog命令使用库文件或库目录ex). ncverilog -f run.f -v lib/lib.v -y lib2 +libext+.v //一般编译文件在run.f中, 库文件在lib.v中,lib2目录中的.v文件系统自动搜索使用库文件或库目录,只编译需要的模块而不必全部编译2.Verilog Testbench信号记录的系统任务:1). SHM数据库可以记录在设计仿真过程中信号的变化. 它只在probes有效的时间内记录你set probe on的信号的变化.ex). $shm_open("waves.shm"); //打开波形数据库$shm_probe(top, "AS"); // set probe on "top",第二个参数: A -- signals of the specific scropeS -- Ports of the specified scope and below, excluding library cellsC -- Ports of the specified scope and below, including library cellsAS -- Signals of the specified scope and below, excluding library cellsAC -- Signals of the specified scope and below, including library cells还有一个M ,表示当前scope的memories, 可以跟上面的结合使用, "AM" "AMS" "AMC"什么都不加表示当前scope的ports;$shm_close //关闭数据库2). VCD数据库也可以记录在设计仿真过程中信号的变化. 它只记录你选择的信号的变化.ex). $dumpfile("filename"); //打开数据库$dumpvars(1, top.u1); //scope = top.u1, depth = 1第一个参数表示深度, 为0时记录所有深度; 第二个参数表示scope,省略时表当前的scope.$dumpvars; //depth = all scope = all$dumpvars(0); //depth = all scope = current$dumpvars(1, top.u1); //depth = 1 scope = top.u1$dumpoff //暂停记录数据改变,信号变化不写入库文件中$dumpon //重新恢复记录3). Debussy fsdb数据库也可以记录信号的变化,它的优势是可以跟debussy结合,方便调试.如果要在ncverilog仿真时,记录信号, 首先要设置debussy:a. setenv LD_LIBRARY_PATH :$LD_LIBRARY_PATH(path for debpli.so file (/share/PLI/nc_xl//nc_loadpli1))b. while invoking ncverilog use the +ncloadpli1 option.ncverilog -f run.f +debug +ncloadpli1=debpli:deb_PLIPtrfsdb数据库文件的记录方法,是使用$fsdbDumpfile和$fsdbDumpvars系统函数,使用方法参见VCD注意: 在用ncverilog的时候,为了正确地记录波形,要使用参数: "+access+rw", 否则没有读写权限3. ncverilog编译的顺序: ncverilog file1 file2 ....有时候这些文件存在依存关系,如在file2中要用到在file1中定义的变量,这时候就要注意其编译的顺序是从后到前,就先编译file2然后才是file2.4. 信号的强制赋值force首先, force语句只能在过程语句中出现,即要在initial 或者always 中间. 去除force 用release 语句.initial begin force sig1 = 1'b1; ... ; release sig1; endforce可以对wire赋值,这时整个net都被赋值; 也可以对reg赋值.我们知道,由于NC-Verilog使用了Native Compile Code 的技术来加强电路模拟的效率,因此在进行模拟时必须经过compile(ncvlog 命令)以及elaborate(ncelab命令)的步骤。