当前位置:网站首页>第七章 行为级建模
第七章 行为级建模
2022-07-07 23:50:00 【江南小作坊】
第七章 行为级建模
前言
- Verilog支持设计者从算法的角度,即从电路外部行为的角度对其进行描述。行为级建模是从一个很高的抽象角度来表示电路。在这个层次上类似C语言,Verilog行为级建模的语法结构和C语言相当类似。
结构化过程语句
- 两种结构化的过程语句:
initial和always,行为级建模的基本语句。 - 与C语言不同,Verilog在本质上是并发非顺序的,即并发执行。
- 每个
initial和always语句代表一个独立的执行过程,每个执行过程从仿真时间0开始执行,两种语句不能嵌套使用。
initial
- 所有在
initial语句内的语句构成了一个initial块。initial块从仿真0时刻开始执行,整个仿真过程中只执行一次。 - 一个模块有多个
initial块,从仿真0开始,并发执行,每个块都是各自独立的。 - 块内有多条行为语句,需要给这些语句分组,使用
begin ... end将其组合为一个块语句;如果块内只有一条语句,则不必使用begin ... end。 - 举例说明

- 执行顺序

- initial块语句在整个仿真期间只能执行一次,因此它一般被用于初始化、信号监视、生成仿真波形等。
- 初始化方法
在变量声明的同时进行初始化

同时进行端口/数据声明和初始化

ANSI C风格端口声明初始化

always
always语句内的所有行为语句构成了一个always语句块,该语句块从仿真0时刻开始顺序执行其中的行为语句,在最后一条执行完成后,再次开始执行其中的第一条语句,如此循环往复,直至仿真结束。(总的有顺序语句吧,很合理。)always语句通常对电路中一组反复执行的活动进行建模,如时钟信号发生器,每半个时钟周期时钟信号翻转一次。现实电路中只要电源接通,时钟信号发生器从时刻0就有效,一直工作下去。- 举例说明

- 说明:clock信号放在initial语句中初始化,因此只初始化一次;如果放在always语句中,则每次执行always语句就会初始化一次,然后无休止的工作下去。执行停止的方式有断电(
$finish)和中断($stop)。
过程赋值语句
- 过程赋值语句的更新对象是寄存器、整数、实数或时间变量。这些类型的变量在被赋值后,其值保持不变,直到重新被赋值。
- 区别连续赋值语句:连续赋值语句总是处于活动状态,任意一个操作数的变化都会导致表达式的重新计算以及重新赋值,但是,过程赋值语句只有在执行到的时候才会起作用。
- Verilog包括两种类型的过程赋值语句:阻塞和非阻塞。
阻塞赋值
- 赋值符:
= - 阻塞语句按顺序执行,如果在一个begin end块中使用了阻塞赋值,那么这个块语句表现的是串行行为。
- 直接上例子

- 说明:
- 只有在语句x=0执行完成后,才会执行y=1,语句count=count+1按顺序在最后执行。
- x=0到reg_b=reg_a之间的语句是0时刻开始执行的(但是这里面是顺序的)。
- 15个时间单位,开始执行reg_a[2]。
- 25个时间单位,执行reg_b[15:13]。
- 语句count=count+1也是25个时间单位的时候执行。
- 还有就是寄存器变量赋值时,左右位宽不等的情况下,左边宽,则高位补0;右边宽则把超过左边位宽的高位丢弃。
非阻塞赋值
- 赋值符:
<= - 在表达式中,作为关系运算符;在非阻塞环境下,作为非阻塞赋值。
- 上例子

- 说明:
- 仿真器将阻塞赋值调度到相应的时刻,然后继续执行后面的语句,并没有停下来等赋值完成。
- 不要在同一个always块中混合使用阻塞和非阻塞赋值语句。
- 应用:可以用来为常见的硬件电路行为建模,如某一事件发生后,多个数据并发传输的行为。

- 避免竞争

- 可以用阻塞来实现非阻塞

- 总结
- 如果某事件发生后将产生多个数据的并发传输,建议使用非阻塞描述。
- 非阻塞的典型应用包括:流水线建模、多个互斥数据传输的建模。
- 非阻塞的问题:仿真速度的下降、内存使用量增加。
时序控制
基于延迟
基于事件
电平敏感
条件语句
多路分支语句
多路分支
casex和casez
循环语句
while循环
for循环
repeat循环
forever循环
顺序块和并行块
块语句类型
块语句特点
生成块
循环生成语句
条件生成语句
case生成语句
举例
四选一多路选择器
四位计数器
交通信号灯控制器
小结
边栏推荐
- General configuration title
- Common fault analysis and Countermeasures of using MySQL in go language
- common commands
- QT build with built-in application framework -- Hello World -- use min GW 32bit
- 2022 safety officer-c certificate examination paper and safety officer-c certificate simulated examination question bank
- Generic configuration legend
- Continued from the previous design
- Write a pure handwritten QT Hello World
- The combination of relay and led small night light realizes the control of small night light cycle on and off
- qt-使用自带的应用框架建立--hello world--使用min GW 32bit
猜你喜欢

QT -- package the program -- don't install qt- you can run it directly
Common fault analysis and Countermeasures of using MySQL in go language

Application of state mode in JSF source code

redis的持久化方式-RDB和AOF 两种持久化机制

2022 high altitude installation, maintenance and demolition examination materials and high altitude installation, maintenance and demolition operation certificate examination

The Ministry of housing and urban rural development officially issued the technical standard for urban information model (CIM) basic platform, which will be implemented from June 1

滑环使用如何固定

Kindle operation: transfer downloaded books and change book cover

2022 high voltage electrician examination skills and high voltage electrician reexamination examination

Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
随机推荐
滑环使用如何固定
5. Discrete control and continuous control
Macro definition and multiple parameters
Four digit nixie tube display multi digit timing
2021-04-12 - new features lambda expression and function functional interface programming
解决报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
A little experience from reading "civilization, modernization, value investment and China"
AttributeError: ‘str‘ object has no attribute ‘strftime‘
4. Apprentissage stratégique
2、TD+Learning
子矩阵的和
The examination contents of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge) in 2021 and the free examination questions of the third batch of Guangdong Prov
How does Matplotlib and PIL image integrate and save multiple pictures into one picture
4、策略學習
npm 内部拆分模块
About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware
GBASE观察 | 数据泄露频发 信息系统安全应如何守护
About snake equation (2)
Arm bare metal
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination