Professional Documents
Culture Documents
synchronous FIFO mean read operation and write operation asserted depends on clk.
condition :
1.read and write pointer should be one bit higher than read and write
address.
Empty is asserted your write pointer and read pointer in same position ( When the
read pointer reaches the write pointer, the FIFO is empty).
Full is asserted your write pointer one step behind read pointer.(If the write pointer
catches up with the read pointer, the FIFO is full)
module FIFO
#(
parameter DWIDTH=8,
parameter AWIDTH=2
input clk,
input reset_i,
input w_en_i,
input r_en_i,
input [DWIDTH-1:0]wdata_i,
output full,
output empty
);
localparam depth=2**AWIDTH;
reg [DWIDTH-1:0]mem[0:depth-1];
begin
if(reset_i)
begin
rptr<=0;
wptr<=0;
waddr<=0;
raddr<=0;
rdata_o<=0;
end
else
begin
begin
end
end
end
end
endmodule
Correct code
1. module FIFO_memory(clk,reset,din,read,write,dout,empty,full);
2.
3. input clk;
4. input reset;
5. input [15:0]din; //16-bit data input
6. input read;
7. input write;
8.
9. output [15:0]dout; //16-bit data output
10. output empty; //flag to indicate that the memory is
empty
11. output full; //flag to indicate that the memory is full
12.
13. parameter DEPTH=3, MAX_COUNT=3'b111;
14. //DEPTH is number of bits, 3 bits thus 2^3=8 memory locations and
MAX_COUNT is the last memory location.
15.
16. reg [15:0]dout;
17. reg empty;
18. reg full;
19.
20. /*head is write_pointer and tail is read_pointer*/
21.
22. reg [(DEPTH-1):0]tail;
23. // tail(3bits) defines memory pointer location for reading
instructions(000 or 001....111)
24.
25. reg [(DEPTH-1):0]head;
26. // head(3bits) defines memory pointer location for writing
instructions(000 or 001....111)
27.
28. reg [(DEPTH-1):0]count;
29. // 3 bits count register[000(0),001(1),010(2),....,111(7)]
30.
31. reg [15:0]fifo_mem[0:MAX_COUNT];
32. // fifo memory is having 16 bits data and 8 memory locations
33.
34. reg sr_read_write_empty; // 1 bit register
flag
35.
36. ///////// WHEN BOTH READING AND WRITING BUT FIFO IS EMPTY ////////
37.
38. always @(posedge clk)
39. begin
40. if(reset==1)
41. //reset is pressed