第二章 VHDL语言程序的基本结构

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
注:该命名规则适用于实体、端口、信号、变量、文件的命名
12
(2) 端口方向:定义外部引脚的信号方向是输入还是 输出 。
端口方向 含义 示意图
输入端口(in)
输出端口(out) 缓冲端口(buffer)
仅允许信号从端口输 入到构造体
仅允许信号从构造体 内经端口输出
用于输出及构造体内 部反馈 可作为in\out\buffer使 双向端口(inout) 用

18
3) 定义语句位于is--begin 之间 :
type declarations; signal declarations; constant declarations; component declarations; function definitions; procedure definitions; 类型说明 信号说明 常量说明 元件说明 函数说明 过程说明
architecture dataflow of mux is signal q0,q1:bit; begin q0 <= d0 and sel; q1 <= not sel and d1; q <= q0 or q1; end architecture dataflow;
20
entity mux is port(d0,d1,sel: in bit; q: out bit); end entity mux;
例:architecture beh of mux2_1 is signal nes1 : bit; --内部连接信号无须说明方向 … begin … end architecture beh;
19
4) 并行处理语句

begin--end 之间语句部分是各种并行语句,具体地描 述构造体的行为及其连接关系,各语句处于并列状态, 执行时不分先后次序 。
25
2) 块和子原理图的关系
26
3) 块内语句的并发性
begin到end block cale之间的语句为并发执行语句。 4) 卫式块(guarded block) 实现块的执行控制:当某种条件满足时,块语句执 行;否则,块语句不执行。 格式: block [卫式布尔表达式]
注意:卫式块不能进行逻辑综合!
存放已经编译的包集合、实体、构造 体和配置。
声明在实体中将用到的常数定义、数 据类型、函数定义和过程定义等。 定义所设计电路系统的外部接口。 描述电路内部的功能。一个实体可以 对应很多个构造体,但在同一时间, 只有一个构造体被使用。
5.配置(Configuration) 决定哪一个构造体被使用。
3
2.1 VHDL语言设计的基本单元及其构成
8

VHDL语言不区分大小写;

除了第一行 entity … is 以外,每一句以分号 “;”结束 ;
编写程序时,一行可以含若干句(以分号间隔), 一句也可以写若干行; 在一句结束后,可以在“--”符号后接说明文字, 有助于理解程序,不会对编译产生影响; 单词之间必须使用空格; 并列信号间使用逗号; 根据不同的层次关系最好设定不同的缩进。
23
2.2 VHDL语言构造体的子结构描述

一个构造体可以用几个子结构来构成,即使用 相对比较独立的几个模块来构成。VHDL有以 下三种形式的子结构描述语句:
块(block)语句结构; 进程(process)语句结构;


子程序(subprograms)语句结构。
过程(procedure)语句 函数(function)


VHDL语言程序是用于描述硬件连接的结构性程 序,采用文本文件编写。 硬件电路模块具有外部接口和内部结构。

VHDL用程序模块表达硬件模块:设定外部端口、 设计内部结构。 4
input1
output1
Entity
inputn
Symbol
outputn
实体说明部分:规 VHDL 语 言 程 定设计单元的输入 序设计的基本 输出接口信号或引 单元由实体说 脚;它对应于电路 明 外观图。 (Entity
10
3)端口说明格式:
端口说明是对基本设计实体(单元)与外部接 口的描述,也可以说是对外部引脚信号的名称, 数据类型和输入、输出方向的描述。
port (端口名[,端口名]:方向 数据类型名;
……
端口名[,端口名]:方向 数据类型名);
注:port为关键字
11
端口说明语法要点
(1) 端口名是赋予每个外部引脚的名称; 命名规则: 英文字母和数字构成,字母开头; 可在名称中使用单个下划线符号_; 字母不分大小写; 名称应具有意义,方便记忆; 名称不能重复使用; VHDL中的关键字保留字不能用做名称。
22
练习
编写一个n选1数据选择器的实体说明,n在类属参数 说明中设定,数据类型为整型integer,设n=4,输入 输出端口数据类型使用std_logic 和std_logic_vector。
library ieee; use ieee.std_logic_1164.all; entity kmux_n is generic (n:integer :=4; m:integer :=2); port (din : in std_logic_vector (n-1 downto 0); sel : in std_logic_vector (m-1 downto 0); y : out std_logic); end entity kmux_n;
9



