Вот два примера из Active-HDL. попробуйте их.
--library IEEE; --use IEEE.std_logic_1164.all; --use IEEE.STD_LOGIC_UNSIGNED.all; -- CLK: in STD_LOGIC; -- RESET: in STD_LOGIC; -- CE: in STD_LOGIC; -- LOAD: in STD_LOGIC; -- DIR: in STD_LOGIC; -- DIN: in STD_LOGIC_VECTOR (3 downto 0); -- COUNT: out STD_LOGIC_VECTOR (3 downto 0) signal COUNT_INT: STD_LOGIC_VECTOR(3 downto 0); begin process (CLK, RESET) begin if RESET = '1' then COUNT_INT <= (others => '0'); elsif CLK'event and CLK='1' then -- elsif rising_edge(CLK) then if LOAD = '1' then COUNT_INT <= DIN; else if CE = '1' then if DIR = '1' then --count up COUNT_INT <= COUNT_INT + 1; else --count down COUNT_INT <= COUNT_INT - 1; end if; end if; end if; end if; end process; COUNT <= COUNT_INT;
=========================
-- 0 to 15 Synchronous Counter (for INTEGERS) -- CLK: in STD_LOGIC; -- RESET: in STD_LOGIC; -- CE, LOAD, DIR: in STD_LOGIC; -- DIN: in INTEGER range 0 to 15; -- COUNT: out INTEGER range 0 to 15;
--auxiliary signal COUNTER declaration --the output port "COUNT" cannot appear on the right side of assignment --statements signal COUNTER: INTEGER range 0 to 15;
begin process (CLK, RESET) begin if RESET='1' then COUNTER <= 0; elsif CLK='1' and CLK'event then if LOAD='1' then COUNTER <= DIN; else if CE='1' then if DIR='1' then if COUNTER = 15 then COUNTER <= 0; else COUNTER <= COUNTER + 1; end if; else if COUNTER = 0 then COUNTER <= 15; else COUNTER <= COUNTER - 1; end if; end if; end if; end if; end if; end process; COUNT <= COUNTER;
|