-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_2.vhd
37 lines (36 loc) · 911 Bytes
/
timer_2.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- Listing 13.9
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity timer_2 is
port(
clk, reset: in std_logic;
timer_start, timer_tick: in std_logic;
timer_up: out std_logic
);
end timer_2;
architecture arch of timer_2 is
signal timer_reg, timer_next: unsigned(4 downto 0);
begin
-- registers
process (clk, reset)
begin
if reset='1' then
timer_reg <= (others=>'1');
elsif (clk'event and clk='1') then
timer_reg <= timer_next;
end if;
end process;
-- next-state logic
process(timer_start,timer_reg,timer_tick)
begin
if (timer_start='1') then
timer_next <= (others=>'1');
elsif timer_tick='1' and timer_reg/=0 then
timer_next <= timer_reg - 1;
else
timer_next <= timer_reg;
end if;
end process;
timer_up <='1' when timer_reg=0 else '0';
end arch;