FIFO
FIFO
A FIFO (First-In, First-Out) is a queue-based memory buffer where data is written into the queue in the order it arrives and is read
in the same order. The principle follows a first-come, first-served approach, making it ideal for buffering, data transfer, and
synchronization in digital systems.
Where:
Fwrite = Write clock frequency
Fread = Read clock frequency
Burst Size = Maximum burst of incoming data
Margin = Safety margin (typically 10-20% of the calculated depth)
2. Asynchronous FIFO
www.linkedin.com/in/harshita-harshi-9377891bb
Synchronous FIFO
Read and write operations occur under the same clock domain.
Requires control logic for full, empty, and almost full/almost empty status.
FIFO Control Logic:
(a) FIFO Full Condition
A FIFO is full when the write pointer catches up to the read pointer after writing.
Full Condition: (Wptr+1)mod N = Rptr
(b) FIFO Empty Condition
A FIFO is empty when the read pointer reaches the write pointer (i.e., no unread data is available).
Empty Condition: Wptr=Rptr
These flags are used to prevent overflow (writing to a full FIFO) or underflow (reading from an empty FIFO).
module synchronous_fifo Depth of FIFO: The number of slots or rows in FIFO is called the
#(parameter DEPTH=8, DATA_WIDTH=8) depth of the FIFO.
( input clk, rst_n,
Width of FIFO: The number of bits that can be stored in each slot
input w_en, r_en,
or row is called the width of the FIFO.
input [DATA_WIDTH-1:0] data_in,
output reg [DATA_WIDTH-1:0] data_out, Working Principle
output full, empty Data is written into the FIFO on a same clock edge till FIFO
); full.
reg [$clog2(DEPTH)-1:0] w_ptr, r_ptr; Data is read from the FIFO on a same clock edge till FIFO
reg [DATA_WIDTH-1:0] fifo[DEPTH]; empty.
// Set Default values on reset.
always@(posedge clk) begin
if(!rst_n) begin
w_ptr <= 0; r_ptr <= 0;
data_out <= 0;
end
end
// To write data to FIFO
always@(posedge clk) begin
if(w_en & !full)begin
fifo[w_ptr] <= data_in;
w_ptr <= w_ptr + 1;
Advantages of Synchronous FIFO
end
:: Simple control logic due to a single clock domain.
end
:: Faster and more power-efficient compared to asynchronous FIFOs.
// To read data from FIFO
:: Easier to implement in hardware (FPGAs, ASICs) using Block(BRAM).
always@(posedge clk) begin
if(r_en & !empty) begin :: Low latency and high-speed data transfer.
data_out <= fifo[r_ptr];
r_ptr <= r_ptr + 1;
end
end
assign full = ((w_ptr+1'b1) == r_ptr); Applications of Synchronous FIFO
assign empty = (w_ptr == r_ptr); 🔹 Data buffering in processors and communication interfaces
endmodule 🔹 Pipeline processing in DSP (Digital Signal Processing)
🔹 Networking devices for buffering
🔹 Audio and video streaming systems
🔹 Memory controllers for temporary data storage
www.linkedin.com/in/harshita-harshi-9377891bb
Asynchronous FIFO
An Asynchronous FIFO is a type of FIFO memory used to transfer data between two different clock domains. It allows smooth data
communication between two circuits that operate on different clock frequencies.
>> Many digital systems have different clock domains for different components.
>> A direct connection between these domains causes metastability issues.
>> Asynchronous FIFOs ensure reliable data transfer between these domains without data loss or corruption.
endmodule
www.linkedin.com/in/harshita-harshi-9377891bb