Для малых модулей счета (малых N) быстрее, чем на lpm_counter, получаются счетчики, написанные в лоб. А для больших quartus сам подставит lpm_counter вместо вашего функционального блока
library ieee, work; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
entity pp_counter is generic ( width : integer := 8; modulus : integer := 250; avalue : integer := 15; svalue : integer := 0 ); port ( din : in std_logic_vector (width-1 downto 0); sload : in std_logic := '0'; sset : in std_logic := '0'; sclr : in std_logic := '0'; updown : in std_logic := '1'; -- '0' - down, '1' - up cnt_en : in std_logic; clk : in std_logic; aload : in std_logic := '0'; aclr : in std_logic := '0'; aset : in std_logic := '0'; dout : out std_logic_vector (width-1 downto 0); cout : out std_logic; is_zero : out std_logic ); end pp_counter;
architecture behav of pp_counter is signal value : unsigned (width-1 downto 0); begin
process (din, cnt_en, clk, aclr, aset, aload) begin if (aclr='1') then value <= (others => '0'); elsif (aset='1') then value <= to_unsigned(avalue, width); elsif (aload='1') then value <= unsigned(din); elsif (cnt_en='1' and rising_edge(clk))then if (sclr='1') then value <= (others => '0'); elsif (sset='1') then value <= to_unsigned(svalue, width); elsif (sload='1') then value <= unsigned(din); else if (updown='1') then if (value=(modulus-1)) then value <= (others => '0'); else value <= value + to_unsigned(1, width); end if; else if (value=0) then value <= to_unsigned(modulus-1, width); else value <= value - to_unsigned(1, width); end if; end if; end if; end if; end process;
dout <= std_logic_vector(value);
cout <= '1' when (value=(modulus-1)) else '0'; is_zero <= '1' when (value=0) else '0'; end behav;
|