You are on page 1of 7

Clocks

Understanding clock domain


crossing issues
By Saurabh Verma tions, the signal names shown
Engineering Manager in Figure 1 are directly used. For
Atrenta example, C1 and C2 imply the
Ashima S. Dabare source and destination clocks re-
Consulting Applications Engineer spectively. Similarly A and B are
Atrenta used as source and destination
flop outputs respectively. Also,
Introduction the source and destination flops
SoCs are becoming more com- are assumed to be positive edge
plex these days. A lot of func- triggered. 1. Clock domain crossing
tionality is being added to chips Clock Domain Crossing Issues
and data is frequently transferred This section describes three main
from one clock domain to anoth- issues, which can possibly occur
er. Hence, clock domain crossing whenever there is a clock do-
verification has become one of main crossing. The solutions for
the major verification challenges those issues are also described.
in deep submicron designs.
A clock domain crossing A. Metastability
occurs whenever data is trans- Problem. If the transition on sig-
ferred from a flop driven by one nal A happens very close to the
clock to a flop driven by another active edge of clock C2, it could
clock. lead to setup or hold violation at
In Figure 1, signal A is the destination flop “FB”. As a re-
launched by the C1 clock do- sult, the output signal B may os-
main and needs to be captured cillate for an indefinite amount of
properly by the C2 clock domain. time. Thus the output is unstable 2. Metastability has consequences.
Depending on the relationship and may or may not settle down
between the two clocks, there to some stable value before the
could be different types of prob- next clock edge of C2 arrives. This
lems in transferring data from phenomenon is known as meta-
the source clock to the destina- stability and the flop “FB” is said to
tion clock. Along with that, the have entered a metastable state.
solutions to those problems can Metastability in turn can have
also be different. the following consequences
Traditional methods like from a design perspective:
simulation and static timing
analysis alone are not sufficient 1. If the unstable data is fed to
to verify that the data is trans- several other places in the 3. Multi-flop synchronization.
ferred consistently and reliably design, it may lead to a high
across clock domains. Hence, current flow and even chip For example, see Figure 2. in the destination domain. A
new verification methodologies burnout in the worst case. If the input signal A transitions commonly used synchronizer
are required, but before devising 2. Different fan-out cones may very close to the posedge of is a multi-flop synchronizer as
a new methodology it is impor- read different values of the clock C2, the output of the des- shown in Figure 3.
tant to understand the issues re- signal, and may cause the tination flop can be metastable. This structure is mainly used
lated to clock domain crossings design to enter into an un- As a result it can be unstable and for single and multi-bit control
properly. Different types of clock known functional state, lead- may finally settle to 1 or 0 as de- signals and single bit data sig-
domain crossings are discussed ing to functional issues in the picted by signals B1 and B2. nals in the design. Other types
here along with the possible is- design. Solution. Metastability prob- of synchronization schemes are
sues encountered in each one of 3. The destination domain out- lems can be avoided by adding required for multi-bit data sig-
them and their solutions. A new put may settle down to the special structures known as nals such as MUX recirculation,
verification methodology is then new value or may return to synchronizers in the destination handshake, and FIFO.
proposed which will ensure the old value. However, the domain. The synchronizers allow
that data is transferred correctly propagation delay could be sufficient time for the oscilla- B. Data Loss
across clock domains. high leading to timing is- tions to settle down and ensure Problem. Whenever a new source
In all the subsequent sec- sues. that a stable output is obtained data is generated, the destination

EE Times-India | December 2007 | eetindia.com 


domain may not capture it in the tion on source data, at least one
very first cycle of the destination destination clock edge should
clock because of metastability. arrive where there is no setup or
As long as each transition on the hold violation so that the source
source signal is captured in the data is captured properly in the
destination domain, data is not destination domain. There are
lost. In order to ensure this, the several techniques to ensure
source data should remain stable this.
for some minimum time, so that For example, a finite state
the setup and hold time require- machine (FSM) can be used to
ments are met with respect to at generate source data at a rate,
least one active edge of destina- such that it is stable for at least
tion clock. 1 complete cycle of the destina-
If the active clock edges of tion clock. This can be generally 4. Effect of metastability on data capture.
C1 and C2 arrive close together, useful for synchronous clocks
the first clock edge of C2, which when their frequencies are
comes after the transition on known. For asynchronous clock
source data A, is not able to domain crossings, techniques
capture it. The second edge of like handshake and FIFO are
clock C2 finally captures the data more suitable.
(Figure 4).
However, if there is sufficient C. Data Incoherency
time between the transition on Problem. As seen in the previous
data A and the active edge of section whenever new data is 5. No data is lost in this case.
clock C2, the data is captured in generated in the source clock do-
the destination domain in the main, it may take 1 or more des-
first cycle of C2. tination clock cycles to capture
Hence, there may not be a it, depending on the arrival time
cycle by cycle correspondence of active clock edges. Consider a
between the source and desti- case where multiple signals are
nation domain data. Whatever being transferred from one clock
the case, it is important that domain to another and each
each transition on the source signal is synchronized separately
data should get captured in the using a multi-flop synchronizer.
destination domain. If all the signals are changing
For example: Assume that simultaneously and the source 6. Data is lost in this case.
the source clock C1 is twice as and destination clock edges ar-
fast as the destination clock C2 rive close together, some of the 0->1 on both the bits of signal X. to another, only one bit change
and there is no phase differ- signals may get captured in the Here the rising edge of clock C2 is required, then either that bit
ence between the two clocks. destination domain in the first comes close to the transition on would change to a new value or
Further assume that the input clock cycle while some others signal X. While the transition on would retain the original value.
data sequence “A” generated on may be captured in the second X[0] is captured in the first clock Since all the other bits have the
the positive edge of clock C1 is clock cycle by virtue of metasta- cycle, the transition on X[1] gets same value in both the states, the
“00110011”. The data B captured bility. This may result in an invalid captured in second clock cycle complete bus will either change
on the positive edge of clock C2 combination of values on the sig- of C2. This results in an inter- to the new value or retain the
will be “0101”. Here, since all the nals at the destination side. Data mediate value of “10” on Y[0:1] original value in this case.
transitions on signal A are cap- coherency is said to have been which is an invalid state. Data This in turn implies that if the
tured by B, the data is not lost. lost in such a case. coherency is lost in this case. bus is Gray-encoded, the prob-
This is depicted in Figure 5. If these signals are together Solution. In the above exam- lem would get resolved and an
However, if the input se- controlling some function of the ple, the problem results because invalid state would never be
quence is “00101111”, then design, then this invalid state all the bits are not changing to obtained.
the output in the destination may lead to functional errors. a new state in the same cycle of However, this is applicable
domain will be “0011”. Here the For example: Assume that destination clock. If all the bits only for control busses as it
third data value in the input “00” and “11” are two valid values either retain their original value may not be possible to Gray-
sequence which is “1” is lost as for a signal X[0:1] generated by or change to the new value in encode the data busses. In
shown in Figure 6. clock C1. As shown in Figure 7, the same cycle, then the design such cases, other techniques
Solution. In order to prevent initially there is a transition from either remains in the original like handshake, FIFO and MUX
data loss, the data should be held 1->0 on both the bits of X. Clock state or goes to a correct new recirculation can be used to
constant in the source domain C2 captures both the transitions state. generate a common control
long enough to be properly cap- in the first cycle itself. Hence the Now, if the circuit is designed logic to transfer data correctly.
tured in the destination domain. signal Y[0:1] becomes “00”. in such a way that while chang- The MUX recirculation technique
In other words, after every transi- Next, there is a transition from ing the design from one state is shown in Figure 8.

 eetindia.com | December 2007 | EE Times-India


quency relationship between logic delay between the source
them, are known as synchronous and destination flops is such
clocks. These are essentially the that the setup and hold time of
clocks originating from the same the circuit can be met, the data
clock-root. A clock crossing be- will be transferred correctly. The
tween such clocks is known as a only requirement here is that
synchronous clock domain cross- the design should be STA (static
ing. It can be divided into several timing analysis) clean. In that
categories based on the phase case, there will be no problem
and frequency relationship of the of metastability, data loss or data
source and destination clocks as incoherency.
follows: Clocks with the same frequen-
cy and constant phase difference
• Clocks with the same These are the clocks having the
frequency and zero phase same time period but a constant
difference phase difference. A typical ex-
• Clocks with the same ample is the use of a clock and
7. Data coherency is lost in this case. frequency and constant its inverted clock. Another ex-
phase difference ample is a clock which is phase
• Clocks with different shifted from its parent clock, for
frequency and variable phase example by T/4 where T is the
difference time period of the clocks.
• Integer multiple clocks Clocks C1 and C2 have the
• Rational multiple clocks same frequency but are phase
shifted and C1 is leading C2 by
All the above sub categories 3T/4 time units (Figure 10).
may not be used in real designs Whenever data is transferred
but are being considered here from clock C1 to C2, there is
for completeness and better un- more restriction on the com-
derstanding of the subject. binational logic delay due to
While describing all the smaller setup/hold margins. If
above cases, it is assumed that the logic delay at the crossing
the source clock (C1) and the is such that the setup and hold
destination clock (C2) have the time requirements can be met,
same phase and frequency jitter data will be transferred properly
and are balanced with the same and there will be no metastabil-
8. MUX recirculation technique. specifications of clock latency ity. In all such cases, there is no
and skew. It is also assumed need for a synchronizer. The
that the clocks begin with a zero only requirement here is that the
phase difference between them design should be STA clean.
and the “clock to Q” delay of the Clocks with different frequen-
flops is 0. cy and variable phase difference
Clocks with the same frequen- These are clocks that have a dif-
cy and zero phase difference ferent frequency and a variable
This refers to two identical clocks, phase difference. There can be
as the clocks C1 and C2 have the two sub-categories here, one
same frequency and 0 phase dif- where the time period of one
ference. Note, that as the clocks clock is an integer multiple of
Figure 9. Clocks with the same frequency and phase. C1 and C2 are identical and gen- the other and a second where
erated from the same root clock, the time period of one clock is
Here, a control signal EN, ency. However, it is important the data transfer from C1 to C2 a non-integer (rational) multiple
generated in the source domain to ensure that when the control is essentially not a clock domain of the other. In both cases, the
is synchronized in the destina- signal is active, the source do- crossing. For all practical pur- phase difference between the
tion domain using a multi-flop main data A[0:1] should be held poses, this is the case of a single active edges of clocks is variable.
synchronizer. The synchronized constant. clock design and is considered These two cases are described in
control signal EN_Sync drives the here for completeness. detail below.
select pin of the muxes, thereby Synchronous Clock Whenever data is transferred
controlling the data transfer for Domain Crossings from clock C1 to C2, one com- A. Integer multiple clocks
all bits of the bus A. In this way, This section describes various plete clock cycle of C1 (or C2) In this case, the frequency of one
individual bits of the bus are not types of synchronous clock do- is available for data capture as clock is an integer multiple of the
synchronized separately, and main crossings. Clocks, which shown in Figure 9. other and the phase difference
hence there is no data incoher- have a known phase and fre- As long as the combinational between their active edges is vari-

EE Times-India | December 2007 | eetindia.com 


