M
moogyd
Hi experts,
Sorry for the cross posting, but I wanted to ensure a complete
readership. It's more a design question than language specific.
When I pass a signal between clock domains (clkfrom to clkto), I use
two FF's in the clkto domain prior to using the signal in this domain.
If there is a timing violation (setup or hold) at the first FF, then
the O/P will become metastable. i.e. Unknown, and it will stay in this
state for a time determind by a probability distribution.
We therefore use a second FF before we use the signal. Hopefully, the
O/P of the fist FF will be stable by the next clock edge. This is not
guarenteed, and depends on the clock frequency, target technology etc.
All we can say is that there is a probabilty of X% that it will always
work.
Therefore, first question : Is my understanding correct?
If so, I have another question.
If I am passing a signal from a fast clock domain (16MHz) to a slow
clock domain (100Hz) at 0.18us, do I need to synchronize?
e.g. As a simple example, I have a timer on a system bus. The cycle
time register is in the fast domain.
Ignoring reset's, (and assuming I gray code the counter) my code looks
like
p_fast : process(fastclk)
if fastclk'event and fastclk='1' then
if write_cycle='1' then
r_cycle <= wr_data ;
end if;
end if ;
end process ;
p_slow : process(slowclk)
if slowclk'event and slowclk='1' then
r_cycle_eq_count <=cycle_eq_count ; // This is an interrupt which
will be sync'ed into fast clock domain
if r_cycle_eq_count='1' then
r_count <= (others => '0') ;
else
r_count <= r_count + 1 ;
endif ;
end if ;
end process ;
assign cycle_eq_count = '1' when r_cycle=r_count else '0' ;
Is there a problem with this code?
If r_cycle changes around slowclk, there may be metastabity in
r_cycle_count, but this should have settled within a 100Hz cycle?
Any further suggestions/insights welcomed.
Steven
Sorry for the cross posting, but I wanted to ensure a complete
readership. It's more a design question than language specific.
When I pass a signal between clock domains (clkfrom to clkto), I use
two FF's in the clkto domain prior to using the signal in this domain.
If there is a timing violation (setup or hold) at the first FF, then
the O/P will become metastable. i.e. Unknown, and it will stay in this
state for a time determind by a probability distribution.
We therefore use a second FF before we use the signal. Hopefully, the
O/P of the fist FF will be stable by the next clock edge. This is not
guarenteed, and depends on the clock frequency, target technology etc.
All we can say is that there is a probabilty of X% that it will always
work.
Therefore, first question : Is my understanding correct?
If so, I have another question.
If I am passing a signal from a fast clock domain (16MHz) to a slow
clock domain (100Hz) at 0.18us, do I need to synchronize?
e.g. As a simple example, I have a timer on a system bus. The cycle
time register is in the fast domain.
Ignoring reset's, (and assuming I gray code the counter) my code looks
like
p_fast : process(fastclk)
if fastclk'event and fastclk='1' then
if write_cycle='1' then
r_cycle <= wr_data ;
end if;
end if ;
end process ;
p_slow : process(slowclk)
if slowclk'event and slowclk='1' then
r_cycle_eq_count <=cycle_eq_count ; // This is an interrupt which
will be sync'ed into fast clock domain
if r_cycle_eq_count='1' then
r_count <= (others => '0') ;
else
r_count <= r_count + 1 ;
endif ;
end if ;
end process ;
assign cycle_eq_count = '1' when r_cycle=r_count else '0' ;
Is there a problem with this code?
If r_cycle changes around slowclk, there may be metastabity in
r_cycle_count, but this should have settled within a 100Hz cycle?
Any further suggestions/insights welcomed.
Steven