⭐本专栏针对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; endendmodule
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; endendmodule
行为形容:
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 endendmodule
Verilog HDL程序的根本构造
模块定义的个别语法结构如下:
module模块名(端口名1,端口名2,端口名3,…) ; 端口类型阐明(input, output, inout); 参数定义(可选); 数据类型定义(wire, reg等); 实例化低层模块和根本门级元件; 间断赋值语句(assign); 过程块构造(initial和always) 行为形容语句;endmodule
几种形容形式小结:
构造形容(门级形容)形式:
个别应用Primitive(外部元件)、自定义的上层模块对电路形容。次要用于层次化设计中。
数据流形容形式:
个别应用assign语句形容,次要用于对组合逻辑电路建模。
行为形容形式:
个别应用下述语句形容,能够对组合、时序逻辑电路建模。
- initial 语句
- always 语句
欢送关注集体公众号【AIShareLab】,一起交换更多相干常识,前沿算法,Paper解读,我的项目源码,面经总结。