Electrical – how to import data from MATLAB to ISE XILINX testbench

MATLABvhdlxilinx

For a project, i need to take sine samples in MATLAB and somehow i need to call it in Xilinx ISE testbench, so that i can use them for further operations. Please tell me how to do it?

Best Answer

You want to create input stimulus in Matlab and use them in your Xilinx ISE simulator. First, you need to put your Matlab data into a file. The easiest way is just to write the data to file line by line. Example:

% Make a 16-bit sin wave
data = floor(2^15*sin(0:0.001:10));

%open the file for writing
file = fopen('my_data.txt','w');
for i=1:length(data)
    fprintf(file,'%d\n', data(i));
end
fclose(file);

Now you need to use that data in VHDL. I have mostly got examples in Verilog, but in VHDL you can use something like this:

How to read a text file using vhdl

Use file_open to open the file:

file_open (file_pointer, "my_data.txt", READ_MODE);

And readline and read to read a line and get its contents:

readline (file_pointer, line_num); 
read (line_num, line_content);

You'd need to cast your number into whatever type you need it as and generate the valids/surrounding signals accordingly.