--================================================================================== -- -- timer = 100.000.000) -> 1/1 second -- timer = 50.000.000) -> 1/2 second = 500 mili second -- timer = 25.000.000) -> 1/4 second = 250 mili second -- timer = 10.000.000) -> 1/10 second = 100 mili second -- timer = 100.000) -> 1/1000 second = 1 mili second -- timer = 50.000) -> 1/2000 second = 0.5 mili second = 500 micro second --=================================================================================== LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.NUMERIC_STD.ALL; entity Stop_Watch is Port ( clk : IN STD_LOGIC ; -- 100 MHz OPERATION : IN STD_LOGIC ; RESET : IN STD_LOGIC ; Period_Info : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ; SW_Period_Over_Flag : OUT STD_LOGIC ; Period : OUT INTEGER range 0 to 5*10E+3); end Stop_Watch; architecture Behavioral of Stop_Watch is signal s_clk : STD_LOGIC ; signal s_OPERATION : STD_LOGIC ; signal s_RESET : STD_LOGIC ; signal s_SW_Period_Over_Flag : STD_LOGIC ; signal s_Period_Info : STD_LOGIC_VECTOR(3 DOWNTO 0) ; signal i_Period : INTEGER range 0 to 5*10E+3 := 0; begin s_clk <= clk ; s_OPERATION <= OPERATION ; s_RESET <= RESET ; s_Period_Info <= Period_Info ; i_Period <= 1 when s_period_info = "0001" else 5 when s_period_info = "0010" else 10 when s_period_info = "0011" else 30 when s_period_info = "0100" else 60 when s_period_info = "0101" else 300 when s_period_info = "0110" else 600 when s_period_info = "0111" else 1800 when s_period_info = "1000" else 3600 when s_period_info = "1001" else 1 ; process(s_clk, s_OPERATION, s_RESET, i_Period ) variable v_timer : integer range 0 to 5*100E+6 := 0; variable v_timer_seconds : integer range 0 to 5*10E+3 := 0; begin if ( rising_edge( s_clk ) ) then if (s_OPERATION = '1') then if ( s_RESET = '1' ) then v_timer := 0 ; else if ( v_timer = 5 ) then v_timer := 0; if ( v_timer_seconds = i_Period) then v_timer_seconds := 0 ; s_SW_Period_Over_Flag <= '1'; else v_timer_seconds := v_timer_seconds + 1 ; s_SW_Period_Over_Flag <= '0'; end if; else s_SW_Period_Over_Flag <= '0'; v_timer := v_timer + 1 ; end if ; end if ; else v_timer := 0 ; end if ; end if ; end process ; SW_Period_Over_Flag <= s_SW_Period_Over_Flag ; Period <= i_Period ; end Behavioral;