8-25 26 veriloga语言

找了一些veriloga的资料。
主要是veriloga官方手册《Cadence®Verilog®-A Language Reference》

1.基尔霍夫定律撑起了整个电路学的大厦(当然也可以认为基尔霍夫定律只是麦克斯韦方程的简化版),作为模拟电路描述语言Verilog-A,同样将基尔霍夫定律作为其基本,最重要的两个概念便是流量(Flow)和位(Potential),在电学里是电流和电压,在力学里可以是力和距离,在热学里可以是功率和温差,等等。
KCL:基尔霍夫第一定律又称基尔霍夫电流定律,简记为KCL,是电流的连续性在集总参数电路上的体现,其物理背景是电荷守恒公理。基尔霍夫电流定律是确定电路中任意节点处各支路电流之间关系的定律,因此又称为节点电流定律。(一个节点处,输入的=输出的)
KVL:

2.在Verilog-A中,你可以将电阻电容电感等器件用一个方程式来表述,比如I(out) <+ V(out)/R,这样就产生了一个电阻,最后Verilog-A仿真器会用某种算法(迭代是最常见的)将I(out)和V(out)求解出来,然后根据这个解去算下一个时刻的I、V等,当然这仅仅是指时域仿真。

使用Verilog-A,可以创建和使用描述组件和系统的高级行为的模块。它使用模块来描述模拟系统及其组件的结构和行为。利用Verilog-A的模拟陈述,你可以描述范围广泛的保守系统和信号流系统,如电气、机械、流体动力学和热力学系统。
在这里插入图片描述
一部分是接口声明,一部分是行为描述。与verilog是有一定相似的。

1.创建模块

module 名字 (模块端口)
endmodule
module res(p, n) ;
inout p, n ;
electrical p, n ;
parameter real r = 0 ;

声明一个名为res的模块、一个名为p和n的端口以及一个名为r的参数。

2.关于端口
input 声明不能设置端口上的信号,尽管可以在表达式中使用它们。
output 声明端口上的信号可以设置,但不能在表达式中使用。
inout 声明该端口是双向的。端口上的信号可以在表达式中设置和使用。inout是默认的端口方向。

module gainer (out, pin) ;  // Declares two ports
output out ;  // Declares port as output
input pin ;  // Declares port as input
voltage out, pin ;  // Declares type of ports
parameter real gain = 2.0 ;
analog
V(out) <+ gain * V(pin) ;
endmodule

module gainer 有两个端口:输出和引脚。输出端口是用output的方向声明的,这样它的值就可以被设置。引脚端口是用input的方向声明的,这样它的值就可以被读取。

3.关于参数
在这里插入图片描述
每个参数,必须指定一个默认值。
module sdiode有一个参数area,默认值为1。如果没有为实例指定area,则它将收到一个值1。类似地,其他参数,is, n, cjo, m, phi,和tt,也有指定的默认值。
module sdiode还定义了三个局部变量:vd、id和qd。

4.定义模块模拟行为
以analog开始

module am(in1, in2, outsum, outmult) ;
input in1, in2 ;
output outsum, outmult ;
voltage in1, in2, outsum, outmult ;
analog begin
V(outsum) <+ V(in1) + V(in2) ;
V(outmult) <+ V(in1) * V(in2) ;
end
endmodule

声明完以后,用analog开始模拟。两条语句。

5.定义具有控制流的模拟行为
带有if,else的。

module vdba(in, out);
input in ;
output out ;
electrical in, out ;
parameter real vin_low = -2.0 ;
parameter real vin_high = 2.0 ;
parameter real gain = 1 from (0:inf) ;
analog begin
if (V(in) >= vin_high) begin
V(out) <+ gain*(V(in) - vin_high) ;
end else if (V(in) <= vin_low) begin
V(out) <+ gain*(V(in) - vin_low) ;
end else begin
V(out) <+ 0 ;
end
end
endmodule

5.积分微分
Verilog-A提供了一个时间导数函数ddt和两个时间积分函数idt和idtmod。

analog
V(p, n) <+ ddt(L * I(p, n)) ;
analog begin
V(diff) <+ ddt(V(in)) ;
V(out) <+ ddt(V(diff)) ;
end
analog begin
V(out) <+ idt(V(in), 0) ;
end

idt为积分,第二项为初始条件。
6.模块中使用内部节点

