Fifo Implementation in Verilog
Fifo Implementation in Verilog
Abstract..5 1. Introduction6 2. Design of FIFO.8 2.1 Working of FIFO9 3. Flow chart........15 4. Verilog Source code...17 5. Test bench code..22 6. Simulating the design....23 7. Simulation Results..30 8.Applications...31 9. Conclusion37 9.References..38
Page 2
1.INTRODUCTION:
WHAT IS A FIFO (first in first out)? In computer programming, FIFO (first-in, first-out) is an approach to handling program work requests from queues or stacks so that the oldest request is handled first. In hardware it is either an array of flops or Read/Write memory that store data given from one clock domain and on request supplies with the same data to other clock domain following the first in first out logic. The clock domain that supplies data to FIFO is often referred as WRITE OR INPUT LOGIC and the clock domain that reads data from the FIFO is often referred as READ OR OUTPUT LOGIC. FIFOs are used in designs to safely pass multi-bit data words from one clock domain to another or to control the flow of data between source and destination side sitting in the same clock domain. If read and write clock domains are governed by same clock signal the FIFO is said to be SYNCHRONOUS and if read and write clock domains are governed by different (asynchronous) clock signals FIFO is said to be ASYNCHRONOUS.
Page 3
SYNCHRONOUS FIFO A synchronous FIFO refers to a FIFO design where data values are written sequentially into a memory array using a clock signal, and the data values are sequentially read out from the memory array using the same clock signal. In synchronous FIFO the generation of empty and full flags is straight forward as there is no clock domain crossing involved. Considering this fact user can even generate programmable partial empty and partial full flags which are needed in many applications.
Page 4
F_EmptyN
F_FullN F_Data
F_LastN F_SlastN
FClrN
F_OutN F_FirstN
FIFO is a First-In-First-Out memory queue with control logic that manages the read and write operations, generates status flags, and provides optional handshake signals for interfacing with the user logic. It is often used to control the flow of data between source and destination. FIFO can be classified as synchronous or asynchronous depending on whether same clock or different (asynchronous) clocks control the read and write operations. In this project the objective is to design, verify and synthesize a synchronous FIFO using binary coded read and write pointers to address the memory array. FFIO full and empty flags are generated and passed on to source and destination logics, respectively, to pre-empt any overflow or underflow of data. In this way data integrity between source and destination is maintained.
A more efficient method to construct a FIFO is to create a circular buffer using an array of memory elements designed so that data can be written to and read from arbitrary locations in the memory array. These structures are also called parallel FIFOs and are often built using common SRAM or DRAM memories. The random access nature of memory arrays enables low minimum latencies, and high energy efficiencies compared to linear FIFOs. Scalability is also dramatically improved due to the fact that clock distribution is not directly affected by the FIFO size and the memory density is higher. In the event of a bu_er size change, generally only very minor control logic changes are required.
Page 5
Figure 3: FIFO block diagram with write and read control logic
Figure 3 depicts the basic building blocks of a synchronous FIFO which are: memory array, write control logic and read control logic. The memory array can be implemented either with array of flip-flops or with a dual-port read/write memory. Both of these implementations allow simultaneous read and write accesses. This simultaneous access gives the FIFO its inherent synchronization property. There are no restrictions regarding timing between accesses of the two ports. This means simply, that while one port is writing to the memory at one rate, the other port can be reading at another rate totally independent of one another. The only restriction placed is that the simultaneous read and write access should not be from/to the same memory location(flowthrough condition).
The Synchronous FIFO has a single clock port Clk for both data-read and data-write operations. Data presented at the module's data-input port Data_In is written into the next available empty memory location on a rising clock edge when the write-enable input FinN is high. The full status output F_FullN indicates that no more empty locations remain in the module's internal memory. Data can be read out of the FIFO via the module's data-output port F_Data in the order in which it was written by asserting read-enable signal F_OutN prior to a rising clock edge. The memory-empty status output F_EmptyN indicates that no more data resides in the module's internal memory.
Page 6
WRITE CONTROL LOGIC Write Control Logic is used to control the write operation of the FIFOs internal memory. It generates binary-coded write pointer which points to the memory location where the incoming data is to be written. Write pointer is incremented by one after every successful write operation. Additionally it generates FIFO full F_FullN, F_LastN (only single space remianing),F_SlastN(2 spaces remaining ) signals which in turn are used to prevent any data loss. For example if a write request comes when FIFO is full then Write Control Logic stalls the write into the memory till the time F_FullN flag gets de-asserted. It intimates the stalling of write to source by not sending any acknowledgement in response to the write request.
READ CONTROL LOGIC Read Control Logic is used to control the read operation of the FIFOs internal memory. It generates binary-coded read pointer which points to the memory location from where the data is to be read. Read pointer is incremented by one after every successful read operation. Additionally it generates FIFO empty and only one data value in FIFO, flags which in turn are used to prevent any spurious data read. For example if a read request comes when FIFO is empty then Read Control Logic stalls the read from the memory till the time F_EmptyN flag gets de-asserted.
MEMORY ARRAY:FIFO MEM BLOCK Memory Array is an array of flip-flops which stores data. Number of data words that the memory array can store is often referred as DEPTH of the FIFO. Length of the data word is referred as WIDTH of the FIFO. Besides flop-array it comprises read and write address decoding logic.
Page 8
Given the use of read and write pointers, there are two primary methods to define the empty and full conditions. As shown in Figure 2.6, the first possibility is to define the empty condition as occurring when wr ptr is equal to rd ptr. The maximum occupancy" (full ) condition is indicated when wr ptr + 1 = rd ptr or alternatively, when wr ptr = rd ptr -1. The second case is shown in Figure 2.7 where the full condition is indicated by equality of rd ptr and wr ptr and the minimum occupancy" (one datum) condition is indicated by rd ptr = wr ptr +1. Clearly, these schemes present problems in representing all possible states because the case where rd ptr = wr ptr becomes ambiguous without either keeping track of the pointer
MTech VLSI & ES,PESIT,BSC Page 9
PORT LIST:
PIN NO. 1 Clk active high input clock signal is provided to synchronise all operations in the FIFO. 2 RstN active low input this signal when asserted low, resets the fifo. All counters are set to 0. 3 4 5 7 8 9 Data_In FInN FOutN F_EmptyN F_FullN F_LastN 32-bit input active low input active low input active low output active low output active low output it is a 32-bit data input into FIFO. write into FIFO signal read from FIFO signal signal indicating that FIFO is empty signal indicating that FIFO is full signal indicating that FIFO has space for one last data value 10 F_SlastN active low output signal indicating that FIFO has space for two data values 11 F_FirstN active low output signal indicating that there is only one data value in FIFO. 12 F_Data 32-bit output it is 32-bit data output from FIFO. PIN NAME SIAGNAL TYPE INDICATION
Page 10
y
If(~RstN|~FClrN)?
If(~FinN &F_FullN)?
if(fcounter==FDEPTH)?
if(fcounter==0)?
if(fcounter==1)?
Page 11
A
F_FullN= F_lastN= F_EmptyN=F_FirstN=1; F_SlastN=0;
if(fcounter==2)?
if(fcounter==3)?
STOP
Page 12
Design of First In First Out Memory Block 4.VERILOG SOURCE CODE FOR FIFO DESIGN: Memory block module:
`resetall `timescale 1ns/1ns `view vlog `define FWIDTH 32 `define FDEPTH 4 `define FCWIDTH 2 module FIFO_MEM_BLK(clk,writeN,wr_addr, rd_addr, data_in,data_out); input clk; //input clk input writeN; //write signal to put data into FIFO input [(`FCWIDTH-1):0] wr_addr; //write address input [(`FCWIDTH-1):0] rd_addr; //read address input [(`FWIDTH-1):0] data_in; //datain in to memory block output [(`FWIDTH-1):0] data_out; //data out from the memory block FIFO wire [(`FWIDTH-1):0] data_out; reg [(`FWIDTH-1):0] FIFO [0:(`FDEPTH-1)]; assign data_out =FIFO[rd_addr]; always@(posedge clk) begin if(writeN==1'b0) FIFO[wr_addr]<= data_in; end endmodule `noview
FIFO module:
`timescale 1ns / 1ns `define FWIDTH 32 `define FDEPTH 4 `define FCWIDTH 2 //width of the FIFO //depth of the FIFO //counter width of the FIFO 2 to power FCWIDTH
module fifo(Clk,RstN,Data_In,FClrN,FInN,FOutN, F_Data,F_FullN,F_LastN,F_SLastN,F_FirstN,F_EmptyN); input Clk; input RstN; input [(`FWIDTH-1):0] Data_In; input FClrN; input FInN; input FOutN; //clk signal //low asserted reset signal //data into FIFO //clear signal to FIFO //write into FIFO signal //read from FIFO signal
Page 13
output [(`FWIDTH-1):0] F_Data; output F_FullN; output F_LastN; output F_SLastN; output F_EmptyN; output F_FirstN; FIFO reg F_FullN; reg F_EmptyN; reg F_LastN; reg F_SLastN; reg F_FirstN; reg [`FCWIDTH:0] fcounter; FIFO reg [(`FCWIDTH-1):0] rd_ptr; reg [(`FCWIDTH-1):0] wr_ptr; wire [(`FWIDTH -1):0] FIFODataOut; wire [(`FWIDTH-1):0] FIFODataIn; wire ReadN=FOutN; wire WriteN=FInN; assign F_Data = FIFODataOut; assign FIFODataIn = Data_In; `uselib view=vlog FIFO_MEM_BLK memblk(.clk(Clk),
// FIFO data out //FIFO full indicating signal //FIFO last but one signal //FIFO Slast but one signal //FIFO empty indicating signal
//counter indicates num of data in // current read pointer //current write pointer //data out from FIFO MemBlk //data into FIFO MemBlk
Page 14
Page 15
always@(posedge Clk or negedge RstN) begin if(!RstN) F_LastN <= 1'b1; else begin if(FClrN== 1'b1)begin if((F_FullN== 1'b0 && ReadN== 1'b0)||(fcounter==(`FDEPTH-2) && WriteN==1'b0 && ReadN==1'b1)) F_LastN <= 1'b0; else if(F_LastN==1'b0 && (ReadN ^ WriteN)) F_LastN <=1'b1; end else F_LastN <= 1'b1; end end always@(posedge Clk or negedge RstN) begin if(!RstN) F_FullN <= 1'b1; else begin if(FClrN==1'b1) begin
Page 16
Page 17
Page 18
ELABORATING
&
SIMULATING
THE
Page 19
Page 20
Page 21
Page 22
Page 23
Page 24
Page 25
7.SIMULATION WAVEFORM:
Page 26
8.APPLICATIONS:
Figure 7:Sytem architecture using FIFO module for communication 1.FIFO module for communication:FIFOs are used to safely pass data between two asynchronous clock domains. In System-on-Chip designs there are components which often run on different clocks. So, to pass data from one such component to another we need ASYNCHRONOUS FIFO Some times even if the Source and Requestor sides are controlled by same clock signal a FIFO is needed. This is to match the throughputs of the Source and the Requestor. For example in one case source may be supplying data at rate which the requestor can not handle or in other case requestor may be placing requests for data at a rate at which source can not supply. So, to bridge this gap between source and requestor capacities to supply and consume data a SYNCHRONOUS FIFO is used which acts as an elastic buffer.
2. Asynchronous Operation of Exclusive Read/Write FIFOs: In use, the SN74LS224A exclusive read/write FIFO timing conditions on the write (WRITE CLOCK) and read (READ CLOCK) inputs must be maintained to ensure proper functioning of the devices. Concurrent read/write FIFOs are also offered on the market that, for their empty or full state, require timing conditions between the write and read inputs that ensure error-free operation of the FULL and EMPTY flags. In addition to the minimum pulse widths for the two signals (WRITE CLOCK 60 ns minimum, READ CLOCK 30 ns minimum), it is necessary to ensure that alternating write and read instructions are separated by a time window of at least 50 ns. If the write and read signals originate from two sources that work asynchronously to one another, a synchronizing circuit should be used as shown in Figure . This ensures correct operation even if the two signals appear at the same time.
Page 27
Figure 8: Synchronizing Circuit for Generating WRITE CLOCK and READ CLOCK Signals
3. Connection of Peripherals to Processors: Modern processors are often considerably faster than peripherals that are connected to them. FIFOs can be used so that the processing speed of a processor need not be reduced when it exchanges data with a peripheral. If the peripheral is sometimes faster than the processor, a FIFO can again be used to resolve the problem. Different variations of circuitry are possible, depending on the particular problem. In some cases, the processor reads input data over a unidirectional peripheral, for example, from an A/D converter .A FIFO can buffer a certain amount of input data, then use an interrupt so that the processor reads the data. This interrupt can be triggered by a HALF FULL, ALMOST FULL, or FULL flag.
Page 28
Often the connected peripherals are bidirectional, like a parallel port, a serial port, a hard-disk controller, or the interface with a magnetic-tape drive. In these cases, there is the possibility of using a bidirectional FIFO like SN74ACT2235. Two independent FIFOs are implemented in this device, each with a word width of 9 bits and memory depth of 1024 words.Figure shows a block diagram for such an application
Page 29
4. Block Transfer of Data: Data are often split into blocks and transmitted on data lines. Computer networks and digital telephone-switching installations are examples of this application. If such a conversion into blocks has to be made at very high speed, it is possible only with appropriate hardware, not through software. A simple solution to this hardware problem is the use of FIFOs (see Figure ). A FIFO with a HALF FULL flag should be selected. Furthermore, memory depth should correspond to twice the size of a block. As soon as the HALF FULL flag is set, the send controller starts sending the data block. The send controller consists, in this case, of a counter and some gates and is very easy to implement with just one PAL. The writing of data into the FIFO can be carried on continuously and is independent of the transfer of data blocks.
Page 30
5. Programmable Delay:With FIFOs, it is possible to implement a programmable, digital delay line with minimum effort. Because of the programmable AF/AE (ALMOST FULL/ALMOST EMPTY) flag of the SN74ACT7881, only one inverter in addition to the FIFO is Necessary.
6. Collecting Data Before and After an Event: By extension of the device in Figure , data words can be collected both before and after the occurrence of an event (see Figure ); 1024 data words are always collected. With the aid of the programmable AF/AE flag, it is possible to specify the number of data words that are collected before and after the event. Until the
MTech VLSI & ES,PESIT,BSC Page 31
Page 32
9.CONCLUSION:
The main objective of the project was to have a working FIFO memory block that functions correctly as per its specification & intent, the same was achieved by designing and simulating the FIFO design using CADENCE TOOLS.This design was verified for its correct functionality by writing testbench & analyzing the actual response against expected one from simulation waveforms.
Page 33
10.REFERENCES:
1.E. Brunvand, \Low latency self-timed ow-through _fos," in Advanced Research in VLSI, Mar.1995, pp. 76. 2. Sutherland and S. Fairbanks, \GasP: A minimal FIFO control," in Advanced Research in Asynchronous Circuits and Systems, Mar. 2001, pp. 46. 3.J. T. Yantchev, C. G. Huang, M. B. Josephs, and I. M. Nedelchev, \Low-latency asynchronous FIFO bu_ers," in Proc. Asynchronous Design Methodologies, May 1995. 4. Chris J. Myers, Asynchronous Circuit Design, John Wiley & Sons, Inc., 2001. 5. W. J. Dally and J. W. Poulton, Digital Systems Engineering, Cambridge University Press, Cambridge, UK, 1998. 6.J. F. Wakerly, Digital Design: Principles and Practices, Prentice-Hall, third edition, 1999. 7.M. Hurtado and D. L. Elliot, \Ambiguous behavior of bistable elements," in Allerton Conf. on Circuit and System Theory, Oct. 1975, pp. 605. 8.J. M. Rabaey, A. Chandrakasan, and B. Nikolic, Digital Integrated Circuits, A Design Perspec- tive, Prentice Hall, Upper Saddle River, NJ, 2003. 9. R. Ho, K.W. Mai, and M.A. Horowitz, \The future of wires," in Proceedings of the IEEE, Apr.2001, vol. 89, pp. 490{504}. 10. G. Semeraro, G. Magklis, and et al., \Energy-e_cient processor design using multiple clock domains with dynamic voltage and frequency scaling," in International Symposium on High- Performance Computer Architecture, Feb. 2002, pp. 29. 11. D. M. Chapiro, Globally-Asynchronous Locally-Synchronous Systems, Ph.D. thesis, StanfordUniversity, Stanford, CA, USA, 1984. 12.FIFO architecture,functions and applications,texas instruments.
Page 34