Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

readmemb / Quartus 14.1 / MIF files?

Hello - I have what I fear is a dumb question, but I can't seem to figure out where it's gone wrong. I'm trying to implement the often re-created VGA text design. I grabbed a MIF file of a font set from an example, and tried to implement it using the Single Port ROM or Single Port RAM templates in Quartus (tried both). While the MIF file seems to match the described syntax in the help file from Quartus - and if I edit it in Quartus, it gives me a nicely formatted grid of sane data that looks like it's interpreting it fine.

However, when I do the $readmemb() to load the data, when I go to elaborate I get a syntax error on the first char of the first line (DEPTH = 2048;"

Error (10079): Verilog HDL syntax error at sysfont.mif(1): illegal character in binary number

Error (10170): Verilog HDL syntax error at sysfont.mif(1) near text D

Error (12152): Can't elaborate user hierarchy "single_port_ram_with_init:char_ram"

Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 3 errors, 11 warnings

Error: Peak virtual memory: 725 megabytes

Error: Processing ended: Wed Apr 08 10:57:01 2015

Error: Elapsed time: 00:00:12

Error: Total CPU time (on all processors): 00:00:28

I can't quite figure out how it's gone wrong, since I'm using pretty much a text book implementation of the template straight from the Quartus docs. I suspected the MIF file syntax had changed, but their description of the MIF file seems to match the file spot on. If I look at file properties in the files tab, it tells me it's a memory initialization file. I'm left scratching my head here and hoping someone can point out the error of my ways.

Cheers

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can't use $readmemb to read a MIF file. You have to remove all the directives and leave just the binary portion of the file. Also watch out for any gaps in the address range.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ah, thank you - is there a way to read a MIF into a template based ROM/RAM rather than an IP based altsyncram?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can always write Verilog to open the MIF file and parse it, extract the data and store it into the memory area used by the altsyncram or an inferred RAM/ROM. The same is possible using VPI/PLI. There might be code for this available somewhere already.

    However, the above is some amount of work.

    Why don't you use your editor and copy the MIF file into a different file and remove all but the binary digits. Or you can just extract the binary part using sed or similar:

    sed -n 's/.*:*\(*\);.*/\1/p' data.mif

    The best and most common solution is to modify the program which generates the MIF file to generate a binary or hex ascii file as well. This requires the source of the generating program of course.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks - I actually solved it, I should also reply for others who might run into it.

    You can indeed initialize with a MIF file, but it requires a synthesis attribute instead, and isn't mentioned in the template description. I found the helpfile here: http://quartushelp.altera.com/14.0/mergedprojects/hdl/vlog/vlog_file_dir_ram_init.htm

    --- Quote Start ---

    Note: You can also specify the synthesis attribute of an inferred RAM, whose implementation you want to control, in a comment following the Variable Declaration. In the comment, the synthesis keyword must precede the synthesis attribute, as shown in the following code:

    reg [7:0] mem[0:255] /* synthesis ram_init_file = " my_init_file.mif" */;

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I thought this was for simulation. My reply applies to simulation. For synthesis you can use the directive you specified. If you generate the ram using qmegawiz/qsys you can give a path to the mif file in the gui.