Search code examples
verilogsystem-verilogquartus

$readmemh syntax error for .mif file in Verilog HDL Intel Quartus Prime


I am trying to read a .mif file and this is the error I am getting -

Error (10170): Verilog HDL syntax error at sine3_test1.MIF near text: p. Check for and fix any syntax errors that appear immediately before or at the specified keyword. The Intel FPGA Knowledge Database contains many articles with specific details on how to resolve this error. Visit the Knowledge Database at https://www.altera.com/support/support-resources/knowledge-base/search.html and search for this specific error message number.

The error seems to be in first line. My MIF file has 8-bit data width and 256 words depth.

memory address = UNS (unisgned decimal)
memory data = hexadecimal

enter image description here

My source code is the following:

reg [7:0]memory[0:255];
begin
    $readmemh("sine3_test1.MIF",memory);
end

I removed white spaces and added a few missing memory block numbers. Currently, I have it stored in my project folder (although not part of the Quartus project).


Solution

  • The format of the input file is incorrect for $readmemh. The $readmemh system task expects a file to just have numbers in hexadecimal format, not words like DEPTH, or address/data pairs like 0:78;.

    You can not directly read the mif file using $readmemh. You need to create another file with just the data in it, like sine3_test1.hex:

    78
    7a
    7d
    

    Then use:

    $readmemh("sine3_test1.hex", memory);
    

    For the complete specification of the input file format, refer to IEEE Std 1800-2017, section 21.4 Loading memory array data from a file. The format does support address information, but it does not seem necessary in this case.


    You could read the mif file using $fopen (and related functions) instead of $readmemh, but that would be a lot more work.