Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17268 Discussions

problem with initialising rom and reading data

Altera_Forum
Honored Contributor II
1,241 Views

Hi, 

 

I would like to read binary data from a text file. Perform FIR filtering on the data and store the simulated result values in another text/mif file for further processing in Matlab. I used $readmemb function with verilog code in Quartus II. The following code seems to work. 

 

module test(addr_a,addr_b,clk,q_a,q_b,c); 

 

input [3:0] addr_a,addr_b; 

input clk;  

output [3:0] q_a,q_b; 

output [7:0] c; 

reg [7:0] c; 

reg [3:0] q_a,q_b; 

parameter data_width=4; 

parameter addr_width=4; 

reg[data_width-1:0] rom[2*addr_width-1:0]; 

initial 

begin 

$readmemb("script.txt",rom); 

end 

always@(posedge clk) 

begin 

q_a<=rom[addr_a]; 

q_b<=rom[addr_b]; 

c<=q_a+q_b; 

 

end 

endmodule 

 

But instead if I use the following, my code does not work. 

 

always@(posedge clk) 

begin 

x[0]<=rom[n]; 

n<=n+1; 

temp<=x[0]; 

end 

 

I don't want to use the address as input signal. I would like to use a counter to fetch the subsequent addresses. Could someone suggest me how to do that.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
504 Views

It's not clear to me what you intend with the code that does not work. 

 

However, the code that does work will have to be the basis of what you want. 

Instead of having the address as a input to your module, you can simply generate the address(es) inside it. Something like: 

 

reg addr_a = 4'h0; 

allways @ (posedge clk) 

addr_a <= addr_a + 4'd1; 

 

 

reg addr_a = 4'h2; 

allways @ (posedge clk) 

addr_b <= addr_b + 4'd1;
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

Thank you. Yes, I wanted to know how to access address values without assigning addr as input. 

 

I appreciate your help. 

 

Ambrin
0 Kudos
Reply