File size: 2,188 Bytes
e3c2ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 08/08/2023 10:01:25 PM
// Design Name: 
// Module Name: fibonacci_bram
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module fibonacci_bram
  (
   
   input	 clk, 
   input	 rst, 
  
   output [31:0] BRAM_addr,
   output	 BRAM_clk,
   output [31:0] BRAM_din,
   input [31:0]	 BRAM_dout,
   output	 BRAM_en,
   output	 BRAM_rst,
   output [3:0]	 BRAM_we
  
   );
   
   localparam	 BRAM_DEPTH = 2048;
   localparam	 SEQ_BITS = 32;
   localparam	 CLK_MHZ = 100;
   
   logic [SEQ_BITS-1:0]	seq_num;
   logic		seq_valid;
   
   logic [31:0]		address;
   logic [31:0]		counter;
   
   logic		get_next_number;
   assign get_next_number = (counter == 1) ? 1 : 0;
   
   localparam		COUNTER_MAX = CLK_MHZ*500000;
   
   fibonacci
     #(
       .SEQ_BITS(SEQ_BITS)
       ) 
   fibonacci_i
     (
      .clk(clk),
      .rst(rst | address == BRAM_DEPTH-1),

      .get_next_number(get_next_number),
      .seq(seq_num),
      .seq_valid(seq_valid)

      );
   
   
   always_ff @(posedge clk) begin
      if (rst) begin
         address <= 0;
         
      end
      else begin
         if (seq_valid) begin
            if (address < BRAM_DEPTH-1) begin
               address <= address + 1;
            end
            else begin
               address <= 0;
               
            end            
         end
      end
   end 
   
   always_ff @(posedge clk) begin
      if (rst) begin
         counter <= 0; 
         
      end
      else begin
         if (counter < COUNTER_MAX-1) begin
            counter <= counter + 1;
         end 
         else begin
            counter <= 0;
         end
      end
   end 
   
   
   assign BRAM_addr = address << 2;
   assign BRAM_clk = clk;
   assign BRAM_din = seq_num;
   assign BRAM_en = 1;
   assign BRAM_rst = rst;
   assign BRAM_we = {4{seq_valid}};
   
   
endmodule