Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Array instantiation in verilog

Status
Not open for further replies.

gnoble29

Member level 1
Joined
Jun 30, 2010
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
india
Activity points
1,528
How can I instantiate an array in verilog?

For example, I Have an array a[0:10] in my top module.I want to pass this a[0:10] into another submodule. How it is possible?

I tried like this but showing error.


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
module top
{
input clk,
input rst
};
wire a[0:10];
sub dut( . clk(clk),
           .rst(rst),
           .a(a)
          ); 
endmodule

 
Last edited by a moderator:

You dont even tell us what the error is, how do you expect anyone to help? Just a guess but your a SW type that's used to C syntax and used to using {} instead of (). If that was just a typo then you should have included the sub module and the reported error from whatever tool you used.

Regards
 

My sub module will be as follows



Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
Module sub(input clk, input rst, output reg a[0:10]);
reg i;
always @(posedge clk)
begin
 
for (i=0;i<10;i=i+1)
begin
a[i]=1’b0;
end
 
end
endmodule




My aim is to initialize an array to zero by using submodule. But I am not able to pass the array since it showing the error “Illegal reference to memory: a”.
 
Last edited by a moderator:

because you have this in the code.

.a(a)

you can't pass an array through verilog module ports. In my opinion this is the biggest flaw of Verilog and should have been changed in 2001. Systemverilog supports arrays passed through module ports, but I'm not sure how well supported it is. Modelsim supports it but I'm pretty sure ISE doesn't and Vivado doesn't (I'll admit I haven't tested it on Vivado) not sure about Quartus II. If you stick with Verilog you'll have to perform conversions of the array to a bus then back again.

Sorrry, I didn't notice the array the first time I looked at your code, though I did notice the {} ;-).
 
Thanks ads_ee for your quick reply.
Can you explain little bit about array to bus conversion and its implementation in verilog?
 


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
// a_bus is used to transfer data through the module ports
wire [15:0] a_bus;
wire a_array[0:15];
 
integer i;
for (i=0;i<16;i=i+1) begin
  // convert array values to bus
  a_bus[i] = a_array[i];
  // convert bus back to array
  a_array[i] = a_bus[i]
end



If you have a 2d array:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
wire [16*8-1:0] a_bus;
wire [7:0] a_array[0:15];
 
integer i;
for (i=0;i<16;i=i+1) begin
  // convert array of bytes to bus
  a_bus[8*i +:8] = a_array[i]; //a_array[i][7:0]
  // convert bus back to array of bytes
  a_array[i] = a_bus[8*i +:8];
end

 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top