程序计数器增量不起作用

时间:2014-10-01 07:03:31

标签: vhdl counter increment

一切正常但增量功能。它可以从0增加到1,1到2,然后从2增加到" 1111111111"。我很难过。

变量:

D_IN:

中的数据

PC_OE:活跃高。驱动PC_TRI输出。

PC_LD:高电平有效同步将D_IN加载到PC中。

PC_INC:高电平有效同步增加PC中的值。

RST:有效的高异步复位。

PC_COUNT:PC中的当前值。地址。

PC_TRI:三态控制下PC中的当前值。当PC_OE =&#39; 1&#39;时,PC_TRI <= PC_COUNT,否则为高阻抗。

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

use IEEE.STD_LOGIC_ARITH.ALL; 


entity ProgramCounter is
    Port ( D_IN : in  STD_LOGIC_VECTOR (9 downto 0);

           PC_OE : in  STD_LOGIC;

           PC_LD : in  STD_LOGIC;

           PC_INC : in  STD_LOGIC;

           RST : in  STD_LOGIC;

           CLK : in  STD_LOGIC;

           PC_COUNT : out  STD_LOGIC_VECTOR (9 downto 0);

           PC_TRI : out  STD_LOGIC_VECTOR (9 downto 0));


end ProgramCounter;

architecture Behavioral of ProgramCounter is

signal s_COUNT : STD_LOGIC_VECTOR (9 downto 0);

begin

s_COUNT <= "0000000000";

proc: process(RST, CLK, PC_LD, D_IN, s_COUNT, PC_INC, PC_OE)
begin

    if  (RST = '1') then
        s_COUNT <= "0000000000";
    elsif (rising_edge(CLK)) then

        if (PC_LD = '1') then
            s_COUNT <= D_IN;
        elsif (PC_INC = '1') then
            s_COUNT <= s_COUNT + 1;
        else
      end if;

    else
    end if;

if (PC_OE = '1') then
    PC_TRI <= s_COUNT;
else
    PC_TRI <= "ZZZZZZZZZZ";
end if;

PC_COUNT <= s_COUNT;

end process proc;

end Behavioral;

2 个答案:

答案 0 :(得分:0)

QuantumRipple的评论非常有用

begin
--s_COUNT <= "0000000000";
...

我试着评论这条线,但它确实奏效了。 尝试这样做,并在开始计算之前制作RST

答案 1 :(得分:-1)

请尝试这种方式让我知道,我更正了你的代码,但我无法尝试:

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

use IEEE.STD_LOGIC_ARITH.ALL; 


entity ProgramCounter is
    Port ( D_IN : in  STD_LOGIC_VECTOR (9 downto 0);

           PC_OE : in  STD_LOGIC;

           PC_LD : in  STD_LOGIC;

           PC_INC : in  STD_LOGIC;

           RST : in  STD_LOGIC;

           CLK : in  STD_LOGIC;

           PC_COUNT : out  STD_LOGIC_VECTOR (9 downto 0);

           PC_TRI : out  STD_LOGIC_VECTOR (9 downto 0));


end ProgramCounter;

architecture Behavioral of ProgramCounter is

signal s_COUNT : STD_LOGIC_VECTOR (9 downto 0);

begin

proc: process(RST, CLK)
begin

    if  (RST = '1') then
        s_COUNT <= "0000000000";
    elsif (rising_edge(CLK)) then

        if (PC_LD = '1') then
            s_COUNT <= D_IN;
        elsif (PC_INC = '1') then
            s_COUNT <= s_COUNT + 1;
        else
      end if;

    else
    end if;
end process;

PC_TRI <= s_COUNT when (PC_OE = '1') else (others => 'Z');
PC_COUNT <= s_COUNT;



end Behavioral;