able. Here the minimum possible the two clocks can be very
phase difference between the small- small enough to cause
active edges of 2 clocks would al- metastability. Whether or not a
ways be equal to the time period metastability problem will oc-
of the fast clock. cur depends on the value of the
In Figure 11 clock C1 is 3 times rational multiple, and the design
faster than clock C2. Assuming T technology. Three different
is the time period of clock C1, cases are being considered here
the time available for data cap- with the help of examples.
ture by clock C2 could be T, 2T In the first case, there is a suf-
or 3T depending on which edge ficient phase difference between Figure 9. Same frequency, phase shifted clocks.
of clock C1 the data is launched. the active edges of the source
Hence, the worst case delay of and destination clocks such that
any path should meet the setup there will be no metastability.
time with respect to the edge In the second case, the active
with a phase difference of T. The clock edges of the two clocks
worst case hold check would be can come very close together,
made with respect to the edge close enough to cause metasta-
with 0 phase difference. bility problem. However, in this
In all such cases, one com- case the frequency multiple is
plete cycle of the faster clock is such that, once the clock edges
always available for data capture, come close together, there
hence it should always be pos 8. would be sufficient margin in
Clocks with the same frequency the next cycle to capture data Figure 11. Integer multiple clocks.
and phase. 8. Clocks with properly without any setup or
the same frequency and phase. hold violation.
sible to meet the setup and hold In the third case, the clock
requirements. As a result there edges of the two clocks can be
will be no metastability or data close enough for many consecu-
incoherency and a synchronizer tive cycles. This is similar to the
is not needed. behaviour of asynchronous
However, there can still be clocks except that here the
a problem of data loss in the clock-root for both the clocks is
case of fast to slow clock cross- the same and hence the phase Figure 11. Clock edges never come very close together.
ing. (That is, the source clock difference between the clocks
is faster than the destination can be calculated. clock C2. As shown in Figure edge of the destination clock ar-
clock.) In order to prevent this, Note that in all the examples 12, the time period of clock C1 rives between two consecutive
the source data should be held given below, some delay values is 15ns and of C2 is 10ns. The transitions on the source data.
constant for at least one cycle are used and it is assumed that least possible phase difference
of the destination clock. Using a phase margin of less than or between the two clock edges is Example 2
some control circuit can ensure equal to 1.5ns between the clock 2.5ns, which should be sufficient In this case, the active clock edges
this, for example, a simple finite edges can cause metastability. to meet setup and hold time of both the clocks can come very
state machine (FSM) would This is just a placeholder value requirements. close together intermittently.
work in this case. In the example and in real designs, it would be a However, additional com- In other words, the clock edges
shown in Figure 11, if the source function of many things includ- binational logic should not be come close together once and
data is generated once in every ing technology used, flop char- added at the crossing due to the then there would be sufficient
3 cycles of the source clock, acteristics, etc. very small setup/hold margins. margin between the edges for
there would be no data loss. If there is any logic, its delay the next few cycles (to capture
For the case of slow to fast cross- Example 1 should meet the setup and hold data properly) before they come
ings, there will anyways be no This is the case when the active time requirements. If this condi- close again. Here the word “close”
data loss. clock edges of both the clocks will tion can be met, there will be no implies close enough to cause
never come very close together, metastability and no synchro- metastability.
B. Rational multiple clocks and in all cases there would be nizer would be required. In Figure 13, clocks C1 and
In this case, the frequency of one a sufficient margin to meet the Further, if the crossing is a C2 have time periods 10ns and
clock is a rational or non-integer setup and hold requirements of slow to fast crossing, there will 7ns respectively. Notice, that
multiple of the other clock and the circuit. be no data loss. However, in case the minimum phase difference
the phase difference between Consider a clock C from which of a fast to slow clock crossing, between the two clocks is 0.5ns,
the active clock edges is variable. 2 clocks C1 and C2 are derived there can be data loss. In order which is very small. So, there are
Unlike the situation where with a frequency of divide-by-3 to prevent this, the source data chances of metastability and a
one clock is an integer multiple and divide-by-2 respectively needs to be held constant for at synchronizer would be required.
of the other, here the minimum with respect to clock C. Here least one cycle of the destination Due to metastability, the data
phase difference between clock C1 is 1.5 times slower than clock so that at least one active may not be captured in the des-

 eetindia.com | December 2007 | EE Times-India


