In-depth understanding of FIFO (including the explanation of FIFO depth)

Source: Internet
Author: User

FIFO:
1. First input first output (FIFO) is a traditional method of execution in order. The first input command is completed and pulled back before the second command is executed.
1. What is FIFO?
FIFO is the abbreviation of first in first out. It is a kind of first-in-first-out data cache. The difference between FIFO and ordinary memory is that there is no external read/write address line, which is very simple to use, however, the disadvantage is that data can only be written in sequence, and data can be read in sequence. The data address is automatically added to 1 by internal read/write pointers, A specified address cannot be read or written by the address line as in normal storage.
2. Under what circumstances should I use FIFO?
FIFO is generally used for data transmission between different clock domains, such as AD data collection at one end of FIFO and PCI bus of the computer at the other end, assume that the ad acquisition rate is 16-bit 100 k SPS, the data volume per second is 1.6 K × 16 bit = Mbps, the PCI bus speed is 33 MHz, the bus width is 32 bit, the maximum transmission rate is 1056 Mbps. In two different clock domains, the FIFO can be used as the data buffer. In addition, FIFO can be used for data interfaces of different widths, such as single-chip microcomputer bit 8-bit data output, while DSP may be a 16-bit data input, when the single-chip microcomputer is connected to the DSP, the FIFO can be used for data matching.
3. Some important parameters of FIFO
FIFO width: The width that is often seen in English documents. It is only the data bit of a FIFO read/write operation, just as the MCU has 8-bit and 16-bit, ARM 32-bit and so on. The width of the FIFO is fixed in a single-chip IC. You can also choose one. If you use FPGA to implement a FIFO, its data bit, that is, the width can be customized.
Depth of the FIFO: The deepth refers to the number of N-bit data that can be stored in the FIFO (if the width is N ). For example, if the depth of an 8-bit FIFO is 8, it can store 8 8-bit data. If the depth is 12, it can store 12 8-bit data, the depth of FIFO can be large or small. I personally think that there is no fixed formula for calculating the depth of FIFO. In actual work, the full/empty mark of the data in the FIFO can control the data to continue writing or reading. In a specific application, it is impossible to calculate the exact required FIFO depth by some parameters, which is feasible when the write speed is better than the read speed, however, in actual use, the FIFO depth is usually greater than the calculated value. Generally, you can estimate the approximate width and depth based on the specific situation of the circuit while taking into account the system performance and FIFO cost. For applications whose write speed is slower than the read speed, the depth of the FIFO should be determined by the specific requirements based on the read data structure and read data.
Full sign: A signal sent by the FIFO status circuit when the FIFO status is full or is about to be full, to prevent the FIFO write operation from continuing to write data to the FIFO status and causing overflow (overflow ).
Empty flag: A signal sent by the FIFO status circuit when the FIFO is empty or is to be empty, in order to prevent the read operation of the first-in-first-out from reading data from the first-in-first-out, leading to the reading of invalid data (underflow ).
Read clock: the clock that the read operation follows. Data is temporarily read along each clock edge.
Write clock: The Clock followed by write operations. Data is temporarily written along each clock edge.
Read pointer: points to the next read address. Automatically add 1 after reading.
Write pointer: point to the next address to be written. After writing, add 1 automatically.
A read/write pointer is actually a read/write address, but this address cannot be selected randomly, but it is continuous.
4. FIFO Classification
The root clock domain that uses FIFO, which can be divided into synchronous FIFO and asynchronous FIFO. Synchronous FIFO refers to the same clock as the read clock and write clock. A read/write operation occurs temporarily along the clock edge. Asynchronous FIFO indicates that the read/write clock is inconsistent and the read/write clock is independent of each other.
5. Difficulties in FIFO Design
The difficulty of the FIFO design lies in how to judge whether the FIFO is empty or full. To ensure that the data is correctly written or read, without the benefit or read null status, you must ensure that the FIFO is full and cannot perform write operations. Read operations cannot be performed in an empty state. How to judge whether a FIFO is full or empty becomes the core issue of the FIFO design. Because synchronous FIFO is rarely used, only the null/full mark of Asynchronous FIFO is described here.
In the design of the trigger, it is inevitable that the sub-steady state problem will occur (for details about the sub-steady state, refer to the relevant information ). In the circuit involving the trigger, the sub-steady state cannot be completely eliminated. You can only find a way to minimize the probability of its occurrence. One of the methods is to use the Gray code. The gray code is transformed by only one digit between two adjacent code elements (in many cases, many code elements change at the same time ). This will avoid the sub-steady state when the counter is synchronized with the clock. However, the gray code has the disadvantage that it can only define 2 ^ n depth, rather than the random definition of the FIFO depth as the binary code, because the Gray code must cycle a 2 ^ N, otherwise, the difference between two adjacent code elements cannot be guaranteed, so it is not a real thunder code. The second is to use a redundant trigger. Assuming that the probability of a trigger's sub-steady state is P, the probability of two and the associated trigger's sub-steady state is the square of P. However, this increases latency. The occurrence of the sub-steady state will cause a FIFO error. The address pointer of the read/write clock sample will be different from the actual value, which leads to an incorrect write or read address. Due to the delay, the null/full mark is not necessarily generated when the FIFO is really empty/full. The "null"/"full" sign may appear when the FIFO is not empty or full. This is nothing bad, as long as the FIFO does not appear Overflow
Or underflow is OK.
Many articles about FIFO actually discuss different algorithms with null or full signs.
In Vijay A. nebhrajani's "Asynchronous FIFO structure", the author proposes two algorithms for the FIFO null/full mark.
First Algorithm: Construct a FIFO with a pointer width of N + 1 and a depth of 2 ^ n Bytes (convert the gray pointer to a binary pointer for the comparison of the cursor ). When the highest bits in the binary code of the pointer are inconsistent and the other N bits are equal, the FIFO is full (in Clifford E. in Cummings's article, the gray Code indicates that the first two are not the same, and the last two LSB are the same as full, which is the same as the binary representation of MSB ). When the pointer is completely equal, the FIFO is null. This may not be easy to see. An example shows how a 8-byte FIFO works (using a pointer that has been converted to binary ). Required o_width = 8, required o_depth =
2 ^ n = 8, n = 3, and the pointer width is n + 1 = 4. At first, rd_ptr_bin and wr_ptr_bin were both "0000 ". In this case, 8 bytes of data are written into the FIFO. Wr_ptr_bin = 1000, rd_ptr_bin = 0000 ". Of course, this is the full condition. Now, assume that eight read operations are performed, so that rd_ptr_bin = "1000", this is an empty condition. The other 8 write operations will make wr_ptr_bin equal to "0000", but rd_ptr_bin is still equal to "1000", so FIFO is a full condition.
Obviously, the starting pointer does not need to be "0000 ". If it is "0100" and the FIFO is empty, the 8 bytes will make wr_ptr_bin = "1100", and rd_ptr_bin is still "0100 ". This also indicates that the FIFO is full.
In Vijay. this article about Asynchronous FIFO structure by nebhrajani describes how to use the Gray code to set the condition of full space, however, it is not clear why the read/write pointer of a FIFO with a depth of 8 must be implemented with a 3 + 1 gray code, while a 3 + 1 gray code can represent a 16-bit depth, the real FIFO is only 8 bits. What is the problem? This issue is explained in Clifford E. Cummings. A three-digit Gray Code represents the depth of eight digits. If one digit is the most MSB, the gray code composed of the other three digits does not represent the new address, that is to say, the gray code 0100 represents 7, while the 1100 represents 7, but the Gray Code enters a cycle with 1 as MSB after a loop with 0 bits in MSB, then we enter a zero-bit MSB loop, and the other three-digit code is still gray code, but this creates a problem. After the 0100 loop is complete, we enter 1000, two of them undergo a transformation instead of one bit. Therefore, the addition of An MSB makes the code in two places: 0100 ~ ~ 0000 two code elements have changed, so this code is not a real Gray code. The added MSB is used to calculate the null full mark. Vijay
A. in the nebhrajani article, the gray code is used to convert the Gray code to the binary code. When the Gray code is converted, an empty full condition is proposed. Only two conversions are performed, while the Clifford E. in Cummings's article, the condition of null full is obtained directly under the condition of Gray code. In fact, the two are the same, but their implementation methods are different.
The second algorithm: style #2 mentioned in Clifford E. Cummings. It divides the FIFO address into four parts. Each part uses the MSB 00, 01, 11, and 10 of the two digits to determine whether the FIFO is going full or going empty (about to be full or empty ). If the number of two MSBs whose write pointer is higher than the value of two MSBs whose read pointer is higher than the value of two MSBs, the FIFO value is "almost full ",
If the number of two MSBs with a write pointer is greater than the value of two MSBs with a read pointer, the FIFO is "almost empty ".
In the third part of Vijay A. nebhrajani's "Asynchronous FIFO structure", we also mentioned a method, that is, the direction signs and thresholds. Set 75% of the FIFO capacity as the upper limit and 25% of the FIFO capacity as the lower limit. When the direction sign exceeds the threshold, the full/empty sign is output, which is similar to style #2 mentioned in Clifford E. Cummings. They all belong to the conservative empty-filled judgment. In fact, the output is empty and full. The FIFO is not necessarily empty/full.
Speaking of this, we have clearly seen that the most important part of the FIFO design is that different algorithms that generate null/full signs generate different FIFO. However, whether it is accurate, empty, full, or conservative, it is to ensure the reliability of the FIFO operation.
========================================================== ========================================================== ==========================================
2. first in, first out, and FIFO)
The first-in-first-out method refers to the method for calculating the inventory cost based on the principle of first-in-first-out. the specific practice of this method is: Calculate the inventory cost based on the unit price at the beginning of the inventory balance, and then calculate the inventory cost based on the unit price of the first inventory, calculate the cost of inventory issuance and inventory settlement by analogy.
The first-in-first-out method is one of the inventory valuation methods. It is priced based on the assumption that the purchased item is obtained first or issued. The final inventory amount calculated using the first-in-first-out method is close to the market price.
The first-in-first-out method is a method of billing the issued inventory based on the assumption that the first-purchased inventory is first issued. In this way, the inventory cost that you first purchase is transferred out before the inventory cost that you later purchase, and the cost of the inventory and the final inventory are determined accordingly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.