VHDL

VHDL

1. 基本结构

实体(entity),结构体(architecture),配置(configuration),库(library),程序包(package)。

library ieee;  --库
use ieee.std_logic_1164.all;   --程序包调用
entity mux21 is            --实体描述开始
	port( a,b:in bit;      
		  s:in bit;
		  y:out bit);
end entity mux21;          --实体描述结束

architecure behavior of mux21 is     --结构体描述开始
signal d,e:bit;    --d,e为内部定义的信号
	begin
		d<=a and (not s);
		e<=b and s;
		y<=d or e;
	end architecture behavior;      --结构体描述结束

信号赋值: <=

注释 : –

1.1 实体

entity 实体名 is
	类属参数说明
	端口说明
end 实体名

类属参数(generic)说明必须放在端口说明之前用于指定参数大小,实体中子元件的数目及实体的定时特性。

generic(m:time:=1ns);

端口

port(端口名:方向  数据类型;
	   ...
	 端口名:方向  数据类型);

端口模式有四种:in,out,inout(双向模式),buffer(缓冲模式,允许内部反馈)

1.2 结构体

architecure 结构体名 of 实体名 is
	定义语句
	begin
	并行处理语句
	end 结构体名;

结构体的描述方法也称为描述风格,有行为描述、数据描述和结构描述。

1.3 库和程序包

常用库:IEEE,STD,WORK和用户自定义库。

ieee.std_logic_1164定义了常用的数据类型和函数。

使用std.standard不需要说明,std.textio需要。


程序包由程序包说明和程序包体组成。

程序包说明的一般形式如下:

package 程序包名 is
	[说明部分];
	end 程序包名;

包体的一般形式如下:

package body 程序包名 is
	[说明部分];
	end 程序包名;

3个常用预定义程序包:

std_logic_1164

std_logic_arith

std_logic_unsigned和std_logic_signed

都在ieee库中。调用

library 库名;
use 程序包;

1.4 配置

一个实体具有多个结构体时,可以使用配置语句为实体选定某个结构体。

configuration conf1 of fulladder is
for behavior
end for;
end conf1;

它选择实体fulladder的结构体bahavior。

2 基本语法

2.1 数据对象

vhdl数据对象:信号、变量和常量。

信号

signal 信号名:信号类型[:=初始值];
eg.
signal a:std_logic='0';

信号赋值 信号名<=表达式


变量

variable 变量名:数据类型[:=初始值];
eg.
variable a,b:bit;

变量赋值 变量名:=表达式


常量

constant 常量名:类型名[:=取值];
eg.
constant delay:time:=25ns

2.2 数据类型


标准数据类型

数据类型含义
bit位型数据,0,1
bit_vector位矢量型,多个位型数据组合
integer整型, − ( 2 31 − 1 ) -(2^{31}-1) (2311) ~ + ( 2 31 − 1 ) +(2^{31}-1) +(2311)
boolean布尔型,true和false
real实型, − 1.0 e 38 -1.0e^{38} 1.0e38~ 1.0 e 38 1.0e^{38} 1.0e38
character字符型 , ‘A’
string字符串,“asdffs”
time整数+空格+单位,10 ns
severity level错误等级类型(4种),note,warning,error,failure.
natural和positive自然数类型 和 正整数类型

ieee.std_logic_1164的两种常用类型:

std_logic,工业标准逻辑型,9种值:初始值’U’,不定值’X’,逻辑‘1’和‘0’,高阻‘Z’,弱信号不定’W’,弱信号零’L’,弱信号一’H’,不可能情况’-’。

std_logic_vector:标准逻辑矢量型,多个std_logic的组合。


用户自定义数据类型

type 数据类型名 is [数据类型定义];

常用 枚举类型、整数类型、实数类型、数组类型、物理类型、记录类型。

枚举类型

type 数据类型名 is (元素1,...,元素n);

数组类型

type  数据类型名 is array(范围) of 原数据类型名、
eg.
type word is array(1 to 8) of std_logic;

range<>表示一个没有范围限制的数组。

物理类型

type 数据类型名 is 范围
	units 基本单位;
		单位条目;
	end units;

记录类型

type 数据类型名 is record
	元素名:数据类型名;
	...
	元素名:数据类型名;
end record;

2.3 运算操作符

4种:逻辑运算符,关系运算符,算术运算符,并置(连接)运算符。


逻辑运算符

not,and,or,nand(与非),nor(或非),xor(异或)。


算术运算符

±*/,mod(求模),rem(取余)、**(指数),abs(绝对值)。


关系运算符(6种)

=,/=(不等于),<,<=,>,>=。


并置(连接运算符)

&,用来形成位矢量或数组组合。

3 描述语句

3.1 并行描述语句

3.1.1 并行信号赋值语句

简单信号赋值语句

条件信号赋值语句

选择信号赋值语句

with 选择表达式 select
赋值目标<=表达式 when 选择值,
               ...
         表达式 when 选择值;
3.1.2进程语句
[进程名]:process(进程敏感信号列表)
begin 
	顺序描述语句;
end process
3.1.3 元件例化语句

元件声明

compoment 元件实体名
	port (元件端口信息);
end compoment 元件实体名;

元件例化

例化名:元件名 port map(端口列表)

端口列表接口格式

[例化元件端口=>]连接实体端口

三种接口格式

名字关联方式,位置关联方式,混合关联方式。

3.2 顺序描述语句

3.2.1 信号和变量的赋值
3.2.2 if
3.2.3 case
3.2.4 wait

wait on

wait until

wait for

复合wait

3.2.5 loop

for

while

3.2.6 next和exit
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值