blob: c1851de19c33b56366b912f0b4fc6329e92115f0 (
plain)
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
|
library IEEE;
context IEEE.IEEE_std_context;
entity TriangularCounter is
generic (
g_Precision : natural := 11
);
port (
CLK : in std_logic;
RST : in std_logic;
EN : in std_logic;
REF : out unsigned(g_Precision-1 downto 0);
TRIGGER : out std_logic
);
end entity;
architecture arch of TriangularCounter is
signal dir : std_logic;
signal cnt : unsigned(REF'range);
signal tg_max : std_logic;
signal tg_min : std_logic;
begin
process(RST, CLK)
begin
if RST then
cnt <= (others=>'0');
dir <= '0';
elsif rising_edge(CLK) then
if EN then
cnt <= cnt-1 when dir else cnt+1;
if tg_min or tg_max then
dir <= not dir;
end if;
end if;
end if;
end process;
tg_max <= (not dir) and (cnt ?= to_unsigned(2**g_Precision-2, REF));
tg_min <= dir and (cnt ?= 1);
REF <= cnt;
TRIGGER <= tg_min;
end architecture;
|