数字电路第十一章

上传人:鲁** 文档编号:585349393 上传时间:2024-09-02 格式:PPT 页数:84 大小:367.02KB
返回 下载 相关 举报
数字电路第十一章_第1页
第1页 / 共84页
数字电路第十一章_第2页
第2页 / 共84页
数字电路第十一章_第3页
第3页 / 共84页
数字电路第十一章_第4页
第4页 / 共84页
数字电路第十一章_第5页
第5页 / 共84页
点击查看更多>>
资源描述

《数字电路第十一章》由会员分享,可在线阅读,更多相关《数字电路第十一章(84页珍藏版)》请在金锄头文库上搜索。

1、第十一章 硬件描述语言VHDL11.1 概述一、硬件描述语言(HDL)二、VHDL的发展概况三、用VHDL设计硬件电路的过程9/2/20241第11章 硬件描述语言VHDL一、元件(componentcomponent) 二、VHDL基本结构11.2.1 实体(ENTITY) 11.2.2 结构体(ARCHITECTURE) 11.2.3 配置(CONFIGURATION) 11.2.4 库(LIBRARYLIBRARY) 11.2.5 包(PACKAGE) 11.2 VHDL基本结构9/2/20242第11章 硬件描述语言VHDL11.3.1 VHDL词法规则与标识符 11.3.2 数据对象

2、和数据类型 11.3.3 运算符(operator) 11.3 VHDL语言元素9/2/20243第11章 硬件描述语言VHDL一、条件语句(if) 二、开关语句(case) 11.4 VHDL常用编程语句11.4.1 顺序(SEQUENTIALSEQUENTIAL)描述语句9/2/20244第11章 硬件描述语言VHDL一、进程语句二、信号赋值语句三、when else语句 四、with select语句 五、元件说明语句、元件例化语句11.4.2 并发(CONCURENTCONCURENT)描述语句9/2/20245第11章 硬件描述语言VHDL11.5.1 组合逻辑电路设计 11.5.2

