Jump to content
  • 0

how to read an csv file in verilog code


jean

Question

hello everyone, i will need help. I would like to know if you have any idea how to store a ROM in fpga from an csv file. I have an CSV file contain hexadecimal data. I want to have a ROM in my design to read data from the external csv file. Thanks
 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Whenever you create a RAM or ROM using FPGA vendor's IP you are given the option of providing an initialization file. The vendor has it's own format such as MIF. Don't use a csv format use the vendor's format. Writing a small Python script or C program to automate the process of converting an array of data to the MIF format isn't very difficult.

Link to comment
Share on other sites

Here's a snippet of my OCTAVE code used to create parts of the PhasorToy project that I posted in the Digilent Project Vault:

clc;
format long;
fixed_point_format(true);

# We want a sin lookup table covering 0 to (Pi/2) -1/(2^depth)-1)
bits  = 18;
depth = 2048;

rad_step  = pi/(2*depth)
deg_step = (rad_step/(pi/2))*90
max_rad = rad_step*(depth-1)
maxdeg = (max_rad/(pi/2))*90

for i=1:depth
  sintab(i) = sin(rad_step*(i-1));
  costab(i) = cos(rad_step*(i-1));
end


# Create a scaled std_logic .coe file
# Uncomment to write coe file
# A better to do this would be to save sintab to a file
# and write a separate function script to do the coe file writing....
S = floor(sintab*2^bits);
figure (3);
plot(S);
fid = fopen('sintab90.coe', 'w+');
fprintf(fid, 'memory_initialization_radix = 2;\n');
fprintf(fid, 'memory_initialization_vector = \n');
for i=1:depth-1
  fprintf(fid, dec2bin(S(i),bits));
  fprintf(fid, ',\n');
end
fprintf(fid, dec2bin(S(depth),bits));
fclose(fid);

Not all FPGA vendor data formats are suitable for simulation, so taking the time to learn how to insert data into your source code is well worth the effort.

 

Link to comment
Share on other sites

17 hours ago, zygot said:

Whenever you create a RAM or ROM using FPGA vendor's IP you are given the option of providing an initialization file. The vendor has it's own format such as MIF. Don't use a csv format use the vendor's format. Writing a small Python script or C program to automate the process of converting an array of data to the MIF format isn't very difficult.


thank you sir @zygot for your reply. I even tried to use a .mem or .text file containing hex data it works in the simulation without any problem . Unfortunately, after the synthesis and the generation of the bitstream, I wanted to do the debug to check its operation, a priori it does not read it or it had a problem. I am using  ZCU111 ultrascale

reg [15:0] ROM [0:4095];
reg [15:0] ROM2 [0:4095];
 
initial begin
$readmemh("I_data.mem", test_memory);
$readmemh("Q_data.mem", test_memory);
end
 

Link to comment
Share on other sites

If there's a path from the ROMs in the PL to the PS via an AXI bus then you can read the ROM contents; otherwise you can't. Such a path is a waste of a lot of PL resources. If your ROMs were dual port ram then that's different. You'd have to have a good reason for expending PL resources for that kind of architecture.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...