在VHDL过程中“等待”一个时钟周期

时间:2018-10-26 12:45:23

标签: vhdl

假设存在一个如下所示的RAM组件实体

entity RAM is
   port(
      -- other port such as clk, reset, ...
      en: in std_logic;
      addr: in std_logic_vector(7 downto 0);
      dataR: out std_logic_vector(7 downto 0));
end RAM;

RAM规范是,当en = '1'时,addr上存储的值在dataR之后一个时钟周期可用。

就目前而言,我使用RAM组件的过程如下:

process(state)
begin
  case(state) is
    -- ...
    when ReadMemory =>
       addr <= "00000000";
       en <= '1';
       next_mem <= dataR;

    -- ...
  end case;
end process;

此设计不起作用,因为在设置dataRaddr的同一时钟周期读取了en

如何才能“等待”单个clck周期以便从内存中读取正确的值?

1 个答案:

答案 0 :(得分:0)

您正在使用有限状态机,因此可以使用“等待”状态

process(state)
begin
    case(state) is
    -- ...
        when ReadMemory =>
            addr <= "00000000";
            en <= '1';

            next_state <= WaitMemory;
        when WaitMemory =>
            next_mem <= dataR;
            next_state <= another_state;
    -- ...
    end case;
end process;

请注意,使用某种有限状态机可能需要等待2个时钟。为了更具体,使用这种FSM:

process(CLK)
begin
    if rising_edge(CLK) then
        state <= next_state;
    end if;
end process;

process(state)
begin
    case(state) is
    -- ...
       -- YOUR FSM with next_state attribution
    -- ...
    end case;
end process;

您必须等待1个时钟。 但是有了这个:

process(CLK)
begin
    if rising_edge(CLK) then
        case(state) is
        -- ...
           -- YOUR FSM with state attribution
        -- ...
        end case;
    end if;
end process;

您将需要等待2个时钟