可编程逻辑电路设计教学组

上传人:pu****.1 文档编号:568523907 上传时间:2024-07-25 格式:PPT 页数:43 大小:428.01KB
返回 下载 相关 举报
可编程逻辑电路设计教学组_第1页
第1页 / 共43页
可编程逻辑电路设计教学组_第2页
第2页 / 共43页
可编程逻辑电路设计教学组_第3页
第3页 / 共43页
可编程逻辑电路设计教学组_第4页
第4页 / 共43页
可编程逻辑电路设计教学组_第5页
第5页 / 共43页
点击查看更多>>
资源描述

《可编程逻辑电路设计教学组》由会员分享,可在线阅读,更多相关《可编程逻辑电路设计教学组(43页珍藏版)》请在金锄头文库上搜索。

1、可编程逻辑电路设计教学组可编程逻辑电路设计教学组可编程逻辑电路设计教学组可编程逻辑电路设计教学组二二二二七年七年七年七年Hardware Description Language (HDL)q数字系统的描述方式数字系统的描述方式qHDL语言既包含一些高级程序设计语言的结构形式,也兼顾描述硬件线路语言既包含一些高级程序设计语言的结构形式,也兼顾描述硬件线路连接的构件,可以支持从系统级到门级的各个层次的行为描述和结构描述。连接的构件,可以支持从系统级到门级的各个层次的行为描述和结构描述。qHDL语言基本特征是并发的(硬件的基本特征),但也提供顺序功能的描语言基本特征是并发的(硬件的基本特征),但也

2、提供顺序功能的描述手段。述手段。qHDL语言特点:语言特点:v文本输入v适于设计大系统表达功能,隐藏细节v高表达效率v易修改、开发周期短v通用语言,模块可重用性好q常用常用HDL语言:语言:VHDL、Verilog-HDL、AHDL 设计层次设计层次行为描述行为描述结构描述结构描述系统级系统级算法流程图算法流程图由由Cpu或控制器、存储器等组成的逻或控制器、存储器等组成的逻辑框图辑框图寄存器传输级(寄存器传输级(RTL)数据流图、真值表、状态机、状态图数据流图、真值表、状态机、状态图(表表)寄存器、寄存器、ALU、MUX、ROM等组成等组成的逻辑图的逻辑图逻辑门级逻辑门级布尔方程、真值表、卡诺

3、图布尔方程、真值表、卡诺图逻辑门、触发器、锁存器等构成的逻逻辑门、触发器、锁存器等构成的逻辑图(网表)辑图(网表)VHDL语言语言qVery high speed integrated circuit HDLqIEEE工业标准工业标准HDL语言语言q可支持仿真与综合可支持仿真与综合q两个版本:两个版本:v10761987v10761993VHDL程序结构程序结构q1、USE定义区定义区vLibrary定义所使用的元件库vPackage定义所使用的元件库中的包q2、Entity定义区:定义电路实体的定义区:定义电路实体的I/O接口规格接口规格q3、Architecture定义区:描述电路内部具体

4、功能定义区:描述电路内部具体功能vComponent定义区v信号定义v行为描述/数据流描述/结构描述q4、Configuration定义区:决定使用哪一个定义区:决定使用哪一个architecture(非必须)非必须)Use定义区定义区Library IEEE;-库定义库定义Use IEEE.std_logic_1164.all;-包引用包引用Use IEEE.std_logic_arith.all;-包引用包引用引用语句的用法:引用语句的用法:Library ,;Use lib_name.pack_name.object;PackagesPackage isConstant Decclara

5、tionsType DeclarationsSignal DeclarationsSubprogram DeclarationsComponent DeclarationsOther DeclarationsEnd ;(1076-1987)End Package ;(1076-1993)Package Body isConstant DeclarationsType DeclarationsSubprogram BodyEnd Package ;(1076-1987)End Package Body (1076-1993)Package Examplepackage package_examp

6、le istype life is (sleeping, working, eating, entertaiment, otheractions);subtype uint4 is integer range 0 to 15;subtype uint5 is integer range 0 to 31;function compare(a, b: integer) return boolean;end package_example;package body package_example isfunction compare(a,b: integer) return boolean isva