module rlc_behav(in, out, ref) ;
inout in, out, ref ;
electrical in, out, ref ;
parameter real R=1, L=1, C=1 ;
electrical n1 ;
analog begin
V(in, n1) <+ R*I(in, n1) ;
V(n1, out) <+ L*ddt(I(n1, out)) ;
I(out, ref) <+ C*ddt(V(out, ref)) ;
end
endmodule

module rlc_behav使用内部节点n1和端口in, ref, and out,直接定义RLC电路的行为特征。注意,n1没有出现在模块的端口列表中。
7.numbers
veriloga支持实数和整数。
在这里插入图片描述

277195000
277_195_000  //Same as the previous number
-634  //A negative number
0005

2.5K  // 2500
1e-6  // 0.000001
-9.6e9
-1e-4
0.1u
50p  // 50 * 10e-12
1.2G  // 1.2 * 10e9
213_116.223_642

8.数据类型和对象
(1)Integer Numbers
例:

integer a[1:64] ;  // Declares array of 64 integers
integer b, c, d[-20:0] ;  // Declares 2 integers and an array
parameter integer max_size = 15 from [1:50] ;
integer cur_vector[1:max_size] ;
/* If the max_size parameter is not overridden, the
previous two statements declare an array of 15 integers. */

(2)Real Numbers
例:

real a[1:64] ;  // Declares array of 64 reals
real b, c, d[-20:0] ;  // Declares 2 reals and an array of reals
parameter integer min_size = 1, max_size = 30 ;
real cur_vector[min_size:max_size] ;

(3)Parameters
例:

parameter integer subord = 8 ;
parameter integer superior = 3 * subord ;

参数是常量,不能在运行时更改参数的值。但是可以通过在编译期间更改参数值来定制模块实例。
(4)Natures
使用属性声明将属性集合定义为属性。性质的属性表征了在模拟过程中求解的模拟量。
例:

nature Mycurrent
units = "A" ;
access = I ;
idt_nature = charge ;
abstol = 1e-12 ;
huge = 1e6 ;
endnature

代码通过指定五个属性来声明当前属性。根据语法要求,与每个属性关联的表达式必须是常量表达式。
(5)Disciplines
在顶层声明一个纪律,不能将规程声明嵌套在其他规程、性质或模块声明中。
例:

discipline electrical
potential Voltage ;
flow Current ;
enddiscipline

(6)Disciplines的兼容
在这里插入图片描述

nature Voltage
access = V ;
units = "V" ;
abstol = 1u ;
endnature
nature Current
access = I ;
units = "A" ;
abstol = 1p ;
endnature
discipline emptydis
enddiscipline
discipline electrical
potential Voltage ;
flow Current ;
enddiscipline
discipline sig_flow_v
potential Voltage ;
enddiscipline

electrical和sig_flow_v具有相同的性质,都为potential。里面定义的内容不一样。

nature Position
access = x ;
units = "m" ;
abstol = 1u ;
endnature
nature Force
access = F ;
units = "N" ;
abstol = 1n ;
endnature
discipline mechanical
potential Position ;
flow force ;
enddiscipline

postion的nature和voltage的nature不一样。
electrical 和 mechanical的 disciplines不相容。
这俩的 natures 都是potential. Take the Yes branch.
Position nature 与 Voltage nature不完全相同. Take the No branch
(7)Net Disciplines
未声明范围的网称为标量网。用范围声明的网称为向量网。

magnetic inductor1, inductor2 ;  // Declares two scalar nets
electrical [1:10] node1 ;  // Declares a vector net
wire [3:0] connect1, connect2 ;  // Declares two vector nets
discipline emptydis
enddiscipline
module comp1 (out, in, unknown1, unknown2) ;
output out ;
input in ;
electrical out, in ;
emptydis unknown1 ;  // Declared with an empty discipline
analog
V(out) <+ 2 * V(in)
endmodule

模块comp1有四个端口:out、in、unknown1和unknown2。模块声明out和in作为电子端口,并使用他们在模拟块。端口unknown1是用空规则声明的,不能在模拟块中使用,因为没有办法访问它的信号。但是,unknown1可以在端口列表中使用,它从连接到它的模块实例的端口继承属性。unknown2出现在端口列表中,而没有在模块主体中声明,所以Verilog-A隐式地将unknown2声明为带有默认规则的标量端口。默认规程类型是wire。

module five_inputs( portbus );
input [0:5] portbus;
electrical [0:5] portbus;
real x;
analog begin
generate i ( 0,4 )
V(portbus[i
  • 61
    点赞
  • 273
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值