0

我有 9 个触发器和一个复位输入。我需要将 8 个触发器的输出设置为0复位时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,我无法更改主程序中第一个触发器的输出

4

3 回答 3

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;
于 2016-06-29T04:25:52.063 回答
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;
于 2016-06-29T07:40:50.830 回答
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;

这种方式与您希望拥有单独的触发器实体的方式保持一致。

于 2016-06-28T13:06:52.570 回答