-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtimer.vhd
71 lines (54 loc) · 1.31 KB
/
timer.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
library IEEE;
use IEEE.std_logic_1164.ALL;
use IEEE.std_logic_arith.ALL;
use IEEE.std_logic_unsigned.ALL;
use work.types.all;
entity timer is
port (
clk : in std_logic;
rst : in std_logic;
timer_in : in timer_in_type;
timer_out : out timer_out_type);
end entity;
architecture Behavioral of timer is
-- 0.01 ms * 66.66 MHz = 0xA2BE8
-- 0.01 ms * 77.77 MHz = 0xBDDE4
-- 0.01 ms * 88.88 MHz = 0xD8FE0
-- 0.01 ms * 93.33 MHz = 0xE3DB4
-- 0.01 ms * 96.29 MHz = 0xEB154
constant tick : std_logic_vector(19 downto 0) := x"EB154";
type reg_type is record
count : std_logic_vector(19 downto 0);
int_go : std_logic;
end record;
constant rzero : reg_type := (
count => (others => '0'),
int_go => '0'
);
signal r, rin : reg_type := rzero;
begin
comb : process(r, timer_in) is
variable v : reg_type;
begin
v := r;
if timer_in.eoi = '1' then
v.int_go := '0';
end if;
if r.count >= tick then
v.count := (others => '0');
v.int_go := '1';
else
v.count := r.count + 1;
end if;
rin <= v;
timer_out.int_go <= r.int_go;
end process;
regs : process(clk, rst) is
begin
if rst = '1' then
r <= rzero;
elsif rising_edge(clk) then
r <= rin;
end if;
end process;
end architecture;