I also attach the VHDL code.
This is an edge detector on the falling edge with integrated flops for the CDC:
library ieee;
use ieee.std_logic_1164.all;
entity EdgeDetector is
port (
clk :in std_logic;
d :in std_logic;
edge :out std_logic
);
end EdgeDetector;
architecture EdgeDetector_rtl of EdgeDetector is
signal meta1 :std_logic:='0';
signal meta2 :std_logic:='0';
signal reg1 :std_logic:='0';
signal reg2 :std_logic:='0';
attribute altera_attribute : string;
attribute altera_attribute of meta1:signal is "-name PRESERVE_REGISTER ON; -name SYNCHRONIZER_IDENTIFICATION FORCED_IF_ASYNCHRONOUS";
attribute altera_attribute of meta2:signal is "-name PRESERVE_REGISTER ON; -name SYNCHRONIZER_IDENTIFICATION FORCED_IF_ASYNCHRONOUS";
attribute altera_attribute of reg1:signal is "-name PRESERVE_REGISTER ON; -name SYNCHRONIZER_IDENTIFICATION FORCED_IF_ASYNCHRONOUS";
attribute altera_attribute of reg2:signal is "-name PRESERVE_REGISTER ON";
begin
reg: process(clk)
begin
if rising_edge(clk) then
meta1 <= d;
meta2 <= meta1;
reg1 <= meta2;
reg2 <= reg1;
edge <= (not reg1) and (reg2);
end if;
end process;
end EdgeDetector_rtl;