vhdl例化

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

元件声明是对VHDL模块(即底层设计,也是完整的VHDL设计)的说明,使之可在其他被调用,元件声明可放在程序包中,也可在某个设计的构造体中声明。

元件例化指元件的调用。

元件声明及元件例化的语法分别如下:
元件声明:
component〈元件实体名〉
prot(〈元件端口信息,同该元件实现时的实体的port部分〉);
end compnent;
—元件例化:
〈例化名〉:〈实体名,即元件名〉port map(〈端口列表〉);
例如,在一个设计中调用一个模为10的计数器cntm10和一个七段译码器decode47构成如下电路,则该调用过程孥即元件例化。

VHDL描述如下:
library ieee;
use ieee.std_logic_1164.all;
entity cntvh10 is
port (rd, ci, clk : in std_logic;
co : out std_logic;
qout : out std_logic_vector (6 downto 0));
end cntvh10;
architecture arch of cntvh10 is
Component decode47 is
port (adr : in std_logic_vector (3 downto 0);
decodeout : out std_logic_vector (6 downto0));
end Component;
—元件声明
Component cntm10 is
Port ( ci : in std_logic;
nreset : in std_logic;
clk : in std_logic;
co : out std_logic;
qcnt : buffer std_logic_vector (3 downto 0));
end Component;
signal qa: std_logic_vector (3 downto 0);
begin
u1 : cntm10 port map (ci, rd, clk, co, qa); —元件例化
u2 : decode47 port map ( decodeout=>qout, adr=>qa);
end arch;
元件例化时的端口列表可按位置关联方法,如u1,这种方法要求的实参(该设计中连接到端口的实际信号,如ci,等)所映射的形参(元件的对外接口信号)的位置同元件声明中的一样;元件例化时的端口列表也可按名称关联方法映射实参与形参,如u2。

格式为(形参1=>实参1,形参2=>实参2,···)。

这种方法与位置无关。

参数化元件可增加元件例化的灵活性。

所谓参数化元件是指元件的规模(或特性)可以通过引用参数的形式指定的一类元件。

例如,下面定义了一个位数可调的计数器:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
ues ieee.std_logic_unsigned.all;
entity cntnbits is
generic (cntwidth:integer:=4); —定义了一个可调参数
port ( ci : in std_logic;
nreset : in std_logic;
clk : in std_logic;
co : out std_logic;
qcnt : buffer std_logic_vector (3 downto 0));
end cntmbits;
architecture behave of antnbits is
constant allis1 : std_logic_vector (cntwidth-1 downto 0) := (others=>’1’); begin
Co <=’1’ when (qcnt=all is 1 and ci=’1’)else’0’;
Process (clk)
Begin
if (nreset=’0’) then
Qcnt<= (others=>’0’);
elsif (clk’event and clk=’1’) then
if (ci=’1’) then
Qcnt<=qcnt+1;
end if;
end if;
end process;
end behave;
可以算出,该计数器同第1部分的四位计数器相比,改动不大,其中在实体处增加了一行:
generic (cntwidth:integer:=4)
该行定义了一个整数cntwidth(计数宽度)并赋初值‘4’,用它代替原来的固定的计数器长度,若想设计的计数器位数8位,仅需将cntwidth初值赋为8:
generic (cntwidth : integer :=8);
若以此计数器为元件,则元件声明为:
Component cntnbit is
generic (cntwidth:integer:=4);
port ( ci : in std_logic;
nreset : in std_logic;
clk : in std_logic;
co : out std_logic;
qcnt : buffer std_logic_vector (cntwidth-1 downto 0));
end Component;。

相关文档
最新文档