42 lines
1.2 KiB
VHDL
42 lines
1.2 KiB
VHDL
-- -------------------------------------------------------------------------- --
|
|
-- edgeDetector.vhd: Basic edge detector
|
|
--
|
|
-- Copyright (C) 2017 Markus Koch <markus@notsyncing.net>
|
|
--
|
|
-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
-- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
-- -------------------------------------------------------------------------- --
|
|
|
|
library ieee;
|
|
use ieee.std_logic_1164.all;
|
|
use ieee.numeric_std.all;
|
|
|
|
entity edgeDetector is
|
|
port(
|
|
clk : in std_logic;
|
|
rst : in std_logic;
|
|
sig : in std_logic;
|
|
risingEdge : out std_logic;
|
|
fallingEdge : out std_logic;
|
|
anyEdge : out std_logic
|
|
);
|
|
end entity edgeDetector;
|
|
|
|
architecture RTL of edgeDetector is
|
|
signal temp : std_logic_vector(1 downto 0);
|
|
begin
|
|
shiftomat : process(rst, clk) is
|
|
begin
|
|
if rst = '1' then
|
|
temp <= "00";
|
|
elsif rising_edge(clk) then
|
|
temp <= temp(0) & sig;
|
|
end if;
|
|
end process shiftomat;
|
|
|
|
risingEdge <= '1' when (temp = "01") else '0';
|
|
fallingEdge <= '1' when (temp = "10") else '0';
|
|
anyEdge <= '1' when (temp = "01" or temp = "10") else '0';
|
|
end architecture RTL;
|