2016-12-30 29 views
-1

我是VHDL的新手。我目前正在開發一個FSM,我希望我的狀態機只有在我的輸入發生變化時才改變狀態。我應該在下面的代碼中做出什麼改變?依賴於輸入事件的狀態轉換VHDL

entity fsm is 
    Port (clk : in STD_LOGIC; 
      reset : in STD_LOGIC; 
      x_in : in STD_LOGIC;       -- input Bitstream 
      y_out : out STD_LOGIC_VECTOR (1 downto 0)); -- Encoded output 
end fsm; 

----------------------------------------------------- 
architecture Behavioral of fsm is 

    -- Building an Enumerated type for the state machine 
    type state_type is (s_idle,s1,s2,s3,s4); -- constraint length = 3, Hence number of Regs = 2 therefore Number of states = 4 
    signal state, next_state: state_type ; -- Registers to hold the Present and next states 

begin 
----------------------------------------------------- 
    process1: process (reset, clk)    -- Sequential Logic Selection process: 
    begin 

      if (reset ='1') then 
       state <=s_idle;   
      elsif (clk='1' and x_in'Event) then  
       state <= next_state; 
      end if; 
-----------------------------------------------------   
    end process process1; 
+0

我編輯了你的問題,但從中間部分無法理解。您可能需要重新格式化它。 –

回答

0

假設你想使FSM改變狀態時 - >

  1. clk
  2. X_in值更改

另外,我會假設你的next_state變量是你沒有提到的state的組合函數。只需進行一次更改即可,將X_in添加到您的過程敏感性列表中。

----------------------------------------------------- 
    process1: process (X_in, reset, clk)    -- Sequential Logic Selection process: 
    begin 

      if (reset ='1') then 
       state <=s_idle;   
      elsif (clk='1' and x_in'Event) then  
       state <= next_state; 
      end if; 
-----------------------------------------------------   
    end process process1; 
+2

這不會合成;它不會將clk和x_in視爲適當的時鐘信號。 –

+0

如果我刪除了對clk的敏感度,它會工作嗎? – martianwars

+0

這是rising_edge()函數可以防止的那種錯誤。 –

0

假設x_in輸入同步到clk,這會做你的描述:

process1: process (reset, clk) 
begin 

     if (reset ='1') then 
      state <=s_idle;   
     elsif (clk='1' and clk'Event) then 
      x_in_prev <= x_in; 
      if x_in_prev /= x_in then 
       state <= next_state; 
      end if; 
     end if; 
end process process1; 

你需要在你的架構定義x_in_prev信號,這個編譯。