Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/edge_detector.vhd

raw
1 -- Copyright (c) 2017 Nuand LLC
2 --
3 -- This program is free software: you can redistribute it and/or modify
4 -- it under the terms of the GNU Affero General Public License as
5 -- published by the Free Software Foundation, either version 3 of the
6 -- License, or (at your option) any later version.
7 --
8 -- This program is distributed in the hope that it will be useful,
9 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 -- GNU Affero General Public License for more details.
12 --
13 -- You should have received a copy of the GNU Affero General Public License
14 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 library ieee;
17 use ieee.std_logic_1164.all;
18 use ieee.numeric_std.all;
19
20 entity edge_detector is
21 generic (
22 EDGE_RISE : std_logic ;
23 EDGE_FALL : std_logic ;
24 NUM_PULSES : positive range 1 to 1023 := 2
25 ) ;
26 port (
27 clock : in std_logic ;
28 reset : in std_logic ;
29 sync_in : in std_logic ;
30 pulse_out : out std_logic
31 ) ;
32 end entity ;
33
34 architecture arch of edge_detector is
35 signal pulses : std_logic_vector( NUM_PULSES - 1 downto 0 ) ;
36 begin
37
38 process( clock, reset )
39 begin
40 if( reset = '1' ) then
41 pulses <= ( others => '0' ) ;
42 pulse_out <= '0' ;
43 elsif( rising_edge( clock ) ) then
44 pulses <= sync_in & pulses( NUM_PULSES - 1 downto 1 ) ;
45
46 if( EDGE_RISE = '1' and pulses(1 downto 0) = "10" ) then
47 pulse_out <= '1' ;
48 elsif ( EDGE_FALL = '1' and pulses(1 downto 0) = "01" ) then
49 pulse_out <= '1' ;
50 else
51 pulse_out <= '0' ;
52 end if ;
53 end if ;
54 end process ;
55
56 end architecture ;