conditional assignmentを使ってconcurrent領域に記述する。シンプルに書けるがほかで目にしたことはない。/=
は、割って代入ではなくnot equal。ここでは4ビットカウンターにした。
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity sute is generic( NUM_BITS : natural := 4 ); port( aclr_n : in std_logic; clk : in std_logic; count : out std_logic_vector(NUM_BITS-1 downto 0) ); end entity; architecture rtl of sute is constant COUNT_TOP : unsigned(count'range) := (others => '1'); signal count_tmp : unsigned(count'range) := (others => '0'); begin count_tmp <= (others => '0') when not aclr_n else --!非同期クリア (others => '0') when rising_edge(clk) and count_tmp = COUNT_TOP else --オーバーフロー count_tmp + 1 when rising_edge(clk) and count_tmp /= COUNT_TOP; --カウントアップ count <= std_logic_vector(count_tmp); end architecture;