What are FIFOs?
FIFO (First-In First Out) is a type of memory, literally translated as "first-in first-out".
Put out the old one first. Isn't that a matter of course?
At convenience stores and supermarkets, put the products with the closest expiry date (listed first) in front.
You make it easy to take, don't you? This is also the idea of FIFO!
Operation of FIFOs
So I decided to check the operation of the FIFO.
FIFO is registered as a Quartus II Megafunction, so use it.
In Quartus II 14.0, you can select pre-registered Megafunctions by selecting IP Catalog from the Tools menu.
(For versions prior to Quartus II 13.1, select MegaWizard Plug-In Manager from the Tools menu)
This time, I made a FIFO with a minimum configuration, 4 bits × 4 words, and a single clock. (Figure 1)
Among the input signals, write is a signal that, when 1, enables writing new data into the FIFO.
When read is 1, it is a signal that makes it possible to read the oldest data written in the FIFO and reflect it in the output q.
The behavior is represented in Figure 2.
Also, the output signal is full = 1 when 4 words are filled, and empty = 1 is output when there is nothing.
question
At this point, I had three questions:
1. What value is printed when read = 0?
2. What happens to the data inside if I write when full = 1?
3. What value will be output when read = 1 , write = 1 with empty = 1 ?
Let's simulate and verify these three with ModelSim!
Question 1: What value is printed when read = 0?
What kind of value is output when the FIFO data is not read?
Is it uncertain?
Should it be 0000?
Or is the value that was read one before output?
inspection:
Write 4 words of data ( write = 1 ), read only 2 words ( write = 0 and read = 1 ),
Then look at the value of the output q when you stop reading ( read = 0 ).
result:
Now it looks like Figure 3.
Looking at the value of the output q, "0010" written in the 2nd word is output as it is in the 3rd clock.
Result is
"The same value as before stopping reading (set read = 0) is output"
was.
I found that when read = 0, the previous value is output as is.
Question 2: What happens to the data inside when writing when full = 1?
When 4 words have already been written ( full = 1 ), what happens to the data inside when only writing is performed?
overwritten?
Is the oldest data erased and new data written?
Or is each bit ORed together?
inspection:
Since we are using a 4-word FIFO this time, write 5 words, which is one more ( write = 1 ), and after writing
Read ( write = 0 and read = 1 ) five times. Now, how is the 5th word output?
result:
Now it looks like Figure 4.
You can see that "0110" written in the 5th word is not output by checking the output q.
Result is
"not written"
was.
It turns out that the data inside the FIFO is not overwritten until full = 0.
Question 3: What value is printed when read = 1, write = 1 with empty = 1?
If there is no data in the FIFO, what will be output if writing and reading are performed at the same time?
Indefinite?
0000?
Or is it the same value as last time?
inspection:
Look at the output when you write 2 words ( write = 1 ), read 2 words ( read = 1 ), then read and write at the same time ( write = 1 and read = 1 ).
result:
Shown in Figure 5.
Instead of the written data "1000" being output immediately, the previous value "0101" is being output.
So the result is
"same output as last time"
was.
In the single-clock FIFO created this time, when empty = 1, it turns out that the written data is sent after one clock and then output.
A single-clock FIFO requires 1 clock for writing, 1 clock for reading, and 1 clock for data output.
Data is output with a delay of 1 clock after "read".
At the end
I found FIFOs to be a type of memory because they can also store data.
Although it is a "first-in first-out" concept, it has the characteristic of not overwriting the data inside, and outputting the same value as the previous time when reading is stopped.
When processing the data obtained from the purpose such as keeping the data input order and not overwriting in practice,
It seems that it is used as a primary save buffer so that processing does not become heavy.
From this verification, I understand well why it is used for that purpose. "FIFO", which sounds mysterious, was actually a disciplined memory that kept order.
today's point
FIFO is a memory that holds data until a read request comes and keeps the order of input data.
If the data inside is full, no new input data is included.
If the data inside is empty and reading and writing are performed at the same time, 3 clocks of "writing", "reading" and "output" are required.
Data is output one clock after "read".