When writer and reader live on different clocks, a sync FIFO's shared pointers break. The async FIFO is the standard bridge — and its secret weapon is Gray-coded pointers crossed through synchronizers. This lesson is the overview; the CDC course covers the deep dive.
An async FIFO stores data in a dual-port RAM. Write logic runs on wr_clk; read logic on rd_clk. Pointers cross domains as Gray codes through 2+ flop synchronizers so full/empty flags are safe (conservative).
Real chips have multiple clock domains: CPU core, DDR controller, PCIe PHY, sensor interface. You cannot share a sync FIFO pointer across unrelated clocks — metastability and multi-bit coherency destroy count and compare logic.
Producer and consumer operate asynchronously. Data must be buffered safely between domains.
Burst writer (e.g. DMA) vs steady reader (processor). FIFO absorbs bursts without dropping beats.
Only control pointers cross — data stays in RAM written on wr_clk, read on rd_clk.
Two people on different schedules pass notes through a locked mailbox. Each has their own key (clock). They never reach in at the same time — they only check a flag ("mail waiting") that the other side updates safely with a delay.
Each side computes full/empty using its local pointer and the synchronized remote pointer. Data never crosses — only Gray pointers do.
At count 7→8, binary flips 4 bits. Gray flips exactly 1 bit. A 2-flop synchronizer on Gray may sample old or new value — never an impossible state.
| Count | Binary | Gray | Bits changed |
|---|---|---|---|
| 0 | 000 | 000 | — |
| 1 | 001 | 001 | 1 |
| 2 | 010 | 011 | 1 |
| 3 | 011 | 010 | 1 |
| 4 | 100 | 110 | 1 |
| 5 | 101 | 111 | 1 |
| 6 | 110 | 101 | 1 |
| 7 | 111 | 100 | 1 |
// Binary ↔ Gray for async FIFO pointers
function automatic [PTR_W:0] bin2gray(input [PTR_W:0] bin);
bin2gray = bin ^ (bin >> 1);
endfunction
function automatic [PTR_W:0] gray2bin(input [PTR_W:0] gray);
integer i;
gray2bin[PTR_W] = gray[PTR_W];
for (i = PTR_W-1; i >= 0; i = i - 1)
gray2bin[i] = gray2bin[i+1] ^ gray[i];
endfunction
// Cross wr_gray to rd_clk domain (2-flop synchronizer)
reg [PTR_W:0] rd_sync_wr_gray_q1, rd_sync_wr_gray_q2;
always @(posedge rd_clk or negedge rd_rst_n) begin
if (!rd_rst_n) begin
rd_sync_wr_gray_q1 <= {(PTR_W+1){1'b0}};
rd_sync_wr_gray_q2 <= {(PTR_W+1){1'b0}};
end else begin
rd_sync_wr_gray_q1 <= wr_gray;
rd_sync_wr_gray_q2 <= rd_sync_wr_gray_q1;
end
end
Never synchronize a binary multi-bit pointer directly. Never use the synchronized pointer for RAM addressing — only for full/empty comparison. RAM access uses the local binary pointer.
Because synchronized pointers lag reality, flags must be conservative:
// Write side: full when wr_gray == {~rd_gray_sync[MSB], rd_gray_sync[MSB-1:0]}
assign wr_full = (wr_gray == {~rd_gray_sync[PTR_W], rd_gray_sync[PTR_W-1:0]});
// Read side: empty when rd_gray == wr_gray_sync
assign rd_empty = (rd_gray == wr_gray_sync);
Go deeper: Full CDC methodology — metastability MTBF, synchronizer chains, pulse crossing, and formal CDC signoff — is covered in the EcrioniX CDC course. Also see Premium course index for related material.
2-flop vs 3-flop sync, MTBF calculation, pulse synchronizers, and structural CDC lint rules.
Tools check for unsynchronized crossings, reconvergence, and glitch-prone paths before tapeout.
Xilinx FIFO Generator, Intel SC FIFO — parameterized, timing-closed, use in production flows.
| ✅ Do | ❌ Don't |
|---|---|
| Gray-encode pointers before CDC | Sync binary pointers for full/empty |
| Use 2+ flop synchronizers per Gray bus | Assume synchronized ptr is cycle-accurate |
| Reset both domains independently | Cross async reset without synchronizer |
| Use dual-port RAM (true dual-port or 2R1W) | Read/write same addr same cycle blindly |
| Document conservative flag latency | Build full custom async FIFO without review |
| Use vendor FIFO IP when possible | Cross data buses without handshake/FIFO |
CDC bugs hide in corner cases. Your testbench should vary clock ratios and phase:
wr_full, verify no write corruptionrd_empty, verify no read garbagewr_rst and rd_rst independently; FIFO must recover emptyTypical wr_clk=100MHz, rd_clk=66MHz fill-then-drain pattern:
fill phase → full → drain → empty
// Clock generators — different periods
initial wr_clk = 0; always #5 wr_clk = ~wr_clk; // 100 MHz
initial rd_clk = 0; always #7.5 rd_clk = ~rd_clk; // ~67 MHz
task fill_to_full;
integer i;
begin
for (i = 0; i < DEPTH; i = i + 1) begin
@(posedge wr_clk);
wr_en = 1; wdata = i[7:0];
end
@(posedge wr_clk); wr_en = 0;
if (!wr_full) $display("FAIL: not full after %0d writes", DEPTH);
end
endtask
"Would you design an async FIFO from scratch?" — For learning and small FPGAs, yes — understand Gray pointers and conservative flags. For production ASICs, use characterized vendor IP or a team-reviewed library cell. Your value is knowing why it works and how to verify it.