File tree Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ Alexander Yazdani
44Synchronous and Asynchronous FIFO Implementations
55*/
66
7+
8+ // Synchronous Parameterized FIFO
79module fifo_synch #(
810 parameter DATA_WIDTH = 8 ,
911 parameter DEPTH = 16
@@ -35,8 +37,7 @@ always @(posedge clk) begin
3537 memory[write_ptr] <= d_in;
3638 write_ptr <= (write_ptr + 1 ) % DEPTH;
3739 count <= count + 1 ;
38- end
39- if (read_en && ! empty) begin
40+ end else if (read_en && ! empty) begin
4041 d_out <= memory[read_ptr];
4142 read_ptr <= (read_ptr + 1 ) % DEPTH;
4243 count <= count - 1 ;
4748assign full = (count == DEPTH);
4849assign empty = (count == 0 );
4950
51+ endmodule
52+
53+
54+ // Synchronous FIFO of Depth 1
55+ module fifo_synch_1 #(parameter DATA_WIDTH = 8 ) (
56+ input clk,
57+ input reset,
58+ input [DATA_WIDTH- 1 :0 ] d_in,
59+ input read_en,
60+ input write_en,
61+ output reg [DATA_WIDTH- 1 :0 ] d_out,
62+ output full,
63+ output empty
64+ );
65+
66+ reg [DATA_WIDTH- 1 :0 ] memory;
67+ reg counter;
68+
69+ always @(posedge clk) begin
70+ if (reset) begin
71+ d_out <= 0 ;
72+ memory <= 0 ;
73+ counter <= 0 ;
74+ end else begin
75+ if (write_en && ! full) begin
76+ memory <= d_in;
77+ counter <= 1 ;
78+ end else if (read_en && ! empty) begin
79+ d_out <= memory;
80+ counter <= 0 ;
81+ end
82+ end
83+ end
84+
85+ assign full = counter;
86+ assign empty = ! counter;
87+
5088endmodule
You can’t perform that action at this time.
0 commit comments