-- entity declaration for a BCD counter with an -- asynchronous reset input. -- (reworked from solution to Ashenden problem 5.26) LIBRARY ieee; USE ieee.std_logic_1164.all; architecture spec of bcd_counter is begin count : process (clock, reset) is variable next_q : std_logic_vector(3 downto 0) := "0000"; variable carry : std_logic; begin if reset = '1' then next_q := "0000"; q <= "0000"; elsif en = '1' and rising_edge(clock) then carry := '1'; -- to increment for n in 0 to 3 loop if next_q(n) = '0' then next_q(n) := carry; carry := '0'; else next_q(n) := not carry; end if; end loop; -- check for values 10 and over and make them 0 if next_q(3) = '1' and (next_q(2) = '1' or next_q(1) = '1') then next_q := "0000"; sync <= '1'; else sync <= '0'; end if; q <= next_q; end if; end process count; end architecture spec;