共计 1789 个字符,预计需要花费 5 分钟才能阅读完成。
⭐本专栏针对 FPGA 进行入门学习,从数电中常见的逻辑代数讲起,联合 Verilog HDL 语言学习与仿真,次要对组合逻辑电路与时序逻辑电路进行剖析与设计,对状态机 FSM 进行分析与建模。
🔥本文已收录于 MySQL 系列专栏:FPGA 欢送订阅,继续更新。
🔥文章和代码已归档至【Github 仓库】,须要的敌人们自取。或者关注公众号【AIShareLab】,回复 FPGA 也可获取。
简略 Verilog HDL 程序实例
Verilog 应用大概 100 个预约义的关键词定义该语言的构造
- Verilog HDL 程序由模块形成。每个模块的内容都是嵌在两个关键词 module 和 endmodule 之间。每个模块实现特定的性能。
- 每个模块先要进行端口的定义,并阐明输出(input)、输入(output) 和双向(inout),而后对模块性能进行形容。
- 除了 endmodule 外,每个语句后必须有英文的分号 (;)。
- 能够用 / — / 和 //…..,对 Verilog HDL 程序的任何局部做正文。
半加器程序实例
/* Gate-level description of a half adder */ | |
module HalfAdder_GL(A, B, Sum, Carry); | |
input A ,B ; // 输出端口申明 | |
output Sum, Carry ; // 输入端口申明 | |
wire A ,B , Sum ,Carry ; | |
xor X1 (Sum, A, B); | |
and A1 (Carry, A, B); | |
endmodule |
/* Dataflow description of a half adder */ | |
module HalfAdder_DF(A, B, Sum, Carry); | |
input A ,B ; | |
output Sum ,Carry ; | |
wire A ,B,Sum ,Carry ; | |
assign Sum = A ^ B; | |
assign Carry = A & B; | |
endmodule |
/* Behavioral description of a half adder */ | |
module HalfAdder_BH(A, B, Sum, Carry); | |
input A ,B ; | |
output Sum ,Carry ; | |
reg Sum ,Carry ; // 申明端口数据类型为寄存器 | |
always @(A or B) begin | |
Sum = A ^ B; // 用过程赋值语句形容逻辑性能 | |
Carry = A & B; | |
end | |
endmodule |
2 选 1 数据选择器的程序实例
module mux2to1(a, b, sel, out); | |
input a, b, sel; // 定义输出信号 | |
output out; // 定义输入信号 | |
wire selnot,a1,b1; // 定义外部节点信号数据类型 | |
// 上面对电路的逻辑性能进行形容 | |
not U1(selnot, sel); | |
and U2(a1, a, selnot); | |
and U3(b1, b, sel); | |
or U4(out, a1, b1); | |
endmodule |
module mux2_1(out, a, b, sel) ; | |
output out; | |
input a, b; | |
input sel; | |
reg out; | |
always @(sel or a or b) | |
begin | |
if (sel) | |
out = b; | |
else out = a; | |
end | |
endmodule |
行为形容:
module mux2_1(out, a, b, sel) ; | |
output out; | |
input a, b; | |
input sel; | |
reg out; | |
always @(sel or a or b) | |
begin | |
case (sel) | |
1’b0 : out = a; | |
1’b1 : out = b; | |
endcase | |
end | |
endmodule |
Verilog HDL 程序的根本构造
模块定义的个别语法结构如下:
module 模块名 (端口名 1,端口名 2,端口名 3,…) ; | |
端口类型阐明 (input, output, inout); | |
参数定义 (可选); | |
数据类型定义 (wire, reg 等); | |
实例化低层模块和根本门级元件; | |
间断赋值语句 (assign); | |
过程块构造 (initial 和 always) | |
行为形容语句; | |
endmodule |
几种形容形式小结:
构造形容(门级形容)形式:
个别应用 Primitive(外部元件)、自定义的上层模块对电路形容。次要用于层次化设计中。
数据流形容形式:
个别应用 assign 语句形容,次要用于对组合逻辑电路建模。
行为形容形式:
个别应用下述语句形容,能够对组合、时序逻辑电路建模。
- initial 语句
- always 语句
欢送关注集体公众号【AIShareLab】,一起交换更多相干常识,前沿算法,Paper 解读,我的项目源码,面经总结。
正文完