没有合适的资源?快使用搜索试试~ 我知道了~
首页组合-时序逻辑电路Verilog-Testbench代码_带仿真代码和波形_
组合-时序逻辑电路Verilog-Testbench代码_带仿真代码和波形_
需积分: 50 40 下载量 7 浏览量
更新于2023-06-25
1
收藏 1.03MB PDF 举报
组合-时序逻辑电路Verilog-Testbench代码_带仿真代码和波形_
资源详情
资源推荐
1 组合逻辑电路--基本门电路
1.1 基本门电路
1.1.1 结构化描述方式
代码如下
View Code
1 module logics
2 (
3 input iA,
4 input iB,
5 output oAnd,
6 output oOr,
7 output oNot
8 );
9
10 and and_inst(oAnd,iA,iB);
11 or or_inst(oOr,iA,iB);
12 not not_inst(oNot,iA);
13
14 endmodule
最底层的是门级原语 and or not
RTL 级视图
testbench 如下
View Code
1 `timescale 1 ns/ 1 ns
2 module logics_tb();
3
4 reg ia;
5 reg ib;
6
7 wire oAnd;
8 wire oOr;
9 wire oNot;
10
11 initial
12 begin
13 ia=0;
14 #40 ia=1;
15 #40 ia=0;
16 #40 ia=1;
17 #40 ia=0;
18 end
19
20 initial
21 begin
22 ib=0;
23 #40 ib=0;
24 #40 ib=1;
25 #40 ib=1;
26 #40 ib=0;
27 end
28
29 logics logics_inst
30 (
31 .iA(ia),
32 .iB(ib),
33 .oAnd(oAnd),
34 .oOr(oOr),
35 .oNot(oNot)
36 );
37
38 endmodule
RTL 级仿真图形如下
GATE 级仿真图如下
可见 RTL 级仿真是理想的,GATE 级仿真考虑了延迟和信号开始的不确定。
1.1.2 采用流描述方法
代码如下
View Code
1 module logics
2 (
3 input iA,
4 input iB,
5 output oAnd,
6 output oOr,
7 output oNot
8 );
9
10 assign oAnd=iA&iB;
11 assign oOr=iA|iB;
12 assign oNot=~iA;
13
14 endmodule
RTL 级视图,仿真图形同上。
1.1.3 采用行为描述方式
代码如下
View Code
1 module logics
2 (
3 input iA,
4 input iB,
5 output reg oAnd,
6 output reg oOr,
7 output reg oNot
8 );
9
10 always @(*)
11 begin
12 oAnd=iA&iB;
13 oOr=iA|iB;
14 oNot=~iA;
15 end
16
17 endmodule
always@()括号内的敏感信号填*,则综合器自动加上敏感信号。
由于 always 语句中左边信号都要是寄存器型,故输出信号定义为寄存器型。描述组合逻辑时,
always 中使用阻塞赋值方式。
RTL 级视图及仿真图形同上。
2 组合逻辑电路--多路选择器与多路分解器
1.2 多路选择器
1.2.1 不带优先级的多路选择器
四路选择器如下
代码如下
View Code
1 module multiplexer
2 (
3 input iA,
4 input iB,
5 input iC,
6 input iD,
7 input [1:0] iSel,
8 output reg oQ
9 );
10
11 always @(*)
12 begin
13 case(iSel)
14 2'b00 : oQ=iA;
15 2'b01 : oQ=iB;
16 2'b10 : oQ=iC;
17 2'b11 : oQ=iD;
18 endcase
19 end
20
21 endmodule
case 语句如果没有全部包含所有的情况,则一般要用 default 语句将信号默认赋值为 0,否则
会出现锁存器,使得仿真结果不一致。
RTL 级视图如下:
testbench 如下
View Code
1 `timescale 1 ns/ 1 ns
2 module logics_tb();
3
4 reg ia;
5 reg ib;
6
7 wire oAnd;
8 wire oOr;
9 wire oNot;
10
11 initial
12 begin
13 ia=0;
14 #40 ia=1;
15 #40 ia=0;
16 #40 ia=1;
17 #40 ia=0;
18 end
19
20 initial
21 begin
22 ib=0;
23 #40 ib=0;
24 #40 ib=1;
剩余28页未读,继续阅读
luoweilai
- 粉丝: 2
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功