我有这个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