Skip to content

raviranjan-vlsi/async-fifo-verilog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ“¦ Parameterized Asynchronous FIFO using Gray-Code Pointers

Verilog Domain Concept Design License


πŸš€ Overview

This project implements a Parameterized Asynchronous FIFO (First-In First-Out) buffer using Gray-code pointer synchronization to enable reliable Clock Domain Crossing (CDC) between two independent clock domains.

The design ensures safe data transfer between modules operating at different clock frequencies, which is a common requirement in System-on-Chip (SoC) architectures, communication interfaces, and digital hardware systems.

🎯 Key Features

βœ” Parameterized FIFO depth and data width
βœ” Independent read and write clocks
βœ” Gray-code pointer synchronization
βœ” Full and Empty detection
βœ” Almost Full and Almost Empty flags
βœ” Dual-port FIFO memory
βœ” Safe clock domain crossing design


🧠 Problem Addressed

When two modules operate on different clocks, direct data transfer can lead to:

  • Metastability
  • Data corruption
  • Timing hazards

Asynchronous FIFOs solve this problem by acting as a buffer between clock domains.


πŸ— System Architecture

The architecture contains the following modules:

  • Write Pointer Logic
  • Read Pointer Logic
  • FIFO Memory (Dual-Port)
  • Gray Code Pointer Synchronization
  • Full & Almost Full Detection
  • Empty & Almost Empty Detection

βš™ Core Modules

Write Pointer Logic

Maintains the write address inside the write clock domain.

Features:

  • Binary write pointer
  • Gray-code conversion
  • Write address generation
  • Overflow protection


Read Pointer Logic

Maintains the read address inside the read clock domain.

Features:

  • Binary read pointer
  • Gray-code conversion
  • Safe pointer synchronization
  • Underflow protection


FIFO Memory

The memory block is implemented as a dual-port memory.

Port Function
Write Port Data written using write clock
Read Port Data read using read clock

Advantages:

  • Simultaneous read and write
  • Efficient buffering
  • Prevents overflow/underflow

πŸ”„ Gray Code Synchronization

Binary counters can change multiple bits simultaneously, which can cause synchronization errors across clock domains.

Gray-code solves this problem because:

βœ” Only one bit changes at a time
βœ” Reduced metastability risk
βœ” Reliable pointer synchronization

Two-stage flip-flop synchronizers are used for safe CDC transfer.


πŸ“Š Full and Almost Full Detection

The FIFO becomes FULL when the write pointer catches the read pointer after wrap-around.

Full Detection Logic

Next Gray Write Pointer == Inverted MSB of Read Pointer

Almost Full

Provides early warning before FIFO overflow.

Used Entries >= DEPTH - ALMOST_FULL_MARGIN


πŸ“‰ Empty and Almost Empty Detection

The FIFO becomes EMPTY when:

Read Pointer == Synchronized Write Pointer

Almost Empty

Indicates the buffer is close to empty.

Used Entries <= ALMOST_EMPTY_MARGIN


πŸ§ͺ Simulation Results

The FIFO was verified using a multi-clock testbench.

Simulation Waveform

Verified conditions:

βœ” Correct data ordering
βœ” Proper flag generation
βœ” Stable clock domain crossing


🧩 RTL Schematic

The RTL view shows:

  • Synchronizer modules
  • FIFO memory block
  • Pointer generation logic
  • Flag detection modules

πŸ“ Project Structure

Asynchronous-FIFO
β”‚
β”œβ”€β”€ rtl
β”‚   β”œβ”€β”€ asynchronous_fifo.v
β”‚   β”œβ”€β”€ sync_w2r.v
β”‚   β”œβ”€β”€ sync_r2w.v
β”‚   β”œβ”€β”€ fifo_mem.v
β”‚   β”œβ”€β”€ full_with_almost.v
β”‚   └── empty_with_almost.v
β”‚
β”œβ”€β”€ testbench
β”‚   └── fifo_tb.v
β”‚
β”œβ”€β”€ docs
β”‚   β”œβ”€β”€ architecture.png
β”‚   β”œβ”€β”€ pointer_logic.png
β”‚   └── synchronizer.png
β”‚
β”œβ”€β”€ images
β”‚   β”œβ”€β”€ simulation_output.png
β”‚   └── rtl_schematic.png
β”‚
└── README.md

⚑ Design Parameters

Parameter Description
WIDTH Data width
DEPTH FIFO depth
ALMOST_FULL_MARGIN Threshold for Almost Full
ALMOST_EMPTY_MARGIN Threshold for Almost Empty

Applications

This FIFO can be used in:

  • SoC Interconnect Systems
  • Communication Interfaces
  • Bus Bridges
  • Network Routers
  • Processor Pipelines
  • DMA Controllers

Future Improvements

Possible extensions include:

  • AXI / AHB FIFO integration
  • Formal CDC verification
  • FPGA implementation
  • ASIC optimization
  • Multi-channel FIFO architecture

πŸ‘¨β€πŸ’» Author

Raviranjan Kumar

M.Tech – Embedded System Design
National Institute of Technology Kurukshetra


⭐ Support

If you find this project useful, please ⭐ star the repository.

About

Parameterized Asynchronous FIFO in Verilog using Gray Code pointers with Full, Empty, Almost Full, and Almost Empty flags for safe clock domain crossing (CDC).

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors