Verilog HDL 初步学习

Verilog HDL 初步学习

程序模块结构

1.模块端口定义
2.模块内容
i/o说明,信号类型说明,功能描述

模块端口定义

用来声明设计电路模块输入输出端口
module 模块名(端口1,端口2.,。。。)
包括全部输入输出信号

模块内容

1.i/o说明
输入(input),输出(output)和双向(inout)

2.信号类型说明
所用信号数据类型及函数声明。

1)连线型(wire)(默认):
逻辑单元物理连接,不保持电荷。用assign语句可进行赋值。
eg:wire [3:0] c;

2)寄存器型(reg) :
具有状态保持作用,能够存储数据,如触发器等。
用过程赋值语句(initial、always)进行赋值。
reg [3:0] c; // 定义4位名为c的reg型变量

3)wire和reg的区别
wire型数据需要有连续的驱动
reg型数据保存最后一次的赋值

3.功能描述:可以用assign语句、元件例化(instantiate)、always块语句、initial块语句等方法来实现,在电路上相当于器件的内部结构。

1) assign语句
一般用于对组合逻辑进行赋值
格式: assign 表达式;
一位全加器

module adder1 (cout, sum, a, b, cin);
  output  cout, sum;
  input   a, b, cin;
  
  assign  {cout, sum} = a + b + cin;
			// 功能描述语句
  
endmodule

默认的数据类型为wire(连线)型,{ }为拼接运算符,是将cout、sum这样两个1位操作数拼接为一个2位操作数。

2) 元件例化(instantiate)
元件例化方式建模是调用Verilog提供的元件库实现的,也叫门级建模。
器件的端口都有规定。
格式: 元件名 实例化名(输出端口,输入端口)

3) always语句
always语句常用于时序逻辑的功能描述。
一个模块中可以有多个always块,程序运行中,若条件满足,就重复执行always结构中的语句。
格式: always @ ( 敏感事件列表 )
语句块;
四位选择器

module mux41 (in0, in1, in2, in3, sel, out);
  input in0, in1, in2, in3;
  input [1:0]sel;
  output out;
  reg out;
//  always @(in1 or in2 or in3 or in0 or sel)
    always @(*)
    case (sel)
      2'b00: out = in0;
      2'b01: out = in1;
      2'b10: out = in2;
      2'b11: out = in3;
      default: out = 1'b0;
   endcase
endmodule

4) initial语句
和always语句块类似,一个模块中可以有多个initial块,程序运行中,只执行一次就结束了。
常用于测试模块对激励向量的描述,或给寄存器变量赋初值。

5)时延 #
语法格式: # <延迟时间> 行为语句;
# <延迟时间>;
举例:
# 10 ina = 1;
// 10个时间单位后,将1赋值给ina
# 5 inb = ina;
// 5个时间单位后,将ina的值赋值给inb

6)拼接运算符 { }

reg	[2:0]	a;
reg	[3:0]	b;
reg	[7:0]	c;
reg	[4:0]	d;
reg	[5:0]	e;
initial begin
	a = 3'b101;
	b = 4'b1110;
	c = {a, b};			// c = 8'b 0101_1110
	d = {a[2:1], b[2:0]};	// d = 5'b 10_110
	e = {2{a}};			// e = 6'b 101_101
end

7)数值

  1. 较长的数之间可以用下划线分开,提高可读性,但是下划线不能做首字符
    16’b 1001_0011_0111_0101

  2. 若定义的位宽比实际的位数大,则在左边补0
    8’b 101 等价于8’b 0000_0101

  3. 若定义的位宽比实际的位数大,最左边的位被舍去
    4’b 11_1010 等价于4’b 1010

  4. 二进制数’b 十六进制数’h
    16’b 1111_0000_0001_0010
    16’h f012

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Verilog HDL (Hardware Description Language) is a high-level hardware description language used to model, simulate, and synthesize digital circuits and systems. It is commonly used in the design of digital electronic systems, such as microprocessors, digital signal processors, and other digital circuits. Verilog HDL provides a powerful set of constructs to describe the behavior and structure of digital circuits. It allows designers to describe the functionality of a circuit in terms of logical operations, timing constraints, and other parameters. Verilog HDL is widely used in the design of integrated circuits and other digital systems. It is supported by most modern EDA (Electronic Design Automation) tools and is used by designers to create complex digital circuits and systems. Some of the key features of Verilog HDL include: 1. Hierarchical modeling: Verilog HDL supports hierarchical modeling, which allows designers to build complex systems by combining smaller building blocks. 2. Behavioral modeling: Verilog HDL supports behavioral modeling, which allows designers to describe the functionality of a circuit in terms of logical operations and other parameters. 3. Structural modeling: Verilog HDL supports structural modeling, which allows designers to describe the physical structure of a circuit. 4. Timing modeling: Verilog HDL supports timing modeling, which allows designers to specify timing constraints and other parameters that affect the behavior of a circuit. Overall, Verilog HDL is a powerful tool for designing and simulating digital circuits and systems. It is widely used in the electronics industry and is an essential skill for anyone working in digital design.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值