There are two main clocks in my project, one is 250MHz, antoher is 100Mhz. A counter counting according 250MHz clock. I want to register the counter's value at some conditions, and send this value into 100MHz clock domain. The code is as bleow:
Is this across clock domains safely or not?!
PS:
1. The SQOK is generated from HITOK, HITOK is a pulse whose width is about 100ns. SQOK is generated as attached BDF design.
2. The attached another image shows HITOK, SQOK and two clocks timing relationship.
Code:
process(ck4x,reset)
begin
if reset='0' then
CT_cnt <= (others => '0');CT_cnt_q <= (others => '0');CT_Latch <= (others => '0');
elsif ck4x'event and ck4x='1' then
CT_cnt_q <= CT_cnt;CT_cnt_2q <= CT_cnt_q;hitok_q <= hitok;hitok_2q <= hitok_q;
if LaunchCT='1' then
CT_cnt <= CT_cnt + 1;--------The counter counting in 250MHz clock domain
else CT_cnt <= (others => '0');
end if;
if hitok_q/=hitok_2q and hitok_q='1' then--Register CT_cnt value at the rising edge of hitok_q.
CT_Latch <= CT_cnt_2q;
end if;
end if;
end process;
process(sysclk,reset)--Send the registered counter value to 100MHz domain.
begin
if reset='0' then
CoarseTime <= (others => '0');
elsif sysclk'event and sysclk='1' then
if SQOK='1' then
CoarseTime <= CT_Latch;
else
end if;
end if;
end process;
PS:
1. The SQOK is generated from HITOK, HITOK is a pulse whose width is about 100ns. SQOK is generated as attached BDF design.
2. The attached another image shows HITOK, SQOK and two clocks timing relationship.