-- -- TCNTR.vhd - Behavioral Model -- 1 minute timer. -- uses behavior of asynchronous counter. -- -- -- timer.vhd -- Version: v1.1 -- Library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_UNSIGNED.all; entity TIMER is port (C: in STD_LOGIC; -- clock (100Hz) EN: in STD_LOGIC; -- enable RST: in STD_LOGIC; -- reset RUN: in STD_LOGIC; -- start/stop ('1' means run) Q3: out STD_LOGIC_VECTOR (3 downto 0); -- 10 Sec Q2: out STD_LOGIC_VECTOR (3 downto 0); -- 1 Sec Q1: out STD_LOGIC_VECTOR (3 downto 0); -- 1/10 Sec Q0: out STD_LOGIC_VECTOR (3 downto 0)); -- 1/100 Sec end TIMER; architecture TIMER_BEH of TIMER is signal QTEMP3, QTEMP2, QTEMP1, QTEMP0, Qst3, Qst2, Qst1, Qst0: STD_LOGIC_VECTOR (3 downto 0); signal CARRY3, CARRY2, CARRY1: STD_LOGIC; begin D0: process (C, RST, RUN) begin if RST = '1' then -- RESET the timer QTEMP0 <= "0000"; CARRY1 <='0'; elsif (C'event and C='0') then if RUN = '1' then -- the RUN needs to be checked here only since this cell drives the next QTEMP0 <= QTEMP0 + 1; else null; end if; if QTEMP0 = "1001" then QTEMP0 <= "0000"; CARRY1 <= '1'; else CARRY1 <= '0'; end if; end if; end process; D1: process (CARRY1, RST) begin if RST = '1' then -- RESET the timer QTEMP1 <= "0000"; CARRY2 <='0'; elsif (CARRY1'event and CARRY1='1') then QTEMP1 <= QTEMP1 + 1; if QTEMP1 = "1001" then QTEMP1 <= "0000"; CARRY2 <= '1'; else CARRY2 <= '0'; end if; end if; end process; D2: process (CARRY2, RST) begin if RST = '1' then -- RESET the timer QTEMP2 <= "0000"; CARRY3 <='0'; elsif (CARRY2'event and CARRY2='1') then QTEMP2 <= QTEMP2 + 1; if QTEMP2 = "1001" then QTEMP2 <= "0000"; CARRY3 <= '1'; else CARRY3 <= '0'; end if; end if; end process; D3: process (CARRY3, RST) begin if RST = '1' then QTEMP3 <= "0000"; elsif (CARRY3'event and CARRY3='1') then QTEMP3 <= QTEMP3 + 1; if QTEMP3 = "0101" then QTEMP3 <= "0000"; else null; end if; end if; end process; Qst3 <= "0000" when RST = '1' else QTEMP3 when EN = '1' else Qst3; Qst2 <= "0000" when RST = '1' else QTEMP2 when EN = '1' else Qst2; Qst1 <= "0000" when RST = '1' else QTEMP1 when EN = '1' else Qst1; Qst0 <= "0000" when RST = '1' else QTEMP0 when EN = '1' else Qst0; Q3 <= Qst3; Q2 <= Qst2; Q1 <= Qst1; Q0 <= Qst0; end TIMER_BEH;