为什么VHDL移位寄存器需要2个时钟rising_edge才能移位



我正在尝试使用 D 触发器制作 8 位移位寄存器。问题在于,在仿真时,寄存器需要两个时钟上升沿来移动,一个用于D输入变化,另一个用于Q变化。我不知道为什么。

entity Registry_8 is
  port (input  : in  std_logic;
        output : out std_logic;
        clk    : in  std_logic;
        clear  : in  std_logic;
        load   : in  std_logic;
        LR     : in  std_logic;
        pIn    : in  std_logic_vector (7 downto 0);
        pOut   : out std_logic_vector (7 downto 0);
        shift  : in  std_logic);
end Registry_8;
architecture Behavioral of Registry_8 is
  component D_flipflop
    port(D, clk, clear, preset : in  std_logic;
         Q, Q_b                : out std_logic);
  end component;
  signal D, Q : std_logic_vector (7 downto 0);
begin
  GEN_FLIP :
  for i in 0 to 7 generate
    D_i : D_flipflop port map(clk => clk, preset => '0', clear => clear, D => D(i), Q => Q(i));
  end generate GEN_FLIP;
  process (clk, load, LR, shift)
  begin
    if (load = '1')
    then D <= pIn;
    end if;
    if (clk'event and clk = '1' and shift = '1')
    then
      if (LR = '0')
      then D(7 downto 0) <= Q(6 downto 0) & input;
           output <= Q(7);
      else
        D(7 downto 0) <= input & Q(7 downto 1);
        output        <= Q(0);
      end if;
    end if;
  end process;
  pOut <= Q;
end Behavioral;

在此过程中,存在时钟边沿敏感条件,表达式为:

clk'event and clk = '1'

因此,该过程实现了附加级别的顺序逻辑(翻转flops),但您可能想为纯组合创建一个过程设计,如:

process (all) is
begin
  if (load = '1') then
    D <= pIn;
  end if;
  if shift = '1' then
    if (LR = '0') then
      D(7 downto 0) <= Q(6 downto 0) & input;
      output        <= Q(7);
    else
      D(7 downto 0) <= input & Q(7 downto 1);
      output        <= Q(0);
    end if;
  end if;
end process;

请注意,VHDL-2008 all用作上面的灵敏度列表,以自动包括组合设计过程中使用的所有信号。

最新更新