7、riable temp:boolean;beginif ab thentemp:=true;elsetemp:=false;end if;return temp;end compare;end package_example;Librariesq包括一系列的包括一系列的packagesq隐含隐含Libraries: 不用声明,自动引用不用声明,自动引用vSTD:Standard:定义bit, Boolean, integer, real和time以及支持它们的运算符。Textio:定义文件操作。vWork: vIEEE:Std_logic_1164Std_logic_arithStd_logi

8、c_signedStd_logic_unsignedv其它库: Altera的元件库用户自定义库Entity(实体)实体)qEntity定义语法Entity isgeneric declarationsport declarationsEnd ;qEntity ExampleEntity adder isgeneric(data_width:integer:=4 );port( add_a, add_b: in std_logic_vector(data_width-1 downto 0);sum: out std_logic_vector(data_width downto 0) );End

9、 adder;Generic & Port DeclarationsqGeneric Declarationsv用于将参数传入Entity。例如:数据线宽度,器件的延时参数、负载电容电阻、驱动能力、功耗等等。qPort Declarations: port_name: : v:管脚的模式In (输入) Out (输出)Buffer (输出带内部反馈) Inout (双向)v: 数据类型Boolean: False, TrueBit: 0, 1Std_logic: X, 0, 1, Z, -, W, L, H,支持多信号判决Std_ulogic: 与Std_logic类型一样,不支持多信号判决B

10、it_vector & std_logic_vector: Integer: NaturalPositiveReal: time自定义数据类型:如数组等Architecture(结构体)结构体)q描述设计的功能或者结构描述设计的功能或者结构q必须与某个必须与某个entity相联系相联系q一个一个entity可以对应多个可以对应多个architecture(编译时通过编译时通过configuration来指定来指定)qArchitecture中的各个语句是并发执行的,对应于电路硬中的各个语句是并发执行的,对应于电路硬件中的不同部件件中的不同部件qArchitecture的描述风格的描述风格v行为

11、描述描述实体的功能,RTL级算法描述数据流描述v结构描述描述实体的结构,门级v混合描述Architecture组成组成qArchitecture定义定义ARCHITECTURE arch_name OF entity_name ISsignal declarations;constant declarations;type & subtype declarations;component declarations;subprogram declarations;BEGINProcess Statements;Concurrent Procedure Calls;Concurrent Signa

12、l Assignment;Conditional Signal Assignment;Selected Signal Assignment;Component Instantiation Statements;Generate Statements;END arch_name;结构描述例子结构描述例子半加器半加器Architecture struct_ha of half_adder iscomponent and_gate port( a1,a2: in std_logic; a3: out std_logic);end component;component xor_gate port(

13、a1,a2: in std_logic; a3: out std_logic);end component;Beging1: and_gate port map(a,b,c);g2: xor_gate port map(a,b,s);End struct_ha;行为描述例子行为描述例子半加器半加器q算法描述算法描述Architecture behave_ha of half_adder isBegin g1:process(a,b)begin if a=1 and b=1 thenc=1; elsec=0; end if;end process; g2:process(a,b)begin if

14、 a=1 and b=0 thenc=1; elsif a=0 and b=1c=1; elsec=0; end if;end process;End struct_ha;q数据流描述数据流描述Architecture behave_ha of half_adder isBeginc= a and b;s=a xor b;End struct_ha;Configurationq用于将用于将entity和和architecture联系起来联系起来q广泛应用于仿真环境广泛应用于仿真环境q被综合器有限支持或者不支持被综合器有限支持或者不支持q语法:语法:Configuration of isfor

15、end for;End;数据对象数据对象qConstant(常数常数)v定义语法: Constant : := v用符号代表常数,增加程序的可读性和可维护性v一经定义,不得更改qSignal(信号信号)v定义语法: Signal : := v对应于电路中的某一节点v通常定义于entity、architecture或者package中,全局使用v可再赋值 : “ =”v进程中对信号的赋值在该进程结尾才生效qVariable(变量变量)v定义语法: Variable : :=v不对应于具体电路中的节点,一般用于计算用途v只局限于进程和子程序中定义并使用v可再赋值: “:=”v对变量的赋值立即生效信

