一、Verilog编程练习
1.1 门电路
1.1.1 两个门
module top_module (
input in1,
input in2,
input in3,
output out);
1.1.2 多逻辑门
module top_module(
input a, b,
output out_and,
output out_or,
output out_xor,
output out_nand,
output out_nor,
output out_xnor,
output out_anotb
);
1.1.3 与门
module top_module(
input a,
input b,
output out );
assign out=a&b;
endmodule
1.2 组合电路
1.2.1 2 1多用复合电路
module top_module(
input a, b, sel,
output out );
endmodule
1.2.2 21总线多路复用器
module top_module(
input [99:0] a, b,
input sel,
output [99:0] out );
endmodule
1.2.3 91多路复用器
module top_module(
input [15:0] a, b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );
endmodule
1.3 时序电路
1.3.1 D触发
module top_module (
input clk, // Clocks are used in sequential circuits
input d,
output reg q );//
// Use a clocked always block
// copy d to q at every positive edge of clk
// Clocked always blocks should use non-blocking assignments
endmodule
1.3.2 D锁存
module top_module (
input d,
input ena,
output q);
endmodule
1.3.3 四位二进制计数器
module top_module (
input clk,
input reset, // Synchronous active-high reset
output [3:0] q);
endmodule
二、Robei软件安装
2.1 安装准备
2.1.1 下载地址
2.1.2 一直点next就行了。
2.1.3 注册(可以不搞)
2.2 初次使用
2.2.1 主界面
2.2.2 Robei三元素
- 模块:
模块是设计流程中的基本元素,可以看作一个黑盒子。用于存放设计好的模型和输入实现模块功能的算法代码以及引脚信息。 - 引脚:
引脚是模块的门户,是模块与外界通信的接口。包括输入与输出两种类型。 - 连接线:
连接线是用来连接两个引脚,负责信号的传输。
2.2.3 与门设计
原理:
直接进入正题,新建文件
属性设置:当点击了引脚之后右侧会弹出引脚属性栏。
输入代码:assign y = a & b;
保存:点击保存选择文件保存位置
注意:
- 保存的路径中不能含有中文和空格
- 保存文件名不能以数字和特殊字符开头
- 相关的文件要保存在同一路径下
- 保存的文件名会显示成当前设计的模块名称
- 命名时不能命名成 verilog 的关键字,如“module”,“if” 等
2.2.4 测试文件设计
新建一个文件命名为andtest,和上面一个项目放在一起。
点击左边current中的模组,添加到andtest中(我把first重新命名为andgate)了,连线,输入代码。
开始仿真,这里编译可能会有几个错误:
可参照下图改正:
最后得到仿真波形
三、资料引用
7天学会Robei.pdf
提取码:uxru
HDLBits — Verilog Practice
HDLBits 中文导学