forked from open-logic/open-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vivado_tutorial.vhd
95 lines (83 loc) · 2.68 KB
/
vivado_tutorial.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
library olo; -- Open Logic Library
entity vivado_tutorial is
port(
-- Control Signals
Clk : in std_logic;
-- Interfaces
Buttons : in std_logic_vector(1 downto 0);
Switches : in std_logic_vector(3 downto 0);
Led : out std_logic_vector(3 downto 0)
);
end entity;
architecture rtl of vivado_tutorial is
signal Buttons_Sync : std_logic_vector(1 downto 0);
signal Switches_Sync : std_logic_vector(3 downto 0);
signal RisingEdges : std_logic_vector(1 downto 0);
signal Buttons_Last : std_logic_vector(1 downto 0);
signal Rst : std_logic := '1';
begin
-- Assert reset after power up
i_reset: entity olo.olo_base_reset_gen
port map (
Clk => Clk,
RstOut => Rst
);
-- Debounce Buttons
i_buttons : entity olo.olo_intf_debounce
generic map (
ClkFrequency_g => 125.0e6,
DebounceTime_g => 25.0e-3,
Width_g => 2
)
port map (
Clk => Clk,
Rst => Rst,
DataAsync => Buttons,
DataOut => Buttons_Sync
);
-- Debounce Switches
i_switches : entity olo.olo_intf_debounce
generic map (
ClkFrequency_g => 125.0e6,
DebounceTime_g => 25.0e-3,
Width_g => 4
)
port map (
Clk => Clk,
Rst => Rst,
DataAsync => Switches,
DataOut => Switches_Sync
);
-- Edge Detection
p_edge_detection : process(Clk)
begin
if rising_edge(Clk) then
-- Normal Operation
RisingEdges <= Buttons_Sync and (not Buttons_Last);
Buttons_Last <= Buttons_Sync;
-- Reset
if Rst = '1' then
RisingEdges <= (others => '0');
Buttons_Last <= (others => '0');
end if;
end if;
end process;
-- FIFO
i_fifo : entity olo.olo_base_fifo_sync
generic map (
Width_g => 4,
Depth_g => 4096
)
port map (
Clk => Clk,
Rst => Rst,
In_Data => Switches_Sync,
In_Valid => RisingEdges(0),
Out_Data => Led,
Out_Ready => RisingEdges(1)
);
end;