Planning Clock Domains
The timer raises its alarm and the processor never hears it. Both blocks work. The fault lies between them, where one clock hands a signal to another.
You Will Be Able To
- Sort the flip-flops of a chip into clock domains, and say which pairs of clocks are related.
- Explain what a two-flop synchronizer carries across, and three things it can lose.
- Choose a crossing for a level, an event, a word and a stream.
- Lesson
- S5.3
- Time
- 26 min
- Runs on
- Your browser
- Check
- 6 questions
The timer engineer shows you a clean pulse on the alarm wire. The processor engineer shows you three quiet samples of the same wire. Neither trace is wrong. How can both be true?
Before You Start
You need two earlier pages. Clock Sources and the Chip-Level Clock Tree gives an oscillator and the period of a clock. Dividers and Clock Gates gives a divided clock.
This page plans crossings. It does not build them. The circuits are in the track on RTL design. RTL is short for register transfer level, the usual way to write hardware. You need its first two pages on crossings: a flip-flop that cannot decide and two flip-flops in a row. The rest of that module is linked where it is used.
The alarm on this page is a service request of a peripheral. The Anatomy of a Peripheral says what that is.
| Question | |
|---|---|
| 1 | What is a clock domain? |
| 2 | When are two clocks related? |
| 3 | What can a two-flop synchronizer lose? |
| 4 | Why must the bits of a word not be synchronized one by one? |
| 5 | Which crossing fits a level, an event, a word and a stream? |
The Idea: Who Shares an Edge, and What Must Survive
A chip has more than one clock. The processor runs on a fast one. Slow peripherals run on a divided one. A real-time clock keeps the time of day on a small oscillator of its own, also while the rest sleeps.
All flip-flops that use one clock form a clock domain. Inside a domain life is simple. Every signal has one period to settle, and a tool can check that it does.
Between two domains it depends on the clocks. If one clock is made from the other, their edges keep a fixed distance, and signals between them can still be checked. If the clocks come from two oscillators, the edges drift past each other. A signal from the other side can then change at any moment, also right on the edge that samples it.
A flip-flop whose input changes on its edge can hover between 0 and 1 for a while. That is metastability. The standard cure is a synchronizer: two flip-flops in a row on the receiving clock. The first may hover. The second looks one period later, when the first has almost surely settled.
Here is the part that plans get wrong. A synchronizer makes a signal safe. It does not make it complete. It takes samples, and whatever happens between two samples is gone. So for every crossing you must say what has to survive. It may be a level, a single event, a whole word, or every word of a stream. That answer picks the circuit.
New Words
| Word | Meaning |
|---|---|
| Clock domain | All the flip-flops that use one clock. |
| Related clocks | Two clocks whose edges keep a fixed, known distance, because one source makes both. A clock and its divided clock are related. |
| Unrelated clocks | Two clocks from different oscillators. Their edges drift past each other. Often called asynchronous clocks. |
| Clock domain crossing (CDC) | A signal that leaves a flip-flop of one clock domain and enters a flip-flop of another. |
| Metastability | The state of a flip-flop that hovers between 0 and 1 because its input changed on its clock edge. |
| Two-flop synchronizer | Two flip-flops in a row on the receiving clock. The first takes the signal in. The second gives the first a period to settle. |
| Level signal | A signal that stays at its value until the receiver has acted on it. |
| Event signal | A short pulse that means "this happened once". |
| Real-time clock (RTC) | A block that keeps the time of day. It runs on a slow oscillator of its own. |
| Domain map | A drawing of the blocks of a chip, each marked with its clock. Every signal between two clocks is marked as a crossing. |
| Clock | Period | Made by | Related to the core clock? |
|---|---|---|---|
| Core clock | 10 ns | The clock root | It is the core clock. |
| Peripheral clock | 20 ns | A divider by two on the core clock | Yes: every edge follows a core edge. |
| RTC clock | 14 ns | The oscillator of the real-time clock block | No: another oscillator. |
Lab choices. A real RTC oscillator is far slower. The numbers are small so that a table can hold them.
One Picture: The Domain Map
- Power
- Clock / reset
- Processor
- Peripheral
- Name the clock of every box
Four blocks, three clocks. The processor and the bus share the core clock. The peripheral registers use that clock divided by two. The real-time clock block has an oscillator of its own.
- A related pair
The peripheral clock is made from the core clock. Every edge of it comes a fixed time after a core edge. A signal between these two boxes can be timed like any other.
- An unrelated pair
The RTC clock comes from another oscillator. Its edges drift past the core edges. The alarm can change at any moment of a core period.
- The synchronizer
So the alarm does not go straight to the processor. It first passes two flip-flops in a row. Both use the core clock: the synchronizer belongs to the domain that receives.
- The plan
Every arrow between two boxes gets a label: related or unrelated. Every unrelated arrow gets a second label: what must survive the crossing. That list is the clock plan.
Read the diagram as text
- Real-time clock block: RTC clock, 14 ns, from its own oscillator
- Synchronizer: two flip-flops on the core clock
- Processor and bus: core clock, 10 ns
- Peripheral registers: peripheral clock, 20 ns: the core clock divided by two
- Real-time clock block → Synchronizer: alarm: unrelated clocks
- Synchronizer → Processor and bus: one domain
- Processor and bus → Peripheral registers: register access: related clocks
A clock plan for four blocks of ap_soc. The three periods are choices of our lab chip, and the next page uses the same three.
The Smallest Example, Worked by Hand
The core clock rises at 5, 15, 25, 35 and 45 ns. At 22 ns the real-time clock block raises two wires. The alarm is a level: it stays at 1. The tick is an event: it falls again after 2 ns, at 24 ns.
| Core edge | Alarm, first flip-flop | Alarm, second flip-flop | Tick, first flip-flop | Tick, second flip-flop |
|---|---|---|---|---|
| 15 ns | 0 | 0 | 0 | 0 |
| 25 ns | 1: the alarm is high | 0 | 0: the tick fell at 24 | 0 |
| 35 ns | 1 | 1: the core sees the alarm | 0 | 0 |
| 45 ns | 1 | 1 | 0 | 0 |
The level arrives, two edges after it was raised. The pulse began at 22 and ended at 24, and no core edge fell in that time. No flip-flop ever saw it. A second flip-flop cannot bring back what the first one never sampled.
A pulse is safe only if it is wider than one period of the receiving clock. A common rule of thumb asks for one and a half periods.
Now a word of two bits. It changes from 01 to 10. Its two wires differ in length, so bit 1 changes at 64 ns and bit 0 at 66 ns. A core edge falls at 65 ns, between the two.
| Core edge | Bit 1 on its wire | Bit 0 on its wire | What the first flip-flops take |
|---|---|---|---|
| 55 ns | 0 | 1 | 01: the old word |
| 65 ns | 1: it changed at 64 | 1: it changes at 66, too late | 11: a word nobody sent |
| 75 ns | 1 | 0 | 10: the new word |
For one period the receiver holds 11. The sender never sent it. Each bit crossed safely, and the word did not.
The Rules
Rule 1: Flip-flops that use one clock form one clock domain.
A synchronizer belongs to the domain of its own clock: the receiving one.
Rule 2: Two clocks are related only if one source makes both.
Two oscillators with the same number on them are unrelated. Their edges drift.
Rule 3: Every signal between unrelated clocks enters through a synchronizer.
Nothing in the receiving domain may use the first flip-flop.
Rule 4: A synchronizer carries a level that lasts longer than one receiving period.
A shorter pulse can fall between two edges and be lost.
Rule 5: The bits of a word are never synchronized one by one.
They can land on different edges and make a word that was never sent.
Rule 6: Choose the crossing by what must survive.
The table below gives one circuit for each kind of signal.
| The signal is | What must survive | The crossing | Built in |
|---|---|---|---|
| A level | Its latest value | A two-flop synchronizer. | The Two-Flop Synchronizer |
| An event | Every single occurrence | The sender turns the pulse into a level. It waits for an answer from the receiver before it sends the next. | Pulse, Toggle and Handshake |
| A word | All bits, from the same moment | The sender holds the word still. Only one "take it now" bit is synchronized. | Pulse, Toggle and Handshake |
| A stream | Every word, in order | A memory with a write side on one clock and a read side on the other. | The Asynchronous FIFO |
Sources for These Rules
Rule 3, metastability and the two-flop synchronizer: Mehta, ASIC/SoC Functional Design Verification, chapter 8, sections 8.2 and 8.3.1. Also Harris and Harris, Digital Design and Computer Architecture, ARM edition, section 3.5.5. And Weste and Harris, CMOS VLSI Design, fourth edition, section 10.6.2.
Rule 4, a pulse lost between two edges of a slower clock, and the rule of thumb of one and a half periods: Mehta, ASIC/SoC Functional Design Verification, chapter 8, section 8.3.3.
Rule 5, a word of several bits: Mehta, ASIC/SoC Functional Design Verification, chapter 8, section 8.3.4. A stream through a memory with two clocks: section 8.3.5.
Rules 1, 2 and 6 are how a clock plan is written. They are design practice, not rules of a standard.
Now Run It
The lab at the end of this page has two free-running clocks and no bus. A few lines of test code play the real-time clock block. Three two-flop synchronizers receive on the core clock.
sent t=22 alarm=1 tick=1
sample t=26 alarm_1=1 alarm_seen=0 tick_seen=0
sample t=36 alarm_1=1 alarm_seen=1 tick_seen=0
sample t=46 alarm_1=1 alarm_seen=1 tick_seen=0
core edges that saw tick=0
sent t=66 mode=10
sample t=76 mode_seen=11
sample t=86 mode_seen=10Rule 3 at work: at 26 ns the first flip-flop holds the alarm and the second does not yet. At 36 ns the core domain sees it.
Rule 4 at work: tick_seen is 0 in all three samples. The next row counts no core edge that saw the tick. The pulse of 2 ns is gone.
Rule 5 at work: the word 10 is complete at 66 ns. At 76 ns the receiving side holds 11. One period later it holds 10.
This lab leaves the main thing out. A simulator of 0 and 1 cannot show a flip-flop that hovers. So the lab shows what a synchronizer loses, and not what it is for. The 2 ns between the two bits of the word is a lab number.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Few clock domains | A clock for every block | Few crossings to design and check. Blocks share a rate that some do not need. |
| A divided clock for slow blocks | A second oscillator for them | The two clocks stay related, so no synchronizer is needed. The rates are tied together. |
| One crossing for a whole bus transfer | A synchronizer on every bus wire | Address, data and direction arrive as one word. The transfer waits a few periods. |
| The alarm as a level | The alarm as a pulse | It cannot be lost. Someone must clear it after it was served. |
The third row is why a crossing is put where a transfer can wait. A bus that is cut in the middle of its handshake leaves two domains to decide which write happened.
The Trap: Two True Traces
Back to the two engineers. The timer engineer probed the alarm wire and saw a pulse, 2 ns wide. The processor engineer looked at core edges and saw 0 three times. Both are right. The pulse lived and died between two edges.
The fix is not a third flip-flop. The fix is to ask what the alarm means. If it means "service is due", make it a level that stays until it is cleared. If it means "count one more", a level is not enough either: two events in one period would merge into one.
The second trap is a label. Two oscillators on the board both say 50 MHz, so someone treats their clocks as one domain. They are unrelated. Each drifts a little, and sooner or later an edge of one lands on an edge of the other.
At Scale
This section looks ahead. Our map has two crossings. A large chip has thousands, and nobody finds them by reading.
A list of every crossing
A plan lists each crossing with its two clocks, what must survive, and its circuit. A tool finds the crossings in the design, and each must match a row of the list.
Modes change the map
A clock mux can turn a related pair into an unrelated one. The list is checked again for every setting of every mux.
The timing check must know
The program that checks timing treats all clocks as related until it is told otherwise. The next page tells it, and shows what its report then leaves out.
Resets cross too
A reset that is released in one domain reaches flip-flops of another. Reset Across Clock Domains builds the circuit for it.
Try It
Run the lab. A level, a pulse of 2 ns and a word of two bits cross from the RTC clock to the core clock.
Change the width of the pulse from 2 to 12. Predict the last of the first five rows before you run it.
Let both bits of the word change at the same moment. Does the receiver still see 11?
Names Printed by the Lab
| Name | Meaning |
|---|---|
| sent | The moment at which the sending side changes a signal, and its new value. |
| sample | A look at the receiving side, 1 ns after a rising edge of the core clock. |
| alarm_1 | The first flip-flop of the synchronizer for the alarm. |
| alarm_seen, tick_seen, mode_seen | The second flip-flop of each synchronizer: what the core domain may use. |
| core edges that saw tick | The number of core edges at which tick_seen was 1. |
sent t=22 alarm=1 tick=1 sample t=26 alarm_1=1 alarm_seen=0 tick_seen=0 sample t=36 alarm_1=1 alarm_seen=1 tick_seen=0 sample t=46 alarm_1=1 alarm_seen=1 tick_seen=0 core edges that saw tick=0 sent t=66 mode=10 sample t=76 mode_seen=11 sample t=86 mode_seen=10Check Yourself
Common Mistakes
Wrong Treat two oscillators of the same rate as one domain.
Their edges drift past each other.
Fix Trace each clock to its source. One source, or unrelated.
Wrong Send a short pulse through a two-flop synchronizer.
It can fall between two edges of the receiving clock.
Fix Send a level, and clear it after it was served.
Wrong Put a synchronizer on every bit of a word.
The bits can land on different edges.
Fix Hold the word still and synchronize one "take it now" bit.
Remember
- Flip-flops that use one clock form a clock domain. Clocks are related only if one source makes both.
- A signal between unrelated clocks enters through a two-flop synchronizer in the receiving domain.
- A synchronizer samples: it can lose a short pulse, and it can tear a word apart.
- Plan every crossing by what must survive: a level, an event, a word or a stream.