我有這個PC
模塊,很簡單(代碼結尾)。我首先生成一些輸入信號port_int
,並在過程結束時說pc_out <= port_int
。我的目標是根據輸入信號增加或增加或減少PC。VHDL內部信號改變輸出 - 不工作?
在仿真中,內部port_int
信號工作正常,但pc_out
沒有。這是爲什麼發生?看看模擬:
看看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;
編輯:
當我導入模塊在整個處理器中,發生這種情況: 相同pc_out
信號奇怪行爲,並且所有輸入都是相同的。我只在一個地方使用pc_out
信號來選擇存儲器。 爲什麼它不正常?這可能導致什麼?
是的,這解決了我的問題!謝謝! – Vidak
還有一件事,當我將這個模塊連接到一個更高的模塊時,pc_out不會像它應該那樣改變。所有輸入信號保持不變,然而'pc_out'從'0000'變爲'0100'而不是'0001'。我在另一個模塊中使用'pc_out'作爲輸入,會影響它嗎?我沒有做任何事情,只是簡單的閱讀。 – Vidak
@Vidak很難說......你是在混合「TO」還是「DOWNTO」?這可能導致位翻轉。 – godel9