3、 时序逻辑电路设计 11.5 基本逻辑电路设计参考教材参考教材作业作业9/2/20246第11章 硬件描述语言VHDL1.VHDL :VHSIC Hardware Description Language; VHSIC : Very High Speed Integrated Circuit;可以描述硬件电路的功能、信号连接关系及定时关系的语言。它可以比电原理图更有效地表示硬件电路的特性。2.Verilog-HDL 第第11章章 硬件描述语言硬件描述语言VHDL11.1概述概述一、硬件描述语言(一、硬件描述语言(HDL)9/2/20247第11章 硬件描述语言VHDL1.IEEE1076-19

4、87(VHDL-87) VHDL-93相对于VHDL-87没有什么大变化,主要是增加了针对VHDL模型的新的VHDL命令和属性。2.IEEE1164-1993(VHDL-93) 二、二、VHDLVHDL的发展概况的发展概况9/2/20248第11章 硬件描述语言VHDL三、用三、用VHDLVHDL设计硬件电路的过程设计硬件电路的过程所谓用VHDL设计是指由设计者编写代码,然后用模拟器验证其功能,再把这些代码综合成一个与工艺无关的网络表,即翻译成由门和触发器等基本逻辑元件组成的原理图(门级电路),最后完成硬件设计。 9/2/20249第11章 硬件描述语言VHDL图图11.2.1 一个元件分两一

5、个元件分两部分:实体和结构体部分:实体和结构体 entityentity and_2 isisportport (in_a, in_b: inin std_logic; out_a:outout std_logic);endend and_2; architecturearchitecture behavioral ofof and_2 isisbeginbeginout_a = in_a andand in_b;endend behavioral;图图11.2.2 元件元件AND_2的的VHDL描述描述 11.2 VHDL11.2 VHDL基本结构基本结构一、元件一、元件(component

6、)(component)9/2/202410第11章 硬件描述语言VHDL1.实体(Entity):定义元件的外部接口;2.构造体(Architecture):指定元件的内部结构、输入与输出之间的关系等,是对元件具体功能的描述;3.包集合(Package):存放各元件都能共享的数据类型、常量和子程序等;4.配置(Configuration):把一个具体的结构体和实体结合在一起,来组成系统设计的不同版本;5.库(Library):存放已经编译的实体、构造体、包集合和配置;二、二、VHDLVHDL基本结构基本结构9/2/202411第11章 硬件描述语言VHDLlibrarylibrary iee

7、e;useuse ieee.std_logic_1164.allall;useuse ieee.std_logic_unsigned.allall;useuse ieee.std_logic_arith.allall;- 库、包集合调用。entityentity cntm16 is isportport (clr : inin std_logic; clk : in in std_logic; q : buffer buffer std_logic_vector(3 downtodownto 0);endend cntm16; - 实体。architecturearchitecture rtl

8、 ofof cntm16 is isbegin begin processprocess (clk,clr) variablevariable i:integer rangerange 0 toto 15;beginbeginifif(clr=0)thenthen i:=0;elsifelsif( clkevent andand clk=1)thenthen if if (i=15)thenthen i:=0; else else i:=i+1; end if end if;end ifend if;q=conv_std_logic_vector(i,4);end processend pro

9、cess;endend rtl; - 结构体。例例11.2.1 用用VHDL描述一个具有异步清零的描述一个具有异步清零的4位计数器。位计数器。 9/2/202412第11章 硬件描述语言VHDLentityentity 实体名 isisportport (signalsignal 信号名:模式 类型指定; signalsignal 信号名:模式 类型指定);endend 实体名 ; 信号名:赋予每个外部引脚的名称,通常用一个或几个英文字母,或者用英文字母加数字命名。如d0,d1,sel等。模式:定义外部引脚的信号方向是输入、输出等。11.2.1 11.2.1 实体(实体(ENTITYENTIT

10、Y)9/2/202413第11章 硬件描述语言VHDLinin 元件只读该信号的值;outout 元件只把值写入该信号;inoutinout 元件对该信号读和写(双向信号);bufferbuffer 元件写和读回该信号(不是双向信号,信号从元件出去);linkagelinkage 不指定方向,无论哪一个方向都可连接,只用在文档中。entityentity component_1 isisportport (a_in : inin bit;b_out:outout bit);endend component_1; -实体举例类型指定:常用bit和bit_vector两种。9/2/202414第1

11、1章 硬件描述语言VHDL例例1 1 用用VHDLVHDL描述下图电路所对应的实体,类型指定为描述下图电路所对应的实体,类型指定为bitbit。 & & &111 1d0d1selq二选一数据选择器的电原理图entityentity mux2 isisportport(d0,d1,sel:in:in bit; q:outout bit); endend mux2;9/2/202415第11章 硬件描述语言VHDL(1)结构体名的命名:通常用behavior(行为),dataflow(数据流)、rtl(寄存器传输)或者structural(结构)命名 。architecturearchitect

12、ure 结构体名 ofof 实体名 isis 结构体说明部分beginbegin 结构体语句部分endend 结构体名;(2)结构体说明:用于对构造体内部所使用的信号、常数、数据类型和函数等进行定义。11.2.2 11.2.2 结构体(结构体(ARCHITECTUREARCHITECTURE)9/2/202416第11章 硬件描述语言VHDL例例11.2.2 11.2.2 用用VHDLVHDL描述一个描述一个2 2选选1 1数据选择器。数据选择器。 entityentity mux2 isisportport(d0,d1,sel:in:in bit; q:outout bit); endend

13、 mux2;architecturearchitecture dataflow ofof mux2 is isbeginbeginq =(d0 andand sel) oror ( notnot sel andand d1);endend dataflow; 9/2/202417第11章 硬件描述语言VHDL把一个具体的结构体和实体结合在一起,来组成系统设计的不同版本。常用于仿真。一、不用配置一、不用配置 二、默认配置二、默认配置 11.2.3 11.2.3 配置(配置(CONFIGURATIONCONFIGURATION)9/2/202418第11章 硬件描述语言VHDLentity ent

14、ity mux is isendend;architecture architecture behv of of mux isisbeginbegin endend;architecture architecture rtl of of mux isisbeginbegin endend;configurationconfiguration mux_behv ofof mux isisfor for behvend forend for ;end end mux_behv; - 结构体behv的默认配置configurationconfiguration mux_rtl ofof mux is

15、isfor for rtlend forend for ;end end mux_rtl; - 结构体rtl的默认配置9/2/202419第11章 硬件描述语言VHDL存放已经编译的实体、结构体、包和配置,是经编译后的数据的集合。一、库的种类一、库的种类1.IEEE库2.STD库:VHDL的标准库3.面向ASIC的库:用于门级仿真4.WORK库:现行作业库。5.用户定义库11.2.4 11.2.4 库(库(LIBRARYLIBRARY)9/2/202420第11章 硬件描述语言VHDL二、库的使用二、库的使用1.库的说明librarylibrary ;useuse .allall;librar

16、ylibrary work;librarylibrary std;useuse std.standard.allall; -打开standard包所在的库;-调用包中的所有项;9/2/202421第11章 硬件描述语言VHDL2.库的作用范围从librarylibrary语句后的实体到该实体所对应的结构体、配置。 例2 librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity and1 isisendend and1; architecturearchitecture rtl ofof and1 isisendend

17、rtl; configurationconfiguration s1 ofof and1 isisendend s1; librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity or1 isisconfigurationconfiguration s2 ofof or1 isisendend s2; 9/2/202422第11章 硬件描述语言VHDL3.库与常见数据类型bit、bit_vector、boolean、character、string、time、integer、real等std_logic,std_ulog

18、ic,std_logic_vector,std_ulogic_vector。 (1)standard包:(2)std_logic_1164包(在库IEEE中):用到以上数据类型,需说明如下:librarylibrary ieee;useuse ieee.std_logic_1164.allall;用到以上数据类型,不用说明。9/2/202423第11章 硬件描述语言VHDL存放各元件都能共享的数据类型、常量和子程序等;library library ieee;library library mylib;use use ieee.std_logic_1164.allall;use use myl

19、ib.mypackage.allall;entity entity myentity isisport port (a: in in std_logic; b: out out std_logic);例例 11.2.3 11.2.3 自定义包自定义包 mypackagemypackage。- 使用自定义包 mypackage示例。11.2.5 11.2.5 包(包(PACKAGEPACKAGE)9/2/202424第11章 硬件描述语言VHDL一、注释(一、注释(commentcomment): :-二、二、标识符(标识符(identifieridentifier) 1.用户自定义2.VHDL

20、语言预定义(关键字或保留字)(1)必须以英文字母开头;(2)英文字母、数字(09)和下划线都是有效的字符; (3)不区分大小写; 如 entityentity。(4)下划线( _ )的前后都必须有英文字母或数字; 11.3 VHDL11.3 VHDL语言元素语言元素 11.3.1 VHDL11.3.1 VHDL词法规则与标识符词法规则与标识符 9/2/202425第11章 硬件描述语言VHDL三、三、数(数(numbernumber)的表示的表示(1)十进制整数表示法 022 43 34_56134561 3E8 (2)以基表示的数: 2#11000100# 16#C4# 4#301#E1 (

21、3)实数: 12.0 0.0 346_4l5.675_23 532.4E-2 为了提高数字的可读性,在相邻数字之间允许插入下划线。 基数 有效位 指数部分 9/2/202426第11章 硬件描述语言VHDL一、数据对象(一、数据对象(objectobject) (1)常数(constantconstant)constant vcc:real := 5.0;(2)变量(variablevariable)constantconstant 常数名:数据类型 : 表达式; variablevariable 变量名:数据类型:约束条件 : 初始值;variablevariable n:integer r

22、ange range 0 to to 15 : 2 ;variable variable x, y : integer ; 变量赋值语句的格式为:日标变量名 := 表达式; x := y +1; 11.3.2 11.3.2 数据对象和数据类型数据对象和数据类型9/2/202427第11章 硬件描述语言VHDL(3)信号(signalsignal) signalsignal 信号名:数据类型:约束条件 : 表达式; signal signal sys_d : bit : 0;signal signal tmp : std_logic; 信号赋值语句格式为: 目标信号名 表达式; a b ;s1

23、s2 afterafter 10 ns ; 信号和变量的区别?信号和变量的区别?9/2/202428第11章 硬件描述语言VHDL1.标准数据类型二、数据类型(二、数据类型(typetype) 2.自定义数据类型 9/2/202429第11章 硬件描述语言VHDL(1)整数类型(integer)、实数类型(real) (2)枚举类型(enumeration) type type 数据类型名 is is 数据类型 约束范围 ; type type digit is is integer range range 0 to to 9; type type myreal is is real rang

24、e range 1e3 to to 1e3; type type 数据类型名 is is (元素1 , 元素2 ,); type type arith_op is is (add,sub,mul,div);type type color is is (red,green,blue);type type bit is is (0, 1);type type boolean is is (false,true);type type std_ulogic is is (U,X,0,1,Z,W,L,H,-);9/2/202430第11章 硬件描述语言VHDL(3)数组类型(arrayarray)、记录

25、类型(recordrecord) type type big_word is array is array (0 toto 63) of of bit; - 一维数组type type matrix_1 is array is array (0 to to 15,0 to to 31) of of bit; - 二维数组type type instruction is recordis record operator : arith_op; op1 : integer; op2 : integer;end record;end record;(4)子类型(subtypesubtype) sub

26、type subtype 标识符 is is 基类型 范围限制; subtype subtype my_int is is integer range range 0 to to 65535;subtype subtype iobus is is std_logic_vector(7 downtodownto 0);9/2/202431第11章 硬件描述语言VHDL分 类运算符功 能二元算术运算符+加-减*乘/除mod求模rem求余*乘方一元算术运算符+正号-负号abs绝对值关系运算符=相等/=不相等大于=大于等于表11.3.2 VHDL运算符 分 类运算符功 能二元逻辑运算符and与Or 或

27、Nand与非Nor或非xor异或一元逻辑运算符not求反并置运算符&连接赋值运算符结合11.3.3 11.3.3 运算符运算符(operator)(operator)9/2/202432第11章 硬件描述语言VHDL顺序语句只能用于进程或子程序(即函数和过程)中。语句按书写次序顺序执行。一、条件语句(一、条件语句(ifif) if if 条件 then then 顺序语句elsifelsif 条件 then then 顺序语句else else 顺序语句end if;end if;11.4 VHDL11.4 VHDL常用编程语句常用编程语句 11.4.1 11.4.1 顺序(顺序(SEQUEN

28、TIALSEQUENTIAL)描述语句描述语句 例例11.4.2 11.4.2 用用ifif语句描述二选一数据选择器语句描述二选一数据选择器例例11.4.3 11.4.3 用用ifif语句描述四选一数据选择器语句描述四选一数据选择器例例11.4.1 11.4.1 简单简单ifif语句举例语句举例9/2/202433第11章 硬件描述语言VHDL二、开关语句(二、开关语句(casecase) case case 表达式 isiswhen when 选择 = 顺序语句;when when 选择 = 顺序语句;when others when others = 顺序语句;end caseend ca

29、se; 功能和if if语句类似,但其可读性比if if语句强。注意:应该将表达式的所有取值都列出来。例例11.4.4 11.4.4 用用casecase语句描述四选一数据选择器语句描述四选一数据选择器9/2/202434第11章 硬件描述语言VHDL一、进程语句(一、进程语句(processprocess) 进程名: process process (敏感信号表) 进程说明部分beginbegin 顺序语句部分end process end process 进程名; 11.4.2 11.4.2 并发(并发(CONCURENTCONCURENT)描述语句描述语句进程语句的特点?进程语句的特点?

30、9/2/202435第11章 硬件描述语言VHDL二、信号赋值语句二、信号赋值语句(signal assignment)(signal assignment) 目标信号 = 表达式; architecturearchitecture behav ofof ab_signal isis beginbegin output = a+b; endend behav; architecturearchitecture behav ofof ab_signal isisbeginbegin process process (a,b) begin begin output = a+b; endend pr

31、ocessprocess;endend behav;-与output = a+b;等价9/2/202436第11章 硬件描述语言VHDL三、三、when elsewhen else语句语句 目标信号 = 表达式 when when 条件 elseelse 表达式 when when 条件 elseelse 表达式 when when 条件 elseelse 表达式 ; 例例11.4.5 11.4.5 用用when elsewhen else语句描述四选一数据选择器语句描述四选一数据选择器9/2/202437第11章 硬件描述语言VHDL四、四、with selectwith select语句语

32、句 with with 表达式 select select 目标信号 = 表达式 when when 选择 ;with with 和 selectselect间表达式的所有可能的取值(即语句中的选择)必须一一列出。 例例11.4.6 11.4.6 用用with selectwith select语句描述四选一数据选择器语句描述四选一数据选择器9/2/202438第11章 硬件描述语言VHDL五、元件说明语句五、元件说明语句、元件例化语句元件例化语句1.元件说明:出现在architecturearchitecture和beginbegin之间 component component 实体名 ge

33、nericgeneric(类属表) ; portport(端口名);end componentend component;标号名:元件名 generic mapgeneric map(类属关联表) port mapport map(端口关联表);2.元件例化:出现在结构体的语句部分例3 用VHDL描述一个二选一数据选择器。9/2/202439第11章 硬件描述语言VHDL11.5 11.5 基本逻辑电路设计基本逻辑电路设计 11.5.1 11.5.1 组合逻辑电路设计组合逻辑电路设计例例11.5.1 11.5.1 二输入与非门的二输入与非门的VHDLVHDL程序设计。程序设计。例例11.5.2

34、 11.5.2 二输入或非门的二输入或非门的VHDLVHDL程序设计程序设计例例11.5.3 11.5.3 二输入异或门的二输入异或门的VHDLVHDL程序设计程序设计例例11.5.4 11.5.4 反相器门电路的反相器门电路的VHDLVHDL程序设计程序设计9/2/202440第11章 硬件描述语言VHDL例例11.5.7 11.5.7 2-42-4线译码器线译码器的程序设计的程序设计例例11.5.8 11.5.8 四选一数据选择器的程序设计四选一数据选择器的程序设计例例11.5.5 11.5.5 单向总线缓冲器的单向总线缓冲器的VHDLVHDL程序设计程序设计例例11.5.6 8-311.

35、5.6 8-3线优先编码器线优先编码器7414874148的的VHDLVHDL程序设计程序设计9/2/202441第11章 硬件描述语言VHDL11.5.2 11.5.2 时序逻辑电路设计时序逻辑电路设计 例例11.5.9 11.5.9 异步复位、边沿触发异步复位、边沿触发D D触发器的设计触发器的设计例例11.5.10 11.5.10 同步复位、边沿触发同步复位、边沿触发D D触发器的设计触发器的设计例例11.5.11 11.5.11 六进制计数器六进制计数器的设计的设计例例11.5.12 11.5.12 串入串入/ /并出八位移存器并出八位移存器的设计的设计9/2/202442第11章 硬

36、件描述语言VHDL参考教材参考教材1.Stefan Sjholm, Lennart Lindh 著, VHDL for Designers(边计年 薛宏熙 译,用VHDL设计电子线路),清华大学出版社,2001.4。2.侯伯亨 顾新 编著,VHDL硬件描述语言与数字逻辑电路设计(修订版),西安电子科技大学出版社,1999.9。9/2/202443第11章 硬件描述语言VHDL作作 业业11.311.411.1111.1311.15 (2)9/2/202444第11章 硬件描述语言VHDLVHDL主要用于描述从抽象到具体级别的(数字)硬件,大多数应用集中在可编程逻辑器件(PLD)的开发上,它的作

37、用是使用软件编程语言进行硬件的设计。行为级描述、门级描述分别是VHDL所能描述的最高、最低层次。9/2/202445第11章 硬件描述语言VHDL注释是以双连符(-)打头直到本行末尾的一段文字,它不是VHDL设计描述的一部分,不参加编译。在MAX+plus软件中,一行可包含多个语句。在MAX+plus软件中,一个文件可包含多个实体,但文件名必须与顶层实体名相同。9/2/202446第11章 硬件描述语言VHDL变量的说明和赋值限定在顺序区域内(即只能在进程,函数和过程中),许多程序设计语言含有全程变量,对所有的程序模块可见。VHDL中不允许有全程变量,VHDL中引入共享变量(即全程变量),赋值

38、形式和普通变量赋值形式相同。9/2/202447第11章 硬件描述语言VHDL图 11.1 VHDL的一般设计流程系统分析和划分系统分析和划分行为级描述行为级描述行为级仿真行为级仿真RTLRTL级描述级描述RTLRTL级仿真级仿真综合成门级电路综合成门级电路门级电路仿真、定时检查门级电路仿真、定时检查输出门级网表输出门级网表电路物理实现电路物理实现对应抽象的算法模型或控制流图和数据流图对应触发器、寄存器计数器、多路选择器、算术逻辑运算单元等功能块对应与门、或门、非门、三态门等门电路及少量的触发器对应系统的一些性能指标对应晶体管、MOS管、二极管、电阻、电容、连线及相应版图中的几何图形9/2/2

39、02448第11章 硬件描述语言VHDLpackagepackage mypackage is - - is - - 包头 functionfunction minimum(a,b: in in std_logic_vector) returnreturn std_logic_vector;- 以下部分说明可用于包外部的常数和数据类型: constant constant maxint : integer := 16#FFFF#; type type arithmetic_mode_type is is (signed, unsigned);end end mypackage;package

40、body package body mypackage is - - is - - 包体 function function minimum(a,b: in in std_logic_vector) return return std_logic_vector isis begin begin if if ab thenthen return return a; elseelse return return b; end if;end if; end end minimum;end end mypackage;9/2/202449第11章 硬件描述语言VHDL信号是全局量,可以进行进程之间的通

41、信;而变量是局部量,只能用于进程或子程序(即函数和过程)中;对变量的赋值是立即发生的,对信号的赋值须经一段时间延迟才会发生;对变量的赋值用“:=”,对信号的赋值用“=” ;信号可以比拟为硬件端口之间的连接,而变量则与硬件之间没有对应关系;9/2/202450第11章 硬件描述语言VHDL数据类型标 识说 明整数INTEGER-(231-1) +(231-1)实数REAL-1.0E+38+1.0E+38位BIT逻辑0 或1,单引号标出位矢量BIT_VECTORBIT的组合,以双引号标出字符CHARACTERSASCII 字符,单引号标出布尔量BOOLEAN逻辑“真”或“假”,TRUE or FA

42、LSE时间TIME时间单位:fs,ps,ns,us,ms,sec,min,hr错误等级SEVERITY LEVELNOTE,WARNING,ERROR,FAILURE自然数NATURAL整数的子集:0231-1正整数POSTIVE整数的子集:1231-1字符串STRING字符矢量,以双引号标出表11.3.1 VHDL标准数据类型9/2/202451第11章 硬件描述语言VHDL可以与其他进程并发运行,并可存取实体或结构体中定义的信号;进程结构中的所有语句按书写顺序执行;为启动进程,在进程结构中必须包含一个显式的敏感信号表或包含一个waitwait语句,即只有敏感信号表中或waitwait语句后

43、的敏感信号发生变化,进程才被启动;进程间通过信号传递,实现相互通信。 9/2/202452第11章 硬件描述语言VHDL(1)参数映射语句(generic mapgeneric map)例例11.4.7 11.4.7 参数传递应用举例。参数传递应用举例。假设and2元件是一个带传输延迟时间参数的二输入与门电路:entityentity and2 isis generic generic (delay:time := 10ns); port port(a,b:in in bit;c:outout bit);endend and2;architecturearchitecture behav of

44、of and2 isisBeginBegin c = a and and b after after delay;endend behav;9/2/202453第11章 硬件描述语言VHDLentityentity exam isis portport(ina,inb,inc,ind:bit;q:outout bit);endend exam;architecturearchitecture behav ofof exam isis componentcomponent and2 genericgeneric (delay:time); portport(a,b:inin bit;c:outo

45、ut bit); end componentend component; signalsignal sl,s2:bit;beginbegin u1:and2 generic mapgeneric map(5ns) port port mapmap(ina,inb,sl); u2:and2 generic mapgeneric map(10ns) port mapport map(inc,ind,s2); u3:and2 generic mapgeneric map(12ns) port mapport map(s1,s2,q);endend behav; 现要调用u1,u2,u3 3个与门,且

46、它们的传输延迟时间要求分别为5ns,10ns,12ns:9/2/202454第11章 硬件描述语言VHDL(2)端口映射语句(port mapport map) 位置映射方法 即在u1中,ina对应a,inb对应 b,s1对应c。and2端口定义:元件例化语句:portport(a,b:inin bit;c:outout bit);u1:and2 port port mapmap(ina,inb,s1);名称映射方法 u1:and2 port mapport map(aina, binb,cs1);或u1:and2 port mapport map(binb, aina, cs1);9/2/2

47、02455第11章 硬件描述语言VHDLentityentity mux2 isisportport(d0,d1,sel:inin bit; q:outout bit); endend mux2;architecturearchitecture struct ofof mux2 isiscomponentcomponent and2portport (a,b:inin bit; c :outout bit);endend componentcomponent;componentcomponent or2portport (a,b:inin bit; c :outout bit);end com

48、ponentend component;componentcomponent invportport (a:inin bit; c :outout bit);endend componentcomponent;signalsignal aa,ab,nsel:bit;beginbeginu1:inv port mapport map (sel,nsel);u2:and2 port mapport map (nsel,d1,ab);u3:and2 port mapport map (d0,sel,aa);u4:or2 port mapport map (aa,ab,q);endend struct

49、;& & &111 1d0d1selqaaabnselu1u2u3u4例例3 3 用用VHDLVHDL描述一个二描述一个二选一数据选择器。选一数据选择器。二选一数据选择器电原理图9/2/202456第11章 硬件描述语言VHDL例例11.5.1 二输入与非门的二输入与非门的VHDL程序设计。程序设计。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity nand2 isis port port (a, b: inin std_logic; y: outout std_logic);endend nand2;arch

50、itecturearchitecture nand2_1 ofof nand2 isisbeginbegin y = a nandnand b;endend nand2_1; 9/2/202457第11章 硬件描述语言VHDL例例11.5.2 二输入或非门的二输入或非门的VHDL程序设计。程序设计。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity nor2 isis port port (a, b: inin std_logic; y: outout std_logic);endend nor2;archite

51、cturearchitecture nor2_1 ofof nor2 isisbeginbegin y = a nornor b;endend nor2_1; 9/2/202458第11章 硬件描述语言VHDL例例11.5.3 二输入异或门的二输入异或门的VHDL程序设计。程序设计。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity xor2 isis port port (a, b: inin std_logic; y: outout std_logic);endend xor2;architecturearc

52、hitecture n xor2_1 ofof xor2 isisbeginbegin y = a xorxor b;endend xor2_1;9/2/202459第11章 硬件描述语言VHDL例例11.5.4 反相器门电路的反相器门电路的VHDL程序设计。程序设计。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity inv isis port port (a: inin std_logic; y: outout std_logic);endend inv;architecturearchitecture in

53、v _1 ofof inv isisbeginbegin y = notnot a;endend inv _1;9/2/202460第11章 硬件描述语言VHDL例例11.5.5 单向总线缓冲器的单向总线缓冲器的VHDL程序设计。程序设计。librarylibrary ieee;useuse ieee.std.logic_1164.allall;entityentity tri_buffer8 isis portport(din: inin std_logic_vector(7 downtodownto 0); dout: outout std_logic_vector(7 downtodow

54、nto 0); en: in in std_logic);endend tri_buffer8;architecturearchitecture tri_buffer8 _1 ofof tri_buffer8 isisbeginbegin process process (en,din) begin begin if if (en=1) then then dout = din; elseelse dout = “ZZZZZZZZ”; end ifend if; end process end process;endend tri_buffer8 _1;9/2/202461第11章 硬件描述语

55、言VHDL表11.5.1 83线优先编码器74148功能表 1 0 1 1 0 1 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 EN使能输入 1 1 1 1 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 Y2 Y1 Y0 输 出 0 0 0 0 0 0 1 1 YEX输出标志 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 YEN I7 I6 I5 I4 I3 I2 I1 I0 使能输出 输

56、 入例例11.5.6 8-311.5.6 8-3线优先编码器线优先编码器7414874148的的VHDLVHDL程序设计程序设计9/2/202462第11章 硬件描述语言VHDLlibrary library ieee; ; use use ieee.std_logic_1164.all;.all; entityentity p74148 isis portport(en,in0,in1,in2,in3,in4,in5,in6,in7:in in std_logic; yen,yex,y0,y1,y2: outout std_logic); endend p74148; architectur

57、earchitecture rtl ofof p74148 isis signalsignal temp_in : std_logic_vector (7 downtodownto 0); signalsignal temp_out : std_logic_vector (4 downtodownto 0); begin begin temp_in = in7&in6&in5&in4&in3&in2&in1&in0; processprocess(en,temp_in) beginbegin if if (en=0) then then 9/2/202463第11章 硬件描述语言VHDL if

58、if(temp_in=“11111111”) then then temp_out = “11110”; elsifelsif (temp_in(7)=0) then then temp_out = “00001”; elsifelsif (temp_in(6)=0) then then temp_out = “00101”; elsifelsif (temp_in(5)=0) thenthen temp_out = “01001”; elsifelsif (temp_in(4)=0) then then temp_out = “01101”; elsifelsif (temp_in(3)=0

59、) thenthen temp_out = “10001”; elsifelsif (temp_in(2)=0) then then temp_out = “10101”; elsifelsif (temp_in(1)=0) then then 9/2/202464第11章 硬件描述语言VHDL temp_out = “11001”; elsifelsif (temp_in(0)=0) thenthen temp_out = “11101”; else else temp_out = “11111”; end if end if; elseelse temp_out = “11111”; en

60、d ifend if; y2 = temp_out(4);y1 = temp_out(3);y0 = temp_out(2);yex = temp_out(1);yen = temp_out(0);end processend process;endend rtl;9/2/202465第11章 硬件描述语言VHDL例例11.5.7 11.5.7 2-42-4线译码器线译码器的程序设计的程序设计 表11.5.2 24 线译码器的功能表 1 1 0 11 000001EN使能输入1 1 1 01 11 0 1 10 10 1 1 1 0 01 1 1 1 Y0 Y1 Y2 Y3A1 A0 输 出输

61、 入9/2/202466第11章 硬件描述语言VHDLlibrarylibrary ieee; useuse ieee.std_logic_1164.allall; entityentity deco_2_4 isis portport(en,a0,a1:inin std_logic; y0,y1,y2,y3: outout std_logic); endend deco_2_4; architecturearchitecture rtl ofof deco_2_4 isis signa signal temp_in : std_logic_vector(1 downtodownto 0);

62、signal signal temp_out : std_logic_vector(3 downtodownto 0); begin begin temp_in temp_out temp_out temp_out temp_out when others = temp_out=“1111”; end case end case; else else temp_out = “1111”; end if end if; y3 = temp_out(3); y2 = temp_out(2); y1 = temp_out(1); y0 = temp_out(0); end process end p

63、rocess; endend rtl; 9/2/202468第11章 硬件描述语言VHDL例例11.5.8 11.5.8 四选一数据选择器的程序设计。四选一数据选择器的程序设计。 表 11.5.3 四选一MUX的功能表 0 0 0 0 1 EN 使能 输入 D3 1 1 D2 1 0 D1 0 1 D0 0 0 0 Y A1 A0 输 出 输 入9/2/202469第11章 硬件描述语言VHDLlibrarylibrary ieee; useuse ieee.std_logic_1164.allall; entityentity mux4 isis portport(en,a0,a1,d0,d

64、1,d2,d3:in in std_logic; y: outout std_logic); endend mux4; architecturearchitecture rtl of of mux4 is is signal signal a : std_logic_vector(1 downtodownto 0); begin begin a y y y y y=0; end case end case; else else y = 0; end if; end if; end process; end process; endend rtl; 9/2/202471第11章 硬件描述语言VH

65、DL例例11.5.9 11.5.9 异步复位、边沿触发异步复位、边沿触发D D触发器的设计触发器的设计DQQBCLR图11.5.1 上升沿触发的D触发器 9/2/202472第11章 硬件描述语言VHDLlibrary ieee; useuse ieee.std_logic_1164.allall; entityentity syclr_edge_dff isis portport(cp,d,clr:inin std_logic; q,qb: outout std_logic); endend syclr_edge_dff; architecturearchitecture rtl ofof

66、yclr_edge_dff isis beginbegin processprocess(cp,clr) begin begin ifif(clr=0) thenthen q=0; qb=1; elsifelsif (cpevent andand cp=1) thenthen q=d; qb= notnot d; end if end if; end process end process; endend rtl; 9/2/202473第11章 硬件描述语言VHDL例例11.5.10 同步复位、边沿触发同步复位、边沿触发D触发器的设计触发器的设计 librarylibrary ieee; us

67、euse ieee.std_logic_1164.allall; entityentity asyclr_edge_dff isis portport(cp,d,clr:inin std_logic; q,qb: outout std_logic); endend asyclr_edge_dff; architecturearchitecture rtl ofof asyclr_edge_dff isis beginbegin process process(cp) begin begin if if(cpevent andand cp=1) thenthen if if (clr=0) th

68、enthen q=0; qb=1; else else q=d; qb= notnot d; end if end if; end process end process; endend rtl; 9/2/202474第11章 硬件描述语言VHDL例例11.5.11 六进制计数器六进制计数器的设计。的设计。librarylibrary ieee; useuse ieee.std_logic_1164.allall; useuse ieee.std_logic_arith.allall; entityentity counter6 isis portport(en,clr,cp:inin std

69、_logic; qa,qb,qc: outout std_logic); endend counter6 ; architecturearchitecture rtl of of counter6 isis signal signal q : std_logic_vector(2 downtodownto 0); subtype subtype countm6 isis integer rangerange 0 toto 5; begin begin process process(cp) variable variable q6:countm6; begin begin if if(cpev

70、ent and and cp=1) then then ifif(clr=0) then then 9/2/202475第11章 硬件描述语言VHDL q6:= 0; elsifelsif (en=1) thenthen if if(q6=5) thenthen q6:=0; else else q6:=q6+1; end if end if; end if end if ; end if end if; q = conv_std_logic_vector(q6,3); qa = q(0); qb = q(1); qc = q(2); end process end process; end

71、end rtl; 9/2/202476第11章 硬件描述语言VHDL例例11.5.12 串行输入串行输入/并行输出八位移位寄存器并行输出八位移位寄存器的设计。的设计。 librarylibrary ieee; useuse ieee.std_logic_1164.allall; entityentity shift_reg isis portport (clk,rst,shift_en,d_in : inin std_logic; q: outout std_logic_vector (7 downtodownto 0); endend shift_reg; architecturearchi

72、tecture rtl ofof shift_reg isis signalsignal shft: std_logic_vector (7 downtodownto 0); beginbegin processprocess (rst, clk) beginbegin if if (rst=0) thenthen shft 0); elsifelsif (clkevent and clk=1) thenthen ifif shift_en = 1 thenthen shft(7 downto 1) = shft(6 downto 0); 9/2/202477第11章 硬件描述语言VHDL s

73、hft(0) = d_in; end if end if; end if end if; end processend process; q = shft; endend rtl; 9/2/202478第11章 硬件描述语言VHDL例例11.4.1 11.4.1 简单简单if if语句举例。语句举例。if if (a=1) thenthenc = b;end ifend if; 9/2/202479第11章 硬件描述语言VHDL例例11.4.2 11.4.2 用用if if语句描述二选一数据选择器。语句描述二选一数据选择器。设输入为一个矢量d :inin std_logic_vector(1

74、downtodownto 0),即输入为d(0),d(1),输出为y,地址变量为a0。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity mux4 isisportport (d : inin std_logic_vector (1 downtodownto 0); a0: inin std_logic; y: outout std_logic);endend mux4;architecturearchitecture archmux ofof mux4 isisbeginbegin process proces

75、s(d,a0) begin begin if if (a0=0) then then y = d(0); else else y = d(1); end if end if; end process end process;endend archmux; 9/2/202480第11章 硬件描述语言VHDL例例11.4.3 11.4.3 用用if if语句描述四选一数据选择器。语句描述四选一数据选择器。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity mux4 isisportport (d : inin std

76、_logic_vector (3 downtodownto 0); a: inin std_logic_vector (1 downtodownto 0); y: outout std_logic);endend mux4;architecturearchitecture archmux ofof mux4 isisbeginbegin process process(d,a) begin begin if if (a=“00”) then then y = d(0); elsifelsif (a=“01”) then then y = d(1); elsifelsif (a=“10”) th

77、en then y = d(2); else else y = d(3); end if end if; end process end process;endend archmux;9/2/202481第11章 硬件描述语言VHDL例例11.4.4 11.4.4 用用casecase语句描述四选一数据选择器。语句描述四选一数据选择器。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity mux4 isisportport (d: inin std_logic_vector (3 downtodownto 0);

78、a: inin std_logic_vector (1 downtodownto 0);y: outout std_logic);endend mux4;architecturearchitecture archmux ofof mux4 isisbeginbegin process process(d,a) begin begin case case a isis when when “00” = y = d(0); when when “01” = y = d(1); when when “10” = y = d(2); when others when others = y = d(3)

79、; end case; end case; end process end process;endend archmux;9/2/202482第11章 硬件描述语言VHDL例例11.4.5 11.4.5 用用when elsewhen else语句描述四选一数据选择器。语句描述四选一数据选择器。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity mux4 isisportport (d : inin std_logic_vector (3 downtodownto 0); a: inin std_logic_ve

80、ctor (1 downtodownto 0); y: outout std_logic);endend mux4;architecturearchitecture archmux ofof mux4 isisbeginbeginy= d(0) whenwhen a=“00” elseelse d(1) whenwhen a=“01” elseelse d(2) whenwhen a=“10” elseelse d(3);endend archmux; 9/2/202483第11章 硬件描述语言VHDL例例11.4.6 11.4.6 用用with selectwith select语句描述四选

81、一数据选择器。语句描述四选一数据选择器。librarylibrary ieee;useuse ieee.std_logic_1164.allall;entityentity mux4 isisportport (d : inin std_logic_vector (3 downtodownto 0); a: inin std_logic_vector (1 downtodownto 0); y: outout std_logic);endend mux4;architecturearchitecture archmux ofof mux4 isisbeginbegin with with a selectselect y= d(0) whenwhen “00” , d(1) whenwhen “01” , d(2) whenwhen “10” , d(3) when otherswhen others;endend archmux; 9/2/202484第11章 硬件描述语言VHDL

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号