tination domain when the clock the value ‘1’ is not captured due
edges are very close together. to setup violation and in the
However, in this case, note that second cycle the new value ‘0’ is
once the clock edges come very incorrectly captured due to hold
close together, in the next cycle violation.
there is a sufficient margin so In order to prevent data
that the destination clock can loss, the data needs to be held
capture the data properly. This constant for a minimum of two
is shown by signal B2 in Figure cycles of the destination clock.
13. While the expected output This is applicable for both fast to
would be B1, the actual wave- slow as well as slow to fast clock
form could look like B2, but still domain crossings. It can be done
there is no data loss in this case. by controlling the source data
However there can be an issue generation using a simple FSM.
of data incoherency as described However, the data incoherency
previously. issue can still be there.
For a fast to slow crossing, In such cases, standard tech- Figure 12. Clock edges come close together intermittently.
data loss can occur, and in or- niques like handshake and FIFO
der to prevent this, the source are more useful to control data
data should be held constant transfer as they will also take care
for a minimum of one destina- of the data incoherency issue.
tion clock cycle. Again, this can
be done by the use of a simple Asynchronous Clock
FSM. Domain Crossings
Clocks that do not have a known
Example 3 phase or frequency relationship
This is the case when the phase between them are known as
difference between the clocks asynchronous clocks. Whenever
can be very small at times and there is a clock crossing between
can remain like that for several two asynchronous clocks, their
cycles. This is very similar to asyn- active edges can arrive very close
chronous clocks except that the together leading to metastability.
variable phase differences will be Here the phase difference be- Figure 14. Clock edges are close for consecutive cycles.
known and will repeat periodi- tween the clocks can be variable
cally. and unlike synchronous clocks it be divided into two categories, techniques can be used to
In Figure 14, clocks C1 and C2 is unpredictable. namely structural and function- perform functional validation.
have time periods 10ns and 9ns Proper synchronization needs al. Structural validation ensures Assertions can be inferred au-
respectively. It can be seen that to be done in the destination that appropriate synchroniza- tomatically in the design using
the active clock edges of both domain to prevent metastabil- tion logic has been added wher- some EDA tools, or they can be
the clocks come very close to- ity. Apart from that, there can ever it is required and functional inserted in the RTL using any of
gether for 4 consecutive cycles. be problems of data loss and validation ensures that the logic the standard assertion languag-
In the first two cycles there is a data incoherency (in both fast to that has been added is actually es like OVL, PSL and SVA. Many
possibility of a setup violation slow as well as slow to fast clock performing the intended func- EDA vendors support these lan-
(as the source clock is leading crossings). If the source and des- tion. guages.
the destination clock) and in the tination clock frequencies are A number of CDC problems These assertions can either
next two cycles there is a pos- known, holding the source data can be detected just by per- be simulated in the functional
sibility of hold violation (as the constant for two cycles of the forming structural validation. simulation environment or can
destination clock is leading the destination clock can prevent These checks are simpler and be verified using formal verifi-
source clock). data loss. However, if the circuit much faster than the functional cation techniques. Both these
In this case, there will be an is to be designed to be indepen- validation. Moreover, if there techniques have their own ad-
issue of metastability and hence dent of clock frequencies, hand- are structural issues, most of the vantages and disadvantages.
synchronization needs to be shake or FIFO techniques should functional validation would have The simulation results are
done. Apart from metastability be used to prevent metastability, no relevance anyway. Hence, dependent on the quality of test
there can be an issue of data loss data loss and data incoherency. verification should begin with vectors used. A problem may go
also, even though it is a slow to the structural checks and the undetected if the vectors ap-
fast clock domain crossing. As Verification Methodology problems detected there should plied cannot stimulate it, and it
can be seen from Figure 14, B1 This section describes a meth- be corrected before moving on is very difficult to determine the
is the expected output if there odology that will ensure that the to functional validation. right set of test vectors that will
would have been no metastabil- circuit has been designed prop- Rule-based checking is give good coverage.
ity. However, the actual output erly to handle the clock domain a very efficient way to per- As compared to simulation,
can be B2. Here the data value ‘1’ crossing issues. form structural validation. formal techniques give a much
is lost, because in the first cycle The validation activity can Assertion-based verification better coverage and there is

EE Times-India | December 2007 | eetindia.com 


no need to provide any test
vectors. However, formal tech-
niques have some performance
issues because of state space
explosion, which is a well known
problem in formal analysis (see
reference 4). So, these checks are
not suitable for full chip analysis
but they work reasonably well at
the block level.
A step-by-step approach for
verifying clock domain crossings
is described here.

