2016-06-28 34 views
0

我有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,我不能在主程序

回答

1

8个触发器改变第一触发器的输出,其重置为'0',您可以使用您提供的代码。对于其他的触发器可以创建另一个实体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; 

这种方式与你想有一个单独的触发器实体的方式是一致的。

+0

这么简单的解决方案。我怎么没有这样做。谢谢! – levshkatov

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; 

然后,当你使用它来创建8名FF的是重置为“0”,1个FF是重置为“1”:

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; 
2

为什么有d_ff实体呢?为什么要有一个单独的层次结构?没有VHDL的专业用户会这样做,除非有特殊原因。相反,只需实现9个触发器作为一个过程:

process (clk) is 
    begin 
     if rst='0' then 
      q < = "000000001"; 
     elsif rising_edge(clk) then 
      q <= d; 
     end if; 
    end process;