Hi! I have a doubt regarding clock domain crossing from a fast clock to
a slower one. Is it possible to use the two flip flops scheme? If yes,
would my code be okay?
sinc_in indicates if data in is valid, sinc_out if data out is valid in
the secod clock domain and clk1 is faster than clk2, so clk2 is the new
domain.
1 | entity clock_sync is
|
2 |
|
3 | port(
|
4 | clk1 : in std_logic;
|
5 | clk2 : in std_logic;
|
6 | sync_in : in std_logic;
|
7 | Data_in : in std_logic_vector(7 downto 0);
|
8 | data_out : out std_logic_vector(7 downto 0);
|
9 | sync_out : out std_logic
|
10 | );
|
11 | architecture behavioral of clock_sync is
|
12 |
|
13 | constant in: std_logic_vector (7 downto0):=(others=>0);
|
14 |
|
15 | type ff is array(0 to 1) of std_logic_vector(7 downto 0);
|
16 |
|
17 | signal sig_reg : ff:=(others=>in);
|
18 | signal i: integer:=0;
|
19 |
|
20 | begin
|
21 | process(Clock2)
|
22 | begin
|
23 | if rising_edge(Clock2) and sync_in=1 then
|
24 | if i < 2 then
|
25 | i<=i+1;
|
26 | sig_reg(i)<= Data_in;
|
27 | sync_out<=0;
|
28 | else data_out<=sig_reg(i-1);
|
29 | sync_out<=1;
|
30 | end if;
|
31 | end if;
|
32 | end process;
|
33 | end behavioral;
|
Thank you!!