vhdl 中的结构设计:元件例化语句

25
VHDL 中中中中中中 中中中中中中 中中中中中 中中中中中中中中中中中中 :; 中中 中中中中中中中中中中 中中 中 中 中中中中中中中中中 中中 :(体),, 中中中中中中中中中中中中中中体; 中中中中中中中中中中 中中 / 中中中中中中

Upload: ken

Post on 16-Mar-2016

165 views

Category:

Documents


2 download

DESCRIPTION

VHDL 中的结构设计:元件例化语句. 设计的要点:建立元件端口之间的连接; 元件:已经定义的电路模块(实体),可以来自标准库中,也可以是自己或他人以前编译过的实体; 元件的基本要点: 元件名 输入 / 输出端口特点;. VHDL 中的结构设计的实例. entity butnot is port ( x,y : in bit; z: out bit); end butnot ; architecture str of butnot is signal temp: bit; - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计:元件例化语句设计的要点:建立元件端口之间的连接;元件:已经定义的电路模块(实体),可以来自标准库中,也可以是自己或他人以前编译过的实体;元件的基本要点: 元件名 输入 / 输出端口特点;

Page 2: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计的实例entity butnot is

port (x,y: in bit; z: out bit); end butnot;

architecture str of butnot is

signal temp: bit;

component kinv port (a: in bit; y: out bit);

end component;

component kand2 port (a,b: in bit; y: out

bit);end component;

Page 3: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计的实例begin

u1: kinv port map(y,temp);

u2: kand2 port map(x,temp,z);

end str;

Page 4: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计的特点Architecture str of 实体名 is

元件说明; --(电路设计中使用的元件及端口)信号说明; --(电路设计中各中间连接点)begin

元件使用语句; --(端口与信号(中间连接点及输入 / 输出端点)的连接关系)end str;

Page 5: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计:元件说明component 元件名port(信号名:模式 信号类型; ……. 信号名:模式 信号类型);end component;要点:所用的电路实体应在 work库或已说明的库中;模块名称和对应端口名称顺序应完全一致;

Page 6: VHDL 中的结构设计:元件例化语句

实体与元件说明的对比entity kand2 isport(a, b: in std_logic; y: out std_logic);end kand2;

component kand2 port ( a, b: in std_logic;y: out std_logic);end component;

Page 7: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计:元件使用元件编号:元件名 port map(信号对应表);元件使用语句要点:对每一元件应该指定唯一的编号;元件名称应该与已经有的元件名称完全一致;元件使用语句为并行语句,只能在结构体中使用,不能在子程序中(函数、过程、进程)使用。

Page 8: VHDL 中的结构设计:元件例化语句

信号对应表的格式将本元件的各端口与外部的信号接点或端口建立连接;每个连接应该具有一个唯一的名称;例:原来元件的端口: port ( a, b: in std_logic;y: out std_logi

c ) ;

顺序关联法: port ( data,en,out ) ;

名称关联法:port ( a=>data,y=>out,b=>en ) ;

Page 9: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计的实例质数检测器的结构设计 p.284 表 4-43architecture prime1_arch of prime issignal n3_l,n2_l,n1_l:std_logic;signal n3l_n0,n3l_n2l_n1,n2l_n1_n0 ,n2_n1l_n0:std_logic;component kinv port (a: in std_logic;y: out std_logic);end component;component kand2 port (a0,a1: in std_logic;y: out std_logic);end component;component kand3 port (a0,a1,a2: in std_logic;y: out std_logic);end component;component kor4 port (a0,a1,a2,a3: in std_logic;y: out std_logic);end component;

Page 10: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计的实例begin u1: kinv port map (n(3),n3_l); u2: kinv port map (n(2),n2_l); u3: kinv port map (n(1),n1_l); u4: kand2 port map (n3_l,n(0),n3l_n0); u5: kand3 port map (n3_l,n2_l,n(1),n3l_n2l_n1); u6: kand3 port map (n2_l,n(1),n(0),n2l_n1_n0); u7: kand3 port map (n(2),n1_l,n(0),n2_n1l_n0); u8: kor4 port map (n3l_n0,n3l_n2l_n1,n2l_n1_n0,n2_n1l_n0,f);end prime1_arch;

Page 11: VHDL 中的结构设计:元件例化语句

相关元件程序library ieee;use ieee.std_logic_1164.all;entity kinv is port (a: in std_logic; y: out std_logic);end kinv;architecture dat of kinv is begin y<= not a;end dat; library ieee;use ieee.std_logic_1164.all;entity kand2 is port (a0,a1: in std_logic; y: out std_logic);end kand2;architecture dat of kand2 is begin y<= a0 and a1;end dat;

Page 12: VHDL 中的结构设计:元件例化语句

