我有9个触发器和一个复位输入。当重置为0
时,我需要将8个触发器的输出设置为0
。并将一个触发器输出到1
。这个触发器独一无二,永不改变。怎么做?
触发器代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity d_ff is
port
(
clk : in std_logic;
rst : in std_logic;
d : in std_logic;
q : out std_logic
);
end entity d_ff;
architecture logicFunc of d_ff is
begin
process (clk) is
begin
if (rst='0') then
q <= '0';
elsif (clk'event and clk = '1') then
q <= d;
end if;
end process;
end architecture logicFunc;
现在,当重置为0
时,此代码将所有触发器设置为0
,并且我无法在主程序中更改第一个触发器的输出
答案 0 :(得分:3)
另一种方法是使用泛型。这允许您对所有d_ff实例使用完全相同的代码。例如:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity d_ff is
generic
(
RESET_VALUE : std_logic
);
port
(
clk : in std_logic;
rst : in std_logic;
d : in std_logic;
q : out std_logic
);
end entity d_ff;
architecture logicFunc of d_ff is
begin
process (clk) is
begin
if (rst='0') then
q <= RESET_VALUE;
elsif (clk'event and clk = '1') then
q <= d;
end if;
end process;
end architecture logicFunc;
然后当你利用它来创建重置为'0'的8个FF和重置为'1'的1个FF时:
library ieee;
use ieee.std_logic_1164.all;
entity foo is
port map
(
clk : in std_logic;
rst : in std_logic;
d : in std_logic_vector(8 downto 0);
q : out std_logic_vector(8 downto 0)
)
end entity foo;
architecture structural of foo is
begin
ff_gen : for i in 0 to 7 generate
begin
ff : entity work.d_ff
generic map
(
RESET_VALUE => '0'
)
port map
(
clk => clk,
rst => rst,
d => d(i),
q => q(i)
);
end generate ff_gen;
ff0_gen : entity work.d_ff
generic map
(
RESET_VALUE => '1'
)
port map
(
clk => clk,
rst => rst,
d => d(8),
q => q(8)
);
end architecture structural;
答案 1 :(得分:2)
为什么要有<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
</configuration>
个实体?为什么要有单独的层次结构? VHDL的专业用户不会这样做,除非有一些特殊原因。相反,只需将9个触发器实现为一个过程:
d_ff
答案 2 :(得分:1)
重置为“0”的8个触发器可以使用您提供的代码。对于另一个触发器,您可以创建另一个实体d_ff1:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity d_ff1 is
port
(
clk : in std_logic;
rst : in std_logic;
d : in std_logic;
q : out std_logic
);
end entity d_ff1;
architecture logicFunc of d_ff1 is
begin
process (clk) is
begin
if (rst='0') then
q <= '1';
elsif (clk'event and clk = '1') then
q <= d;
end if;
end process;
end architecture logicFunc;
这种方式符合你想要一个单独的触发器实体的方式。