16、号和变量的区别信号和变量的区别例例1q一段程序:a, b: in std_logic;x, y: out std_logic; signal temp: std_logic;process (a, b, temp)begintemp=a;x=temp;temp=b;y=temp;end process;q等价电路图:q另一段程序:a, b: in std_logic;x, y: out std_logic; process (a, b, temp) variable temp: std_logic;begintemp:=a;x=temp;temp:=b;y=temp;end process;q

17、等价电路图:信号和变量的区别信号和变量的区别例例2q一段程序:D, clk: in std_logic;x: out std_logic; signal temp: std_logic;process (clk)begin if (clkevent and clk=1) thentemp=D;x=temp; end if;end process;q等价电路图:q另一段程序:D, clk: in std_logic;x: out std_logic; process (clk) variable temp: std_logic; begin if (clkevent and clk=1) the

18、ntemp:=D;x=temp; end if;end process;q等价电路图:数据类型数据类型q基本数据类型基本数据类型v逻辑类型: bit, boolean, std_logic, std_ulogic, std_logic_vector, bit_vectorv整数类型: Integer(及其子类如Natural, Positive), unsigned, signedv实数类型: Realq高级数据类型高级数据类型v枚举类型:定义语法:TYPE IS (, , )使程序易读,例如在定义状态机时v数组类型:定义语法:TYPE IS ARRAY (integer1 DOWNTO in

19、teger2) OF 多用于定义ROM、RAM等运算符运算符q关系运算符:关系运算符:v = = = /=q逻辑运算符:逻辑运算符:vand, or, not, nand, nor, xorq算术运算符:算术运算符:v * / MOD REM * ABSq其他运算符:其他运算符:v(正号) (负号) &(连接) q运算符重载运算符重载v对于不同的数据类型定义同样一个运算,其实际操作可能不同。例如+(加)运算,可以对整数使用,也可以对std_loigc_vector等类型用(在std_logic_arith包中定义)。v通常定义与package中。vIEEE的package中定义了大量的重载运算

20、符Vector信号的分解与合并信号的分解与合并Architecture rtl of test issignal a: std_logic_vector(3 downto 0);signal b: std_logic_vector(0 to 3);signal c: std_logic_vector(0 to 1);signal d: std_logic_vector(1 downto 0);Beginc=a(2 downto 1);b=A(3) & D & 1End rtl;a(3)a(2)a(1)a(0)b(0)b(1)b(2)b(3)c(0) d(1)c(1) d(0)1并发语句并发语句

21、qVHDL程序的结构体中的各个语句是并发的,代表电路程序的结构体中的各个语句是并发的,代表电路的不同节点,它们是同时运作的的不同节点,它们是同时运作的q并发语句的顺序不影响其执行结果并发语句的顺序不影响其执行结果q并发语句列表:并发语句列表:v直接信号赋值: =v条件信号赋值:when-elsev选择信号赋值:selectwhenv进程:processv断言:assert面向仿真的语句,不能综合v块语句:BlockvComponent语句vFor-GenerateWhen-elseq语法:语法: = when else when else. when else ;q特点:特点:v各个条件可以不

22、互斥v主要用于译码器、多路复接器和解复接器q例子:例子: q = a when sel=“00” elseb when sel=“01” elsec when sel=“10” elsed;abcdselqSelect-whenq语法:语法:with select = when , when ,. when others;q特点:特点:v各个条件必须互斥v主要用于译码器、多路复接器和解复接器q范例:范例: with sel selectq = a when “00”,b when “01”,c when “10”,d when others;abcdselqBlockq用于将电路划分成几个模用

23、于将电路划分成几个模块,增加程序的可读性块,增加程序的可读性q语法:语法: blockBeginEnd block ;q范例:范例:Library ieee;Use ieee.std_logic_1164.all;Entity half_addsub isport(a,b: in std_logic;sum, carry: out std_logic;diff, borrow: out std_logic);End half_addsub;Architecture rtl of half_addsub isBeginHalf_adder: blocksum=a xor b;carry=a an