2)类属参数说明格式:
generic([类属常量名:类型 [:=静态表达式]; …… [类属常量名:类型 [:=静态表达式]);

要点:
(1) 类属说明必须在端口说明之前,为设计实体和外 部环境提供静态数据传输通道;
(2) generic 为关键字,静态表达式为可选项; (3) 示例: generic(m: time :=1 ns); q<=tmp after m;
路原理图。
5
clrቤተ መጻሕፍቲ ባይዱ
二选一电路的VHDL语言描述
实 体 说 明
entity mux is generic(m: time :=1 ns); port(d0,d1,sel: in bit; q: out bit); end entity mux; architecture connect of mux is signal tmp: bit; begin cale:process(d0,d1,sel) is variable tmp1,tmp2,tmp3: bit; begin tmp1:=d0 and sel; tmp2 :=d1 and (not sel); tmp3 :=tmp1 or tmp2; tmp<=tmp3; q<=tmp after m; end process; 7 end architecture connect;
并行语句
块语句:由一系列并行语句组成,从形式上划分出 模块,改善程序的可读性。 进程语句:进程内部为顺序语句,而不同进程间则 是并行执行的,进程只有在某个敏感信号发生变化 时才会触发。 子程序调用:调用过程或函数,并将获得的结果赋 给信号。 信号代入语句:将实体内的处理结果向定义的信号 或端口进行赋值。 元件例化语句:调用其他设计实体描述的电路,将 其作为本设计实体的一个元件,元件例化是实现层 次化设计的重要语句。
21
练习
为3-8线译码器编写实体说明
library ieee; use ieee.std_logic_1164.all; entity kdecoder38 is port (din: in std_logic_vector(2 downto 0); en: in std_logic; dout: out std_logic_vector(7 downto 0)); end entity kdecoder38;
构 造 体 定 义
1. 实体说明
1) 实体说明的基本格式:
entity 实体名 is [类属参数说明];--确定局部常量或实体时限 [端口说明]; --确定输入/输出端口数量及类型 end entity 实体名; entity mux is generic (m: time :=1 ns); port (d0,d1,sel: in bit; q: out bit); end entity mux;
15

实 体 说 明 示 例
例2-1 entity mu is port(d0,d1,sel : in bit; q : out bit; bus : out bit_vector(7 downto 0)); end mu; 例2-2 library ieee; use ieee.std_logic_1164.all; entity mu is port(d0,d1,sel : in std_logic; q : out std_logic; bus : out std_logic _vector(7 downto 0)); end mu; 16
27
entity latch is port(d, clk : in bit; q, qb : out bit); end entity latch;
卫 式 块 举 例
Architecture
Schematic
a b c d sel
2
D Q
mux_out
clk
ENA CLRN
Declaration) 和 构造体定义部分: 构 造 体 定 义 定义设计单元的具 (Architecture 体 构 造 和 操两 ( 行 Definition) 作 部 为);它对应于电 分构成。
2. 构造体(结构体)

具体指明基本设计单元的行为、元件及内部的连接 关系,也就是说它定义了设计单元具体的功能 。
1) 构造体的基本格式:
architecture 构造体名 of 实体名 is
[定义语句];--内部信号、常数、数据类型、函数等的定义
begin [并行处理语句];--构造体中所有语句同时执行,不以书写 顺序为执行顺序 end architecture 构造体名;
13
14
(3) 端口数据类型

所有端口都必须规定其数据类型,VHDL语言中 有10种数据类型,在数字电路设计中最常用的类 型为:bit 和 bit_vector 。 Bit:单个逻辑量 Bit_vector:逻辑数组、总线逻辑量 在VHDL语言的标准库IEEE库当中的包集合 std_logic_1164提供的std_logic和std_logic_vector 分别与bit和bit_vector对应,完全等效。只是在使 用时要声明使用了该包集合。下面给出一个例子。
第二章 VHDL语言 程序的基本结构
1
本章内容:

VHDL语言设计的基本单元及其构成

VHDL语言构造体的子结构描述
块语句
进程语句
子程序语句

包集合、库及配置
2
完整VHDL语言程序结构
1.库(Library)
2.包(Package) 3.实体(Entity) 4.构造体(Architecture)
17
2) 构造体的命名
每个构造体必须属于一个实体; 每个构造体必须有一个名称: 命名要符合命名规则 命名可根据设计者 采用何种描述方式 来描述 模块的功能来命名,给阅读程序的人带来方便。 如: beh (行为描述,基本设计单元的数学模型描述) rtl (寄存器传输描述,数据流描述) str (结构描述,逻辑元件的连接) 例: architecture str of mux2_1 is
语句
24
1. 块语句结构描述
1) 格式
块结构名: block begin [并发语句]; end block 块结构名; entity mux is port(d0,d1,sel: in bit; q: out bit); end entity mux; architecture connect of mux is signal tmp1,tmp2,tmp3: bit; begin cale:block begin tmp1 <=d0 and sel; tmp2 <=d1 and (not sel); tmp3 <=tmp1 or tmp2; q <=tmp3; end block cale; end architecture connect;
相关文档
最新文档