Professional Documents
Culture Documents
Basic Fundamentals of FIFO Design
Basic Fundamentals of FIFO Design
Basic Fundamentals of FIFO Design
FIFO:
1-clock FIFO
and
2-clock FIFO
2
Producer Consumer
Producer Consumer
FIFO
3
FIFO
Delinks the producer and the
consumer
PRODUCER CONSUMER
• Writer • Reader
• Deposits Data into the FIFO. • Reads Data from the FIFO.
5
Data Plumbing:
Producer Consumer
(Sending (Receiving
Block) Block)
Data Flow
Matched flow schedules require no buffering
Producer Consumer
(Sending (Receiving
Block) Block)
Holding
Tank
Capacitor on circuit boards
Initially
⮚ The FIFO has two pointers to denote the locations to write and read:
▪ Write Pointer (WP): The location pointed to by the WP is where producer deposits data.
▪ Read Pointer (RP): The location pointed to by the RP is from where consumer reads data.
⮚ Initially the FIFO is empty. Both WP and RP point to location 0 of the FIFO.
8
7
6
PRODUCER 5 CONSUMER
4
3
2
1
WP 0 RP
7
6
PRODUCER 5 CONSUMER
4
3
2
WP 1
0 FILLED RP
10
7
6
PRODUCER CONSUMER
5
4
3
WP 2
1 FILLED
0 FILLED RP
11
7
6
PRODUCER 5 CONSUMER
4
WP 3
2 FILLED
1 FILLED
0 FILLED RP
12
7
6
PRODUCER 5 CONSUMER
WP 4
3 FILLED
2 FILLED
1 FILLED
0 FILLED RP
13
7
6
WP 5 CONSUMER
4 FILLED
3 FILLED
PRODUCER
2 FILLED
1 FILLED
0 FILLED RP
7
6
WP 5 CONSUMER
4 FILLED
3 FILLED
PRODUCER
2 FILLED RP
1
0
16
7
WP 6
5 FILLED CONSUMER
4 FILLED
3 FILLED
PRODUCER
2 FILLED RP
1
0
17
WP 7
6 FILLED
5 FILLED CONSUMER
4 FILLED
3 FILLED
PRODUCER
2 FILLED RP
1
0
6 5
7 4
0 3
RP 1 2
WP
0 3 0 3
1 2 1 2
RP RP
WP
0 3 0 3
1 2 1 2
RP RP
WP
20
0, 1, 2, 3, 4, 5, 6, 7
EMPTY FULL
(If it was seen running (If it was seen running
almost empty most recently) almost full most recently)
22
MOD SUBTRACTOR
3 10 10 10 -0 -1 -1 -1 10
4 0 0 2 4 0 0 2
-1 2 3 4 -1 2 3 4 10 10 10
2 7 6 8 2 7 6 8 -1 -1 -1 -1 10
4 0 0 2
SUMMARY
An ordinary n-bit subtractor with -7 2 3 4
its borrow output ignored is a
Mod-2n subtractor. 6 7 6 8
24
3 10 10 10 -0 -1 -1 -1 10
4 0 0 2 4 0 0 2
-1 2 3 4 -1 2 3 4 10 10 10
2 7 6 8 2 7 6 8 -1 -1 -1 -1 10
4 0 0 2
SUMMARY
An ordinary n-bit subtractor with -7 2 3 4
it’s borrow output ignored is a
Mod-2n subtractor. 6 7 6 8
25
FIFO PIN-OUT
WEN REN
Write Enable (from the Producer) Read Enable (from the Consumer)
FULL EMPTY
Full status info (to the Producer) Empty status (to the Consumer)
RD (READ DATA)
WD (WRITE DATA)
FIFO
Since the WP and RP are part of the FIFO, the FIFO PIN-OUT does not change if we
change the FIFO depth from 8 locations to 8K locations!
WEN REN
Write Enable (from the Producer) Read Enable (from the Consumer)
FULL EMPTY
Full status info (to the Producer) Empty status (to the Consumer)
RD (READ DATA)
WD (WRITE DATA)
FIFO
WP RP
DETAILED DESIGN OF A
SINGLE-CLOCK 8X4 FIFO
We illustrate a detailed design using schematic components .
We use here
-- an 8x4 register array for the FIFO storage,
-- two 3-bit counters for the WP and RP pointers, and
-- a 3-bit subtractor.
Synchronous FIFO (Common clock for WRITE & READ) 29
FULL EMPTY
WA2
RA2 RENQ
WA2 RA2
WENQ WA1 REN
WEN WA1 RA1
RA1
WA0 RA0
WP WA0 RA0
EN RP EN
WA2 RA2
QA WENQ RENQ QA
WA1 WEN REN RA1
QB
E QB
E
WA0 RA0
QC WD3 RD3 QC
CLK WD3 RD3 CLK CLK
CLK
WD2 RD2
CLR~ WD2 RD2 CLR~
CLK
Vdd
FULL WA[2:0]
RAF AF
J Q DIFF2
CLK DIFF1 RAF
B2
C0
B0
A2
A0
A1
B1
RAE AE
K Q~
CLR~
C3
S2
S0
S1
DIFF2
RESET~ DIFF1 RAE
EMPTY DIFF[2:0]
DIFF
30
FIFO Storage
Register Array acting as a Dual Port Memory
(a write-only (WO) port and a read-only (RO) port)
WA RA
WA2
WA2 RA2 RA2
WA1 DUAL PORT RAM RA1
WA1 MEMORY RA1
WA0 RA0
WA0 RA0
WENQ RENQ
WEN REN
FULL EMPTY
RENQ
WENQ REN
WEN
WP
EN RP EN
WA2 RA2
QA QA
WA1 RA1
QB
E QB
E
WA0 RA0
QC QC
CLK CLK CLK
CLK
CLR~ CLR~
RESET~ RESET~
32
Computing Depth
A ripple carry adder turned into a subtractor
X-Y = X + Y’ + 1
WA2 WA1 WA0 - RA2 RA1 RA0
RP
RA[2:0]
WP Vdd
WA[2:0]
B2
C0
B0
A2
A0
B1
A1
S2
S0
S1
Mod-8 subtractor
DIFF[2:0]
DIFF
33
R_bar
36
N-bit pointers
vs
(N+1)-bit pointers
38
⮚ Now suppose we deliberately use a 4-bit pointer for the WP and a 4-bit
pointer for the RP. Then the 4-bit subtraction (WP-RP)mod_16, which
can potentially produce 16 values (0-15), will produce all the 9 legal
values (0-8) and will never produce the 7 illegal values (9 through 15).
There is no ambiguity to be resolved now!
39
RENQ
WEN WENQ REN
We provided the producer the FULL information. So, when he says "write" (by
activating WEN), he must have checked to see that we are not running FULL.
If so, why are we double-checking Full and EMPTY as shown above before
activating WENQ and RENQ?
41
WEN REN
FULL EMPTY
WEN REN
FULL EMPTY
Avoiding LONG critical path (round-trip) by breaking it into two one-way trips 44
WEN REN
FULL EMPTY
WEN REN
WENQ
RENQ
RETRY RETRY
FULL EMPTY
45
WCLK RCLK
(Write Clock) 2-clock (Read Clock)
Read Clock
Write Clock
An asynchronous FIFO =
Domain
Domain
A two-Clock FIFO
47
WP RP
WPS RPS
WPSS RPSS
Depth = WP - RPSS
Depth = WPSS - RP
To: 100
Can potentially be any value from 0
(000) to 7 (111) due to metastability
of the flip-flop.
49
GRAY CODE:
Gray WP 0
0
0
Counter 1
WPS
1
1
0
0
1
1 1
1
Since only 1-bit changes at most in WP, the WPSS will 0
0
either be the old WP or the new WP and will never
be an absurd value!
50
WP RP
WPS RPS
WPSS RPSS
Depth = WP - RPSS
Depth = WPSS - RP
So, he will delay consuming the data and this is safe! As long as the
consumer does not consume from an empty FIFO, it is safe!
51
RP_Bin[3:0]
Counter
Counter
Counter
Counter
Gray to
WP_Gray WP_Gray_S WP_SS_Bin
Binary
WP_Gray_SS
Gray
4 4 4 4 4
Bin
Bin
4
WCLK WCLK RCLK RCLK RCLK
RENQ
Counter
Counter
RP_Gray
Gray to
RP_SS_Bin RP_Gray_S
Binary
RP_Gray_SS
4 4
Gray
4 4
The junior engineer changed all [3:0] on the previous page to [2:0] as shown
on the next slide and is about to add on each side one set of "JK FF and
related circuitry" (Similar to the single clock FIFO).
2 [3:0] 2 [3:0] WD 2 [3:0] 2 [3:0]
WD WP_SS_Bin RP_Bin
WP_Bin RP_SS_Bin WP_Bin[2:0]
WP
3 8-location
WENQ Register Array
A B WENQ A B
WCLK
WCLK 3 4-bit Bin Subtractor
3 4-bit Bin Subtractor
A-B A-B
REG
ARRAY
RD depth_rd
depth_wr RD
FULL RP_Bin[2:0] EMPTY
=1000 3 RP =0000
WENQ WENQ RENQ
Counter
2 2
Counter
Counter
Counter
Gray to
WP_Gray WP_Gray_S WP_SS_Bin
Binary
WP_Gray_SS
WP_Bin[3:0] RP_Bin[3:0]
Gray
43 4 3 4 3 4 3
Bin
Bin
4 43
3
WCLK WCLK RCLK RCLK RCLK
RENQ
JK
JK
FF
FF
Counter
Counter
RP_Gray
Gray to
RP_Gray_SS
etc.
4 3 4 3
Gray
4 3 4 3
The senior engineer told him not to do that as that would create a
deadlock!
DON’T
DO
THIS
EMPTY (if most recently it was almost empty)
WP – RP = 0
WCLK
RCLK
WCLK
RCLK
WCLK
7
6
5
FULL= 0 EMPTY= 1
4
ALMOST_FULL= 0 3 ALMOST_EMPTY= 1
2
WP 1
0 FILLED RP
59
RCLK
WCLK
7
6
5
FULL= 0 EMPTY= 1
4
ALMOST_FULL= 0 3 ALMOST_EMPTY= 1
WP 2
1 FILLED
0 FILLED RP
60
RCLK
WCLK
7
6
5
FULL= 0 EMPTY= 1
4
ALMOST_FULL= 0 WP 3 ALMOST_EMPTY= 1
2 FILLED
1 FILLED
0 FILLED RP
61
RCLK
WCLK
7
6
5
FULL= 0 EMPTY= 1
WP 4
ALMOST_FULL= 0 3 FILLED ALMOST_EMPTY= 1
2 FILLED
1 FILLED
0 FILLED RP
62
RCLK
WCLK
7
6
WP 5
FULL= 0 EMPTY= 1
4 FILLED
ALMOST_FULL= 0 3 FILLED ALMOST_EMPTY= 1
2 FILLED
1 FILLED
0 FILLED RP
63
RCLK
WCLK
⮚ ALMOST_FULL=1 as WP-RP=6
7
WP 6
5 FILLED
FULL= 0 EMPTY= 1
4 FILLED
ALMOST_FULL= 1 3 FILLED ALMOST_EMPTY= 1
2 FILLED
1 FILLED
0 FILLED RP
64
RCLK
WCLK
WP 7
6 FILLED
5 FILLED
FULL= 0 EMPTY= 1
4 FILLED
ALMOST_FULL= 1 3 FILLED ALMOST_EMPTY= 1
2 FILLED
1 FILLED
0 FILLED RP
65
RCLK
WCLK
WCLK