Program Counter's Increment Won't Work

[亡魂溺海] 提交于 2019-12-11 21:04:45

问题


Everything works but the increment function. It can increment from 0 to 1, 1 to 2, and then from 2 it goes to "1111111111". I'm stumped.

Variables:

D_IN: Data in

PC_OE: Active high. Drives PC_TRI output.

PC_LD: Active high synchronously loads D_IN into PC.

PC_INC: Active high synchronously increments value in PC.

RST: Active high asyncronous reset.

PC_COUNT: Current value in PC. Address.

PC_TRI: Current value in the PC under tri-state control. When PC_OE = '1', PC_TRI <= PC_COUNT, else high impedance.

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;

回答1:


The comment of QuantumRipple is very useful

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

I tried to comment such line and it worked. Try to do this, and make RST before start to count




回答2:


Please try this way and let me know, i corrected your code but I can't try it :

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;


来源:https://stackoverflow.com/questions/26135823/program-counters-increment-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!