2017-04-27 61 views
0

當進程2沒有變化時,進程2保持激活狀態。我有一塊電路板來測試我的代碼,當我翻動時鐘(我將時鐘設置爲一個按鈕)時,狀態會改變。在我的代碼中,只有我翻動秦纔會改變狀態。所以它沒有做我希望它做的事情,我花了很多時間去試圖找出造成它的原因,但我做不到。請幫忙。如圖所示,在圖中,PS(present_state)的輸出是正確的,但在板中,它不是正確的輸出。我發現有一件事情非常重要,我嘗試輸出next_state,當我將Qin翻轉爲'1',狀態顯示爲「001」,然後我將clk翻轉爲'1',狀態變爲「010 「,這不會發生。我希望這是一個重要的信息。當信號的變化,但每次分配的東西信號,即使它像以前那樣具有相同的價值當靈敏度列表不變時,VHDL進程被激活

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

-- Uncomment the following library declaration if using 
-- arithmetic functions with Signed or Unsigned values 
--use IEEE.NUMERIC_STD.ALL; 

-- Uncomment the following library declaration if instantiating 
-- any Xilinx leaf cells in this code. 
--library UNISIM; 
--use UNISIM.VComponents.all; 

entity VendingMechine is 
    Port (Clk : in STD_LOGIC; 
      Reset : in STD_LOGIC; 
      Cr : in STD_LOGIC; 
      Qin : in STD_LOGIC; 
      S : in STD_LOGIC; 
      CB : in STD_LOGIC; 
      W : in STD_LOGIC; 
      CRo : out STD_LOGIC_VECTOR(1 DOWNTO 0); 
      Qo : out STD_LOGIC; 
      PS : out STD_LOGIC_VECTOR(2 DOWNTO 0); 
      Wo : out STD_LOGIC; 
      CBo : out STD_LOGIC; 
      So : out STD_LOGIC); 
end VendingMechine; 

architecture Behavioral of VendingMechine is 
    TYPE state IS(Idle, S1, S2, S3, Soda, Candy, Water); 
    Signal Next_State : state; 
    Signal Present_State : state := Idle; 
begin 

Process1:Process(clk, reset) 
begin 
    if(reset = '1') THEN 
     Present_State <= Idle; 
    elsif rising_edge(clk) THEN Present_State <= Next_State; 
    end if; 
end process; 

Process2:Process(Qin, Present_State, Cr, S, w) 
begin 
    Next_State <= Present_State; 
    CRo <= "00"; Qo <= '0'; PS <= "000"; Wo <= '0'; CBo <= '0'; So <= '0'; 
    CASE Present_State IS 
     When Idle => 
      PS <= "000"; 
      if Qin='1' Then Next_State <= S1; 
      else Next_State <= Idle; 
      end if; 
     When S1 => 
      PS <= "001"; 
      if Qin='1' Then Next_State <= S2; 
      elsif Cr = '1' Then Cro <= "01"; Next_State <= Idle; 
      else Next_State <= S1; 
      end if; 
     When S2 => 
      PS <= "010"; 
      if Qin='1' Then Next_State <= S3; 
      elsif Cr = '1' Then CRo <="10"; Next_State <= Idle; 
      elsif S = '1' Then Next_State <= Soda; 
      elsif CB = '1' Then Next_State <= Candy; 
      else Next_State <= S2; 
      end if; 
     When S3 => 
      PS <= "011"; 
      if Cr = '1' Then CRo <= "11"; Next_State <= Idle; 
      elsif S = '1' Then Qo <= '1'; Next_State <= Soda; 
      elsif CB = '1' Then Qo <= '1'; Next_State <= Candy; 
      elsif W = '1' Then Next_State <= Water; 
      elsif Qin = '1' Then Qo <= '1'; 
      else Next_State <= S3; 
      end if; 
     When Soda => 
      PS <= "100"; 
      So <= '1'; 
      Next_State <= Idle; 
     When Candy => 
      PS <= "101"; 
      CBo <= '1'; 
      Next_State <= Idle; 
     When Water => 
      PS <= "110"; 
      Wo <= '1'; 
      Next_State <= Idle; 
    END CASE; 
end process; 
end Behavioral; 
+0

我說過,當我翻轉Qin,Cr,S,W時,狀態會改變 –

+1

您可以提供一個測試臺來模擬您的代碼並查看它行爲? – Roman

+0

我在我的線程中添加testbench圖形,看看你是否願意 –

回答

0

過程將推出不但。這可能是原因。在平行過程中,你不能依賴時間發射,但是在某些情況下會導致輸入。

0

Qin連接到外部開關?如果是的話,你應該在輸入端實現時鐘域同步(和可能的去抖動)。

如果你不知道怎麼做,請在評論中告訴我。

缺少時鐘同步信號會導致狀態機中的毛刺和掛起。沒有反彈將導致多個開關脈衝("bouncing"