VHDL的元件例化语句.ppt

上传人:小飞机 文档编号:5452190 上传时间:2023-07-08 格式:PPT 页数:23 大小:310.49KB
返回 下载 相关 举报
VHDL的元件例化语句.ppt_第1页
第1页 / 共23页
VHDL的元件例化语句.ppt_第2页
第2页 / 共23页
VHDL的元件例化语句.ppt_第3页
第3页 / 共23页
VHDL的元件例化语句.ppt_第4页
第4页 / 共23页
VHDL的元件例化语句.ppt_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《VHDL的元件例化语句.ppt》由会员分享,可在线阅读,更多相关《VHDL的元件例化语句.ppt(23页珍藏版)》请在三一办公上搜索。

1、第六讲 VHDL硬件描述语言_4,教学课时:2学时教学内容:VHDL语句(1)元件例化语句(1学时)(2)生成语句(1学时),元件例化语句,元件例化就是将预先设计好的设计实体定义为一个元件,然后利用映射语句将此元件与另一个设计实体中的指定端口相连,从而进行层次化设计。元件例化是使VHDL设计实体构成“自上而下”或“自下而上”层次化设计的一种重要途径。,元件例化语句分为元件声明和元件例化两部分。用元件例化方式设计电路的方法是:(1)完成各种元件的设计。(2)元件声明。(3)通过元件例化语句调用这些元件,产生需要的设计电路。,元件声明语句的格式,COMPONENT 元件名 GENERIC;PORT

2、;END COMPONENT;,元件例化语句的格式,元件例化就是将元件的引脚与调用该元件的端口的引脚相关联。关联方法有位置关联,名字关联,混合关联。(1)位置关联方式例化名:元件名 port map(信号1,信号2,.);(2)名字关联方式例化名:元件名 port map(信号关联式1,信号关联式2,.);信号关联式形如:a=a1,b=b1,意思是将元件的引脚a与调用该元件的端口a1相关联。这种情况下,位置可以是任意的。(3)混合关联方式将上述两种相结合,即为混合关联方式。,元件例化举例,例1:利用2输入与非门元件,设计4输入的与非与非电路。方法一:在调用文件里声明元件,它放在结构体的begi

3、n之前。第一步:设计2输入与非门,其VHDL源程序为nand_2.vhd;第二步:元件声明及元件例化,其VHDL源程序为nand_4.vhd;,生成的RTL视图:,library ieee;use ieee.std_logic_1164.all;entity nand_2 isport(a,b:in std_logic;y:out std_logic);end nand_2;architecture one of nand_2 isbeginprocess(a,b)beginy=a nand b;end process;end one;,library ieee;use ieee.std_lo

4、gic_1164.all;entity nand_4 isport(a,b,c,d:in std_logic;y:out std_logic);end nand_4;architecture one of nand_4 is-元件声明component nand_2 port(a,b:in std_logic;y:out std_logic);end component;-元件声明signal y1,y2:std_logic;beginu1:nand_2 port map(a,b,y1);-元件例化u2:nand_2 port map(c,d,y2);u3:nand_2 port map(y1

5、,y2,y);end one;,例1:利用2输入与非门元件,设计4输入的与非与非电路。方法2:将元件声明放在程序包里进行说明 第一步:设计2输入与非门,其VHDL源程序为nand_2.vhd;第二步:元件声明,放在程序包里,其VHDL源程序为mypkg.vhd;第三步:元件例化,其VHDL源程序为mynand_4.vhd;,程序包(p228),在设计实体中声明的数据类型、数据对象只能用于本实体和结构体内部,不能被其他实体和结构体使用,就像高级语言中的局部变量一样。为了使数据类型、元件等能被多个设计实体调用或共享,VHDL提供了程序包的机制。程序包就像是公用的工具箱,各个设计实体都可使用其中定义

6、的工具。,程序包的格式,package 程序包名 is程序包头说明部分end 程序包名;package body 程序包名 is程序包体说明部分及包体内容end 程序包名;,如何打开程序包?用语句use work.程序包名.all;打开程序包。其中,work库是用户设计的现行工作库,用于存放自己设计的工程项目。在QuartusII 的根目录下为设计建立一个工程目录(即文件夹),VHDL综合器将此目录默认为work库。但work不是设计项目的目录名,而是一个逻辑名。VHDL标准规定work库总是可见的,因此,在程序设计时不需要明确指定。,用将元件声明放在程序包里的设计方法设计4输入的与非与非门,

7、详见演示实例mynand_4.qpf。(1)在QuartusII 的根目录下新建工程mynand_4.(2)编辑VHDL源程序文件nand_2.vhd,mypkg.vhd,mynand_4.vhd.nand_2.vhd用来描述2输入与非门。mypkg.vhd用来进行元件声明。mynand_4.vhd实现元件例化。,library ieee;use ieee.std_logic_1164.all;entity nand_2 isport(a,b:in std_logic;y:out std_logic);end nand_2;architecture one of nand_2 isbeginp