Step 1
Check for the presence
of valid synchronizers in:
All asynchronous clock
domain crossings, and,
those cases of synchronous clock
domain crossings where there
can be metastability as described Figure 15. Formal verification helps catch gray-encoding failure.
in the section on rational multiple
clocks. incoherency. Figure 15 shows a Asserting that each source that there is no FIFO overflow
A multi-flop synchronizer is control bus clock domain cross- data launch is always captured or underflow.
sufficient to ensure that there will ing, which is synchronized using in the destination domain can • Mux recirculation: With refer-
be no metastability. However, a multi-flop synchronizer but is validate these. ence to Figure 8, check that
there can still be a problem of not Gray-encoded. A waveform In the case of fast to slow syn- while the synchronized con-
data incoherency. So, it is advis- trace is generated for the asser- chronous clock domain cross- trol signal EN_Sync is active,
able to check at this stage only, tion failure. ings, where a synchronizer is not the following two conditions
that multi-flop synchronizers are In case the converging sig- required and for the simple cases hold:
used only for scalar signals. They nals cannot be Gray-encoded, of multi-flop synchronization, o Source data A[0:1] is stable,
can also be used for control bus- change the synchronization check that after every transition and,
ses. They should not be used for scheme to one which uses a on the source data an active o at least one active edge of
data busses however. common control signal, for ex- edge of the destination clock ar- destination clock arrives
A rule-based checker can be ample, MUX recirculation, FIFO rives where there is no setup or
used to automatically detect all or handshake. These schemes hold violation. The methodology described
clock domain crossings and to still need to be validated for For other synchronization in the above four steps is also
check for the presence of valid proper functionality as described schemes, some standard func- depicted in Figure 16.
synchronizers at all places where in Step 4. tional checks can be done to
they are required. ensure that there is no data loss, Summary
If there are missing synchro- Step 3 which are described in Step 4. Traditional verification methods
nizers, the designer should mod- Once the proper synchroniza- like simulation and static tim-
ify the design to add appropriate tion logic is in place and the Step 4 ing analysis are not sufficient
synchronization logic. Gray-encoding checks have been In all cases, where some special to detect all types of problems,
done, the next step is to verify synchronization schemes are which can occur in clock domain
Step 2 that there is no data loss while used, it is necessary to verify that crossings. The problems that can
Check for the presence of sepa- transferring data from one clock they are performing the intended occur depend on the types of
rately synchronized signals that domain to the other. This needs function correctly. This is impor- clock domain crossings. Similarly,
are converging. These are prob- to be checked for the following tant to ensure that there will be the solutions to those problems
able candidates for data incoher- two cases: no metastability, data incoher- are also different and hence the
ency. Doing structural analysis ency or data loss problem. verification techniques required
of the design can identify these • Synchronous clock domain The required checks are given are different as well. Some of the
candidates. crossings here for three commonly used basic problems of clock domain
The candidate signals for data • All fast to slow crossings schemes: crossings have been discussed
incoherence should be verified to • Slow to fast crossings where here. The solutions to those issues
be Gray-encoded. This validation the clock edges can be close • Handshake synchronization: are also discussed and a verifica-
can be done through assertions. together for continuous Check that the request-data tion methodology is proposed
A structural checking tool could cycles and request-acknowledge which will ensure that data is
even generate the assertion • All asynchronous clock do- protocols are working as per correctly transferred across clock
itself whenever it sees signals, main crossings the specifications. domains.
which are candidates for data • FIFO synchronization: Check

 eetindia.com | December 2007 | EE Times-India


References
[1] Sanjay Churiwala, “Tackling
multiple clocks in SoCs”, EE
Times March 15, 2004.
[2] Shaker Sarwary, “Solving the
toughest problems in CDC
analysis”, EE Times August 28,
2006.
[3] http://www.asic-world.com/
tidbits/metastablity.htm
[4]K. McMillan, Symbolic Model
Checking, Kluwer Academic
Publishers, Boston, 1993.

16. The flow of the verification methodology.

EE Times-India | December 2007 | eetindia.com 

You might also like