Storing array in FPGA

1.7k views Asked by At

I am trying to implement a simple multiplier. I have a text file, from in which there are two columns. I am multiplying column 1 to column 2. Here is code in Verilog:

module File_read(
input clk
);

reg [21:0] captured_data[0:10];
reg [21:0] a[0:8];
reg [21:0] b[0:8];
reg [43:0] product[0:5];
`define NULL 0 
integer n=0;
integer i=0;
initial 
$readmemh("abc.txt",captured_data);
always @(posedge clk) begin
   product[i]<=captured_data[n]*captured_data[n+1];
   n<=n+2;
   i<=i+1;
end
endmodule

I have Xilinx SpartanĀ®-6 LX45 FPGA board. And it offers 128M bit ddr2 ram and 16Mbyte x4 SPI Flash for configuration & data storage.

Now I want to store my file into FPGA board into memory. So how can I do this? Do I have to use IP core to access memory or by any other source?

P.S: This is my first time, I am storing anything on FPGA.

Regards!

Awais

1

There are 1 answers

1
Paebbels On

First of all don't use DDR or Flash memory, unless you really need them. Your FPGA has plenty of BlockRAMs to store several thousand arguments for your multiplier.

One easy way is to instantiate 2 BlockRAMs and load them at compile time with data from a file. Xilinx offers tools like data2mem to achieve this.

Alternatively, you can use Ethernet or a UART connection to send the test data to your design.

Edit 1 - How to instantiate BlockRAM

Solution 1: A generic VHDL description.

  type T_RAM is array(LINES - 1 downto 0) of std_logic_vector(BITS-1 downto 0);
  signal ram : T_RAM;
begin
  process (Clock)
  begin
    if rising_edge(Clock) then
      if (WriteEnable = '1') then
        ram(to_integer(WriteAddress)) <= d;
      end if;

      q <= ram(to_integer(ReadAddress));
    end if;
  end process;

Solution 2: The IPCore generator has a wizard to create BlockRAMs and assign external files.

Solution 3: Manually instantiate a BlockRAM macro. Each FPGA family comes with a HDL library guide of supported macros. For example the Virtex-5 has a RAMB36 macro on page 311.

The usage of BlockRAMs with data2MEM and *.bmm (BlockRAM memory map) files is described here.