24、d b;End block half_adder;Half_sub: blockdiff=a xor b;borrow=(not a) and b;End block half_sub;End rtl;ComponentqComponent定义语句:与定义语句:与entity类似类似 Component generic ( generic_declarations );port ( port_declarations);End component;qComponent例化语句:例化语句:: generic map ( generic_mapping)port map (port_mapping

25、);qPort map语句两种格式:语句两种格式:vPort map ( =, =, );vPort map ( , , ); Component范例范例4位全加器位全加器Library ieee;Use ieee.std_logic_1164.all;Entity full_adder_4 isport( A, B: in std_logic_vector(3 downto 0); ci: in std_logic; C: out std_logic_vector(3 downto 0); co: out std_logic);End full_adder_4;Architecture rt

26、l of full_adder_4 iscomponent full_adder_1port(a,b: in std_logic;ci: in std_logic;c: out std_logic;co: out std_logic);end component;signal t: std_logic_vector(2 downto 0);BeginU0: full_adder_1port map(A(0),B(0),ci,C(0),t(0); U1: full_adder_1port map(A(1),B(1),t(0),C(1),t(1); U2: full_adder_1port map

27、(A(2),B(2),t(1),C(2),t(2); U3: full_adder_1port map(A(3),B(3),t(2),C(3),co);End rtl;ciFull_adder_1A(0) B(0)Full_adder_1t(0)A(1) B(1)Full_adder_1t(1)A(2) B(2)Full_adder_1t(2)A(3) B(3)coC(0)C(1)C(2)C(3)For-Generateq例化多个相同的例化多个相同的Componentq语法:语法:: For i in to generatecomponent例化语句;End generate ;q范例范例:

28、4位全加器位全加器Architecture rtl of full_adder_4 is;signal t: std_logic_vector(4 downto 0);Begingen: for I in 0 to 3 generateadd1: full_adder_1 port map(A(i),B(i),t(i),C(i),t(i+1);end generate gen;t(0)=ci;co=t(4);End rtl;qIf-Generate语句可以条件生成。语句可以条件生成。q生成语句可以嵌套。生成语句可以嵌套。顺序语句顺序语句q可用于进程、函数和子程序中可用于进程、函数和子程序中q依

29、次执行,语句顺序影响其执行结果依次执行,语句顺序影响其执行结果q顺序语句的执行需要被激活顺序语句的执行需要被激活q顺序语句列表:顺序语句列表:v变量和信号赋值::= =vIf语句:if-then-elsif-elsevCase语句:case-whenvLoop语句vWait语句Processq特点:特点:vProcess语句本身是一个并发式语句,但其内部包含的是顺序语句v仅当进程的某个敏感信号发生变化时,进程内部的顺序语句块才被激活依次执行;否则进程处于被挂起的状态。v进程内的变量在进程被挂起和再次激活时,保持原值。v可以通过两种方式定义敏感信息:用敏感信息表或者用wait语句。但这两者不能同

30、时出现在一个进程中(wait语句可以有多个)。q定义语法:定义语法:Process()constant declaration;type declarations;variable declarations;Beginsequential statement #1;sequential statement #2; .sequential statement #n;End process;Process范例范例Process(clk)Beginif (clkevent and clk=1) thenq=d;end if;End process;ProcessBeginwait on clk;if

31、 clkevent and clk=1 thennq=not d;end if;End process;Process敏感列表敏感列表(1)正常的代码Process (ck, d)Beginif ck=1 thenq=d;end if;End process;Max+plus II综合结果:LatchFPGA Express综合结果: Latch(2)危险的代码Process (ck)Beginif ck=1 thenq=d;end if;End process;Max+plus II综合结果: D触发器FPGA Express综合结果: LatchIf语句语句q语法:语法:If thense

32、quential statements;Elsif thensequential statements; .Elsesequential statements;End if;q对应于对应于when-else语句语句q范例范例:if sel=“00” thenq=a;elsif sel=“01” thenq=b;elsif sel=“10” thenq=c;elseq=d;end if;Case语句语句q语法:语法:case is when =sequential statements; when =sequential statements; . when others=sequential

33、statements;end case;q对应于对应于select-when语句语句q范例范例:case sel is when “00” =q q q q=d;end case;Loop语句语句q无限循环:使用无限循环:使用Exit退出循环退出循环v语法:: Loopsequential statements;exit Loop_lable when ;End loop;qWhile循环:根据条件结束循环循环:根据条件结束循环While Loopsequential statements;End loop;qFor循环:循环:FOR IN Loopsequential statements;

34、End loop;Loop语句范例语句范例q例1Signal a: std_logic_vector(7 downto 0)Process (a)variable temp: std_logic;Begintemp:=1;for I in 0 to 7 loop temp:=temp and a(i);end loop;b=temp;End process;q例2Signal a: std_logic_vector(7 downto 0)Process (a)variable cnt: integer;variable temp: std_logic;Begintemp:=1;cnt=0;wh

35、ile cnt8 loop temp:=temp and a(cnt); cnt:=cnt+1;end loop;b=temp;End process;SubprogramPackage body of example is procedure p(A: in integer, B:inout integer) is begin B:=A+B; end; function inc(A: in integer) return integer is beginreturn (A+1) end;End example; q子程序调用范例:子程序调用范例:p(a,b);x=inc(a); q用于描述一

36、定的算法用于描述一定的算法q内部是串行执行内部是串行执行类似类似processq可以在程序中任何地方被调用可以在程序中任何地方被调用q调用方法类似于调用方法类似于Component例例化化q综合结果是组合逻辑电路综合结果是组合逻辑电路q包括包括function和和procedurevFunction: 有返回值vProcedure: 无返回值q子程序定义范例:子程序定义范例:Package example is procedure p(A: in integer, B:inout integer); function inc(A: in integer) return integer;Pack

37、age example;设计中应注意的问题设计中应注意的问题qProcess的敏感列表应完全的敏感列表应完全qIf, case-when语句应注意条件的完备性语句应注意条件的完备性q尽量避免采用可能有歧义的语法尽量避免采用可能有歧义的语法q使用使用IEEE提供的数据包中的函数提供的数据包中的函数IF语句对比语句对比a,b: in std_logic;q: out std_logic;Process(a,b)beginIf a=1 thenq=b;End if;End process;Process(a,b)beginIf a=1 thenq=b;Elseq=0;End if;End proce

38、ss;abLatchqabqLibrary IEEEq定义了许多运算符的重载函数,方便实现各种组合逻辑定义了许多运算符的重载函数,方便实现各种组合逻辑和算术功能和算术功能q定义了各种数据类型的相互转换函数,如定义了各种数据类型的相互转换函数,如conv_signed()将其他类型如将其他类型如integer, unsignedq在在maxplus2vhdl93ieee目录下可以看这些库文件的目录下可以看这些库文件的源代码,例如源代码,例如arith.vhd是是std_logic_arith包的声明文件,包的声明文件,而而arithb.vhd是该包的是该包的body。例:减法器例:减法器q输入:

39、输入:A: 二进制无符号整数,8位B: 二进制无符号整数,8位q输出输出C: 二进制补码表是整数,9位q功能:功能:C=A-Bq要求:输入输出都是要求:输入输出都是std_logic_vector类型。类型。Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_arith.all;Entity sub_8 isport( A,B: in std_logic_vector(7 downto 0);C: out std_logic_vector(8 downto 0);End sub_8;Architecture rtl of sub_8 issignal t1,t2: integer range 0 to 255;signal t3: integer range 256 to 255;Begint1=conv_integer(unsigned(A);t2=conv_integer(unsigned(B);t3=t1-t2;C=conv_std_logic_vector(t3,9);End rtl;本次实验内容本次实验内容q必做:必做:v1、三八译码器v2、二十进制转换器v3、十六进制数显示 v4、二十进制转换

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

最新文档


当前位置:首页 > 幼儿/小学教育 > 幼儿教育

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