Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is $readmem synthesizable in Verilog?

I am trying to implement a microcontroller on an FPGA, and I need to give it a ROM for its program. If I use $readmemb, will that be correctly synthesized to a ROM? If not, what is the standard way to do this?

like image 639
user526035 Avatar asked Dec 01 '10 04:12

user526035


People also ask

Is initial block synthesizable in Verilog?

An initial block is not synthesizable and cannot be converted into a hardware schematic with digital elements. The initial blocks do not have more purpose than to be used in simulations. These blocks are primarily used to initialize variables and drive design ports with specific values.

What does Readmemh do in Verilog?

It reads the file into the memory structure. Words are white space separated (space, tab, return, etc). The difference between $readmemb and $readmemh is that, memb reads in binary, and memh reads in hex.


1 Answers

It depends on the synthesis tool whether or not $readmemb is synthesizable.

Altera's Recommended HDL Coding Styles guide includes example 10-31 (page 10-38), which demonstrates a ROM inferred from $readmemb (reproduced below):

module dual_port_rom (
   input [(addr_width-1):0] addr_a, addr_b,
   input clk, 
   output reg [(data_width-1):0] q_a, q_b
);
   parameter data_width = 8;
   parameter addr_width = 8;
   reg [data_width-1:0] rom[2**addr_width-1:0];
   initial // Read the memory contents in the file
           // dual_port_rom_init.txt. 
   begin
      $readmemb("dual_port_rom_init.txt", rom);
   end
   always @ (posedge clk)
   begin
      q_a <= rom[addr_a];
      q_b <= rom[addr_b];
   end
endmodule

Similarly, Xilinx's XST User Guide states that:

The $readmemb and $readmemh system tasks can be used to initialize block memories. For more information, see:

Initializing RAM From an External File Coding Examples

Use $readmemb for binary and $readmemh for hexadecimal representation. To avoid the possible difference between XST and simulator behavior, Xilinx® recommends that you use index parameters in these system tasks. See the following coding example.

$readmemb("rams_20c.data",ram, 0, 7);

like image 146
mrkj Avatar answered Oct 07 '22 20:10

mrkj