diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main-stopwatch.vhd | 26 | ||||
| -rw-r--r-- | src/stopwatch.vhd | 41 |
2 files changed, 54 insertions, 13 deletions
diff --git a/src/main-stopwatch.vhd b/src/main-stopwatch.vhd index f8d0ac0..ac5ff2d 100644 --- a/src/main-stopwatch.vhd +++ b/src/main-stopwatch.vhd @@ -53,19 +53,19 @@ begin end if; end process; - controller: component FSM_controller - port map( - clk => clk, - sysReset => sysReset, - buttons => buttons, - watchRunning => watchRunning, - watchReset => watchReset); + -- controller: component FSM_controller + -- port map( + -- clk => clk, + -- sysReset => sysReset, + -- buttons => buttons, + -- watchRunning => watchRunning, + -- watchReset => watchReset); stopwatch: component Watch port map( clk => clk, sysReset => sysReset, - watchRunning => watchRunning, - watchReset => watchReset, + watchRunning => buttons(0), + watchReset => buttons(1), mins => mins, secs => secs); bcd0: component bin2bcd @@ -91,10 +91,10 @@ begin disp: component bcd2disp port map( CLK => CLK_T(16), - N0 => N0, - N1 => N1, - N2 => N2, - N3 => N3, + N0 => N3, + N1 => N2, + N2 => N1, + N3 => N0, DD => DD, DS => DS); end Behavioral; diff --git a/src/stopwatch.vhd b/src/stopwatch.vhd index cfbd7ff..01300fc 100644 --- a/src/stopwatch.vhd +++ b/src/stopwatch.vhd @@ -1,5 +1,7 @@ library ieee; use ieee.std_logic_1164.all; +use ieee.std_logic_arith.all; +use ieee.std_logic_unsigned.all; entity Watch is port( @@ -9,4 +11,43 @@ end Watch; architecture Behavioral of Watch is begin + process(clk, sysReset) + variable subsec: std_logic_vector(26 downto 0) := (others => '0'); -- floor(log2(100_000_000)) + -- = 26 (bits needed to count to 1 second for 100Mhz clock) + variable minute, second: std_logic_vector(5 downto 0) := (others => '0'); + begin + if sysReset = '1' then + subsec := (others => '0'); + second := (others => '0'); + minute := (others => '0'); + elsif rising_edge(clk) then + if watchRunning = '1' then + subsec := (subsec + 1); + + -- if subsec is 100_000_000 (second complete) + if subsec = "101111101011110000100000000" then + subsec := (others => '0'); + second := (second + 1); + + -- if second is 60 (minute complete) + if second = "111100" then + second := (others => '0'); + minute := (minute + 1); + + -- if minute is 60 (hour complete) + if minute = "111100" then + minute := (others => '0'); + end if; + end if; + end if; + elsif watchReset = '1' then + subsec := (others => '0'); + second := (others => '0'); + minute := (others => '0'); + end if; + end if; + + mins <= minute; + secs <= second; + end process; end Behavioral; |