请选择 进入手机版 | 继续访问电脑版

集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1411|回复: 3

FPGA学习之VHDL实例化

[复制链接]
fpga_feixiang 发表于 2017-11-22 14:47:31 | 显示全部楼层 |阅读模式
实例化就是把已经写好的元件在新的元件中调用,从而组成更大的元件。

下面基础元件是一个十进制计数器,然后用三个计数器组成了一个更大的计数器。

看代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity cnt10 is
port(clk,clr,en:in std_logic;
   qut std_logic_vector(3 downto 0);
   cout std_logic);
end entity;

architecture rtl of cnt10 is
signal tmp:std_logic_vector(3 downto 0);
begin
process(clk,clr,en)
begin
if clr='1' then
   tmp<="0000";
elsif rising_edge(clk) then
   if en='1' then
    if tmp="1001" then
     tmp<="0000";
    else
     tmp<=tmp+'1';
    end if;
   end if;
end if;
end process;

process(tmp)
begin
   if tmp="0000" then
    co<='1';
   else
    co<='0';
   end if;
end process;
q<=tmp;
end;

生成的rtl文件如下:

FPGA学习之VHDL实例化(15) - 白色 - gor
然后是顶层代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity watch is
port(clk0,clr0,en0:in std_logic;
   dataoutut std_logic_vector(11 downto 0));
end entity;

architecture rtl of watch is
component cnt10 is                              --这里是说明已有的元件
port(clk,clr,en:in std_logic;
   qut std_logic_vector(3 downto 0);
   cout std_logic);
end component;

signal co1:std_logic;
signal co2:std_logic;

begin
U1:cnt10 port map(clk0,clr0,en0,dataout(3 downto 0),co1);    --把已有的元件实例化到具体的器件
U2:cnt10 port map(co1, clr0,en0,dataout(7 downto 4),co2);
U3:cnt10 port map(co2, clr0,en0,dataout(11 downto 8));
end;

生成的rtl文件如下:

FPGA学习之VHDL实例化(15) - 白色 - gor
因为通常芯片用的晶振为50Mhz,所以肯定也是需要分频的,这次就没分频了,练习嘛。

其实和verilog的实例化还是大同小异的。
zhangyukun 发表于 2017-11-23 09:00:05 | 显示全部楼层
FPGA学习之VHDL实例化
大鹏 发表于 2022-6-22 14:50:52 | 显示全部楼层
FPGA学习之VHDL实例化
LYF 发表于 2022-6-22 17:56:36 | 显示全部楼层
FPGA学习之VHDL实例化
http://www.fpgaw.com/forum.php?m ... 7&fromuid=59610
(出处: fpga论坛|fpga设计论坛)
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-3-29 06:51 , Processed in 0.063948 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表