階層設計において定義をトップエンティティで行う
場合、generic文を使用します。
クロックの分周 Divider.vhd
-- Divider
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DIVIDER is
generic(
CLK_BIT : integer
);
port(
CLK : in std_logic;
RESET : in std_logic;
DIV_CLK_2HZ : out std_logic;
DIV_CLK_32HZ: out std_logic
);
end DIVIDER;
architecture RTL of DIVIDER is
signal DIV_COUNTER : std_logic_vector(CLK_BIT-1 downto 0);
begin
process(CLK,RESET)
begin
if (RESET = '0') then
DIV_COUNTER <= (others => '0');
elsif (CLK'event and CLK = '0') then
DIV_COUNTER <= DIV_COUNTER + 1;
end if;
end process;
DIV_CLK_2HZ <= not DIV_COUNTER(CLK_BIT-2);
DIV_CLK_32HZ <= not DIV_COUNTER(CLK_BIT-5);
end RTL;
トップエンティティ Counter24top.vhd の違う部分のみ
---
component DIVIDER
generic(
CLK_BIT : integer
);
port(
CLK : in std_logic;
RESET : in std_logic;
DIV_CLK_2HZ : out std_logic;
DIV_CLK_32HZ: out std_logic
);
end component;
---
---
U1 :DIVIDER
generic map (25)
port map (CLK, RESET, CLK_2Hz, open);
---
この方法だと、定数はトップエンティティで指定することになります。