In Verilog, I'm trying to use $readmemb to read .txt file but it only loads xxxxx (dont cares) on memory

always verilog
for loop in verilog
verilog assign
verilog tutorial
verilog code
verilog conditional operator
verilog concatenation
verilog case

I need to load a memory with some data originally in binary. I read that $readmemb can be use for this, and there is even a method to make synthesizable.

So, I created another module named RAM_IN (which is not the testbench module) and "connected" to the top module.

Before knowing about $readmemb, I was using this code:

initial
begin
in_ram [0] <= 32'b11111111_000000000000000000000000; 
in_ram [1] <= 32'b10010111_000000000000000000000000;
in_ram [2] <= 32'b00110110_000000000000000000000000;
in_ram [3] <= 32'b00111110_000000000000000000000000;
in_ram [4] <= 32'b00111111_000000000000000000000000;
in_ram [5] <= 32'b00111110_000000000000000000000000;
end

But its too tiring for me to write 100 numbers like this, so implemented $readmemb like this:

module RAM_IN (pix_val, indx);


input [0:5] indx;
output [31:0] pix_val;


reg [31:0] pix_val;
reg [31:0] in_ram [0:4];

always @ (indx)
pix_val = in_ram [indx];

initial
begin
$readmemb("in_ram.txt", in_ram);
end

The purpose of reading this file, is to initially load 100 binary values (wich simulate the pixel intensity of a 10x10 image) one by one into the top module (which is going to process and spit a result later...)

I created a .txt file which looks content exactly like this

11111111000000000000000000000000
10010111000000000000000000000000
00110110000000000000000000000000
00111110000000000000000000000000
00111111000000000000000000000000 

When I simulate, modelsim show me memory filled with xxxxxxxxxxxxxxxxx (dont care), it looks like isn't loading anything to the memory.

I don't know what I'm doing wrong. Likely isnt the dispossition of the numbers in the .txt file. Maybe is because I'm intending to load file with $readmemb in another module which is not testbench?

PD: The simulation of this process of filling the memory I'm doing only for practical purpose, the final intention is to put the Top module design into a full SoC which I think I will do using QSYS. But I'm very new at this so I'm still studying. Any help will be much appreciated!!!

Are you sure you run simulation?

Your code with TB:

module RAM_IN (pix_val, indx);

input [0:5] indx;
output [31:0] pix_val;

reg [31:0] pix_val;
reg [31:0] in_ram [0:4];

always @ (indx)
  pix_val = in_ram [indx];

initial
begin
  $readmemb("in_ram.txt", in_ram);
end

endmodule

module tb;
reg [0:5] indx; 
wire [31:0] pix_val;

RAM_IN ram_in(pix_val, indx);

initial
begin
  indx = 'b0;
  $monitor ($realtime, " Read Data = %0b" ,pix_val);
  repeat(4)
  begin
    #10;
    indx = indx + 1'd1;
  end
  $finish;
end
endmodule

With same in_ram.txt.

Questasim:

QuestaSim-64 qverilog 10.4 Compiler 2014.12 Dec  2 2014
Start time: 18:27:01 on May 10,2016
qverilog me.v 
-- Compiling module RAM_IN
-- Compiling module tb

Top level modules:
    tb
Reading pref.tcl

# 10.4

# vsim -lib work tb -c -do "run -all; quit -f" -appendlog -l qverilog.log -vopt 
# ** Note: (vsim-3812) Design is being optimized...
# //  Questa Sim-64
# //  Version 10.4 linux_x86_64 Dec  2 2014
# //
# //  Copyright 1991-2014 Mentor Graphics Corporation
# //  All Rights Reserved.
# //
# //  THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION
# //  WHICH IS THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS
# //  LICENSORS AND IS SUBJECT TO LICENSE TERMS.
# //  THIS DOCUMENT CONTAINS TRADE SECRETS AND COMMERCIAL OR FINANCIAL
# //  INFORMATION THAT ARE PRIVILEGED, CONFIDENTIAL, AND EXEMPT FROM
# //  DISCLOSURE UNDER THE FREEDOM OF INFORMATION ACT, 5 U.S.C. SECTION 552.
# //  FURTHERMORE, THIS INFORMATION IS PROHIBITED FROM DISCLOSURE UNDER
# //  THE TRADE SECRETS ACT, 18 U.S.C. SECTION 1905.
# //
# Loading work.tb(fast)
# run -all
# 0 Read Data = 11111111000000000000000000000000
# 10 Read Data = 10010111000000000000000000000000
# 20 Read Data = 110110000000000000000000000000
# 30 Read Data = 111110000000000000000000000000
# ** Note: $finish    : me.v(34)
#    Time: 40 ns  Iteration: 0  Instance: /tb
# End time: 18:27:02 on May 10,2016, Elapsed time: 0:00:01
# Errors: 0, Warnings: 0