相关元件程序library ieee;use ieee.std_logic_1164.all;entity kand3 is port (a0,a1,a2: in std_logic; y: out std_logic);end kand3;architecture dat of kand3 is begin y<= a0 and a1 and a2;end dat; library ieee;use ieee.std_logic_1164.all;entity kor4 is port (a0,a1,a2,a3: in std_logic; y: out std_logic);end kor4;architecture dat of kor4 is begin y<= a0 or a1 or a2 or a3;end dat;

Page 13: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计: generate 语句编号: for 指标 in 范围 generate

元件编号:元件名 port map(信号 1 ,信号 2 ,…); end generate

generate语句对同一结构体中使用的多个相同元件进行说明;语句中,指标为整数,不需要定义,各元件对应的信号此时成为数组,其下标由指标范围决定;

Page 14: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计: generate 语句也可以采用 if-generate 语句的形式控制电路的结构变化:编号: if 关系式 generate

元件语句;end generate;在关系式为 true时生成相关的元件;

Page 15: VHDL 中的结构设计:元件例化语句

generate 语句的使用实例8 位总线反相器 p.285 architecture str of inv8 iscomponent kinv port (a: in std_logic; y: out std_logic);end component;begin g1: for b in 7 downto 0 generate u1: kinv port map (x(b),y(b)); end generate;end str;

Page 16: VHDL 中的结构设计:元件例化语句

VHDL中的结构设计: generic 语句在原有元件中的定义: p.285 表 4-46 entity …. generic (参量名:参量类型;… .); port …..

在元件语句中赋值:元件编号:元件名 generic map(参量名=>常量值)port map(信号…);赋值后,参量名由具体常量值所替代。

Page 17: VHDL 中的结构设计:元件例化语句

generic 语句的使用实例n 位总线反相器设计 p.285 entity businv is generic (width:positive:=4); port (x: in std_logic_vector (width-1 downto 0); y:out std_logic_vector (width-1 downto 0) ); end businv;

Page 18: VHDL 中的结构设计:元件例化语句

generic 语句的使用实例architecture s of businv iscomponent kinv port (a: in std_logic; y: out std_logic); end component;begin g1: for b in width-1 downto 0 generate u1: kinv port map (x(b),y(b)); end generate;end s;

Page 19: VHDL 中的结构设计:元件例化语句

generic 语句的使用实例16位总线反相器设计:architecture s of inv16 iscomponent businv is generic (width:positive:=4); port (x: in std_logic_vector (width-1 downto 0); y:out std_logic_vector (width-1 downto 0) ); end component;begin u1: businv generic map(16) port map (x,y);end s;

Page 20: VHDL 中的结构设计:元件例化语句

元件语句的简化使用—宏调用元件的使用通常需要在结构体中进行说明,可能使程序显得很长;在很多综合工具中,允许将这种说明省略,只要进行了包含元件的资源说明,就可以在结构体中直接使用元件名称和相关的语句。

Page 21: VHDL 中的结构设计:元件例化语句

宏调用的使用实例16位总线反相器设计:library ieee;use ieee.std_logic_1164.all;use work.all; entity inv16 is port (x: in std_logic_vector (15 downto 0); y:out std_logic_vector (15 downto 0) ); end inv16; architecture s of inv16 isbegin u1: businv generic map(16) port map (x,y);end s;

Page 22: VHDL 中的结构设计:元件例化语句

宏调用的使用实例8 选 1 数据选择器设计( altera数据库的使用)library ieee;use ieee.std_logic_1164.all;library altera;use altera.maxplus2.all; entity mux8_alt is port(a,b,c,gn:in std_logic; d:in std_logic_vector(7 downto 0); y,wn:out std_logic);end mux8_alt; architecture str of mux8_alt isbegin mux:a_74151b port map(c,b,a,d,gn,y,wn);end str;

Page 23: VHDL 中的结构设计:元件例化语句

宏调用的使用实例24位寄存器的 LPM设计( LPM库的使用)library ieee; use ieee.std_logic_1164.all;library lpm; use lpm.lpm_components.all;entity reg24lpm is port(clk: in std_logic; d:in std_logic_vector(23 downto 0); q: out std_logic_vector(23 downto 0));end reg24lpm;architecture str of reg24lpm isbegin reg24: lpm_ff generic map (lpm_width =>24) port map (data=>d(23 downto 0),clock=>clk,q=>q(23 downto 0));end str;

Page 24: VHDL 中的结构设计:元件例化语句

结构设计的小结与图形输入设计法最接近,可以最直观地进行逻辑电路图的设计;电路直观,节点清楚,便于仿真分析调试;直接进行人工优化,能实现最优化的电路;使用语句种类最少,能够直接编译综合;

Page 25: VHDL 中的结构设计:元件例化语句

结构设计的小结便于实现层次化模块化设计;尤其适合于系统高层的设计;设计中人为干预较强,设计效果依赖经验,设计过程较长;进行层次设计时,需要先有底层的元件,才能进行上层元件及电路的设计。