8、rocess(a,b)beginy=a nand b;end process;end one;,library ieee;use ieee.std_logic_1164.all;package mypkg iscomponent nand_2port(a,b:in std_logic;y:out std_logic);-元件声明end component;end mypkg;,library ieee;use ieee.std_logic_1164.all;use;-打开程序包entity mynand_4 isport(a,b,c,d:in std_logic;y:out std_logic

9、);end mynand_4;architecture one of mynand_4 issignal y1,y2:std_logic;begin-元件例化u1:nand_2 port map(a,b,y1);u2:nand_2 port map(c,d,y2);u3:nand_2 port map(y1,y2,y);end one;,思考题,用一位D触发器,利用元件例化语句实现4位移位寄存器。思路:(1)设计一位D触发器的源程序文件shift_reg1.vhd。(2)用元件例化实现4位移位寄存器文件shift_reg4.vhd。,4位D触发器的VHDL程序文件:library ieee;u

10、se ieee.std_logic_1164.all;entity shift_reg4 isport(clk:in std_logic;D:in std_logic;Q:out std_logic);end shift_reg4;architecture one of shift_reg4 iscomponent shift_reg1port(clk:in std_logic;D:in std_logic;Q:out std_logic);end component;-元件声明signal Q0,Q1,Q2:std_logic;begin-元件例化u0:shift_reg1 port map

11、(clk,D,Q0);u1:shift_reg1 port map(clk,Q0,Q1);u2:shift_reg1 port map(clk,Q1,Q2);u3:shift_reg1 port map(clk,Q2,Q);end one;,1位D触发器的VHDL程序文件:library ieee;use ieee.std_logic_1164.all;entity shift_reg1 isport(clk:in std_logic;D:in std_logic;Q:out std_logic);end entity;architecture one of shift_reg1 isbegi

12、nprocess(clk,D)beginif clkevent and clk=1 thenQ=D;end if;end process;end one;,生成语句生成语句(GENERATE)是一种可以建立重复结构或者是在多个模块的表示形式之间进行选择的语句。由于生成语句可以用来产生多个相同的结构,因此使用生成语句就可以避免多段相同结构的VHDL程序的重复书写(相当于复制)。生成语句有两种形式:FOR-GENERATE模式和IF-GENERATE模式。FOR-GENERATE 模式的生成语句FOR-GENERATE 模式生成语句的书写格式为:标号:FOR 循环变量 IN 离散范围 GENERA

13、TE;END GENERATE 标号;,其中循环变量的值在每次的循环中都将发生变化;离散范围用来指定循环变量的取值范围,循环变量的取值将从取值范围最左边的值开始并且递增到取值范围最右边的值,实际上也就限制了循环的次数;循环变量每取一个值就要执行一次GENERATE语句体中的并行处理语句;最后FOR-GENERATE模式生成语句以保留字END GENERATE 标号:;来结束GENERATE语句的循环。生成语句的典型应用是存储器阵列和寄存器。下面以四位移位寄存器为例,说明FOR-GENERATE模式生成语句的优点和使用方法。,4位D触发器的VHDL程序文件:library ieee;use ie

14、ee.std_logic_1164.all;entity shift_reg4 isport(clk:in std_logic;D:in std_logic;Q:out std_logic);end shift_reg4;architecture two of shift_reg4 iscomponent shift_reg1port(clk:in std_logic;D:in std_logic;Q:out std_logic);end component;-元件声明signal y:std_logic_vector(0 to 4);beginy(0)=D;u0:for i in 0 to

15、3 generate元件生成ux:shift_reg1 port map(clk,y(i),y(i+1);end generate;Q=y(4);end two;,1位D触发器的VHDL程序文件:library ieee;use ieee.std_logic_1164.all;entity shift_reg1 isport(clk:in std_logic;D:in std_logic;Q:out std_logic);end entity;architecture one of shift_reg1 isbeginprocess(clk,D)beginif clkevent and clk

16、=1 thenQ=D;end if;end process;end one;,例:FOR-GENERATE模式生成语句应用.用1位D触发器设计4位移位寄存器。,可以看出用FOR-GENERATE模式生成语句替代思考题中的四条元件例化语句,使VHDL程序变的更加简洁明了。,IF-GENERATE模式生成语句IF-GENERATE模式生成语句的书写格式如下:标号:IF 条件 GENERATE;END GENERATE 标号;,思考题,设计一位二进制全加器,然后利用for-generate生成语句实现4位二进制全加器,并仿真验证设计结果。,library ieee;use ieee.std_logi

17、c_1164.all;entity adder_1 isport(a,b:in std_logic;cin:in std_logic;cout:out std_logic;s:out std_logic);end adder_1;architecture one of adder_1 issignal temp:std_logic_vector(2 downto 0);beginprocess(a,b,cin)begintemp=a,一位二进制全加器的VHDL代码,library ieee;use ieee.std_logic_1164.all;entity adder_4 isport(a,

18、b:in std_logic_vector(3 downto 0);cin:in std_logic;cout:out std_logic;sum:out std_logic_vector(3 downto 0);end entity;architecture one of adder_4 iscomponent adder_1port(a,b:in std_logic;cin:in std_logic;cout:out std_logic;s:out std_logic);end component;signal qout:std_logic_vector(3 downto 0);signal qin:std_logic_vector(4 downto 0);signal s:std_logic_vector(3 downto 0);beginqin(0)=cin;u0:for i in 0 to 3 generateux:adder_1 port map(a(i),b(i),qin(i),qout(i),s(i);qin(i+1)=qout(i);end generate;cout=qout(3);sum=s;end one;,4位二进制全加器的VHDL代码,4位二进制全加器的RTL图,4位二进制全加器的仿真结果,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号