2013-12-18 42 views
1

我有這個PC模塊,很簡單(代碼結尾)。我首先生成一些輸入信號port_int,並在過程結束時說pc_out <= port_int。我的目標是根據輸入信號增加或增加或減少PC。VHDL內部信號改變輸出 - 不工作?

在仿真中,內部port_int信號工作正常,但pc_out沒有。這是爲什麼發生?看看模擬: sim

看看port_int如何改變,因爲它應該,而pc_out是遲到。後來在模擬中,pc_out變得更糟,變化不規則,甚至不遲到。

我在做什麼錯?有沒有另一種方法來改變pc_out? Bcoz你不能改變out信號,我已經告訴inout是非常不好的做法..

下面的代碼:

entity PC is 
    Port (clk : in STD_LOGIC; 
     enable : in STD_LOGIC; 
     reset : in STD_LOGIC; 
     pc_out : out STD_LOGIC_VECTOR (3 downto 0); 
     data : in STD_LOGIC_VECTOR (3 downto 0); -- jump value 
     zero : in STD_LOGIC; -- jump condition 
     jmp_en : in STD_LOGIC;  -- jump enable 
     jmp_dir : in STD_LOGIC; -- jump direction 
     ctrl_en : out STD_LOGIC); -- output signal 
end PC; 

architecture Behavioral of PC is 

type state_type is (s0, s1, s2, s3); 
signal reg_state, next_state : state_type; 

signal port_int : std_logic_vector(3 downto 0); 

begin 

state_transition: process(clk, reset) 
begin 
    if (reset = '1') then 
     reg_state <= s0; 
    elsif(rising_edge(clk)) then 
     reg_state <= next_state; 
    end if; 
end process; 

next_state_logic: process(reg_state, enable) 
begin 
    case reg_state is 
     when s0 => 
      if(enable = '1') then 
       next_state <= s2; 
      else 
       next_state <= s1; 
      end if; 

     when s1 => 
      if(enable = '1') then 
       next_state <= s2; 
      else 
       next_state <= s1; 
      end if; 

     when s2 => 
      next_state <= s3; 

     when s3 => 
      if(enable = '1') then 
       next_state <= s2; 
      else 
       next_state <= s1; 
      end if; 
    end case; 
end process; 

output_logic: process(reg_state, zero, jmp_en, jmp_dir, data) 
begin 
    case reg_state is 
     when s0 => 
      pc_out <= "0000"; 
      port_int <= "0000"; 
      ctrl_en <= '0'; 

     when s1 => 
      ctrl_en <= '0'; 

     when s2 => 
      if(zero = '1' and jmp_en = '1' and jmp_dir = '1')then 
       port_int <= port_int + data; -- jump forward 
      elsif(zero = '1' and jmp_en = '1' and jmp_dir = '0')then 
       port_int <= port_int - data; -- jump backward 
      else -- nije ispunjen uslov skoka 
       port_int <= port_int + '1'; -- increment PC 
      end if; 
      pc_out <= port_int; 

     when s3 => 
      ctrl_en <= '1'; 
    end case; 
end process; 

end Behavioral; 

編輯:

當我導入模塊在整個處理器中,發生這種情況: sim3 相同pc_out信號奇怪行爲,並且所有輸入都是相同的。我只在一個地方使用pc_out信號來選擇存儲器。 爲什麼它不正常?這可能導致什麼?

回答

1

計算輸出值的第二個過程(output_logic:過程)有一些問題。

首先,回顧,它實現一個組合電路(因此,無記憶),所以像port_int方程< = port_int +數據只能如果port_int的值被存儲在某處計算。順便說一句,固定代碼後,您可以直接刪除內部信號port_int並使用pc_out

其次,作爲該過程的一個組合電路,必須指定其全部真值表;否則,將推斷鎖存器。請注意,例如,只有ctrl_en的值在狀態s1中指定。您必須在所有狀態中指定所有輸出值(相同列表),或者等價地,您可以在個案個案之前創建一個輸出值列表,以便編譯器在未明確聲明值時將它們用作默認值。

2

如果我明白你正確地做什麼,你只需要process塊外面一條語句:

pc_out <= port_int; 

採取一切其他語句分配的東西pc_out你的設計中。我想你會被<=運營商絆倒,該運營商會等到下一次模擬增量時才真正更新信號驅動器。

+0

是的,這解決了我的問題!謝謝! – Vidak

+0

還有一件事,當我將這個模塊連接到一個更高的模塊時,pc_out不會像它應該那樣改變。所有輸入信號保持不變,然而'pc_out'從'0000'變爲'0100'而不是'0001'。我在另一個模塊中使用'pc_out'作爲輸入,會影響它嗎?我沒有做任何事情,只是簡單的閱讀。 – Vidak

+0

@Vidak很難說......你是在混合「TO」還是「DOWNTO」?這可能導致位翻轉。 – godel9