And Simulation:

Appendix A. Verilog Code of Design Examples, Verilog Code. 797 assign acc = msbs; initial begin. $readmemh("sine256x8.txt", rom); end always @ (posedge clk) begin sin <= rom[msbs]; end endmodule. Verilog-2001 is the version of Verilog supported by the majority of commercial EDA software packages. Verilog 2005. Not to be confused with SystemVerilog, Verilog 2005 (IEEE Standard 1364-2005) consists of minor corrections, spec clarifications, and a few new language features (such as the uwire keyword).

I already fixed this. The problem is that modelsim couldn't find the .txt file, I don't know where could be the predetermined location for such of files, but looking in internet, I found that I can declare in the Ram module, the exact path like this

initial
begin
$readmemb("C:/altera/15.0/Prueba5/in_ram.txt", in_ram);
end

Now modelsim is loading the correct data. Thanks everybody.

[PDF] Verilog 1 - Fundamentals, Verilog 1 - Fundamentals. 6.375 Complex Digital Systems. Arvind. FA. FA. FA. FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2;. A procedure in Verilog corresponds to the same context that a function in C programming does. It is a particular block of statements called procedural statements. If we compare it with the high-level language, it comes out to be that the function arguments and parameters in a language like C, Python are the same as that of the procedural

Pasting a copy of the initialization data file (e.g. "in_ram.txt") into the project's ..\simulation\modelsim\ directory also resolved this issue for me.

Verilog, A for loop is the most widely used loop in software, but it is primarily used to replicate hardware logic in Verilog. The idea behind a for loop is to iterate a set of � Verilog deals with the design of digital electronic circuits.. Describing a complex circuit in terms of gates (gate-level modeling) is a tedious task.Thus, we use a higher level of abstraction.

Verilog for Loop, and synthesis vendors Verilog HDL Reference. Manuals. In addition to the OVI Language Reference Manual, for further examples and explanation of the Verilog � Verilog Data types Verilog Scalar/Vector Verilog Arrays Ch#3: Building Blocks Verilog Module Verilog Port Verilog Module Instantiations Verilog assign statements Verilog assign examples Verilog Operators Verilog always block Combo Logic with always Sequential Logic with always Verilog initial block Verilog in a nutshell Verilog generate Verilog

[PDF] Quick Reference Verilog� HDL, Attributes were added in. Verilog-2001. • An attribute can appear as a prefix to a declaration, module items, statements, or port connections. • An attribute� A for loop is the most widely used loop in software, but it is primarily used to replicate hardware logic in Verilog. The idea behind a for loop is to iterate a set of statements given within the loop as long as the given condition is true. This is very similar to the while loop, but is used more in a context where an

[PDF] Verilog-2001 Quick Reference Guide, Verilog is not only a specification language which tells the CAD system what hardware is suppose to do, it also includes a complete simulation environment. A . Verilog model or testbench can read text and binary files to load memories, Files can also be written. the file I/O functions is based on the C stdio routines, such as fopen, fgetc,

Comments
  • It looks alright to me and it works alright, too. http://www.edaplayground.com/x/5kxx
  • @hexafraction I would have said numbering a memory like this is pretty conventional: reg [31:0] in_ram [0:4];.
  • friend, you are taking the $readmemb file as the top module and applying a test bench to it. The problem is that my $readmemb file is not the top module, it is controlled by the register "indx" and the test bench goes to the top module. For some reason, if I load one by one it works, but if use the $readmemb instruction it loads xxxxxxxxxxxxxxxx. Do you think if I post the whole code, can give me a hand on this? Thanks