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.

How to use variable in generate loop

Status
Not open for further replies.

ismailov-e

Member level 1
Joined
Jan 26, 2015
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
295
Hi everybody!
Can anybody help me to understand how to use variable outside of generate-endgenerate loop.
I found some explanation. For example:

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
generate
for(i=0; i<SIZE; i=i+1)
begin:addbit
wire n1,n2,n3; //internal nets
xor g1 (n1 ,a[i] ,b[i]);
xor g2 (sum[i] ,n1 ,c[i]);
and g3 (n2 ,a[i] ,b[i]);
and g4 (n3 ,n1 ,c[i]);
or g5 (c[i+1] ,n2 ,n3);
end
endgenerate



In the preceding example, each generated net will have a unique name, and each generated
primitive instance will have a unique instance name. The name comprises the name of the block
within the for-loop, plus the value of the genvar variable used as the loop index. The names of
the generated n1 nets are:
addbit[0].n1
addbit[1].n1
addbit[2].n1
addbit[3].n1

I can't use for example prereg <= addbit[0].n1.
How can i use instance outside generate loop?
The relative generation i saw in bram generation in AXI4-Full.
But the register have the same name but multiplied.
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,805
Helped
1,809
Reputation
3,628
Reaction score
1,768
Trophy points
1,393
Location
USA
Activity points
58,918
n1 is local to the for loop if you want to use it both inside and outside the loop then you should make it local to the module, this is similar to software variable scoping rules.
 

dave_59

Advanced Member level 3
Joined
Dec 15, 2011
Messages
816
Helped
361
Reputation
726
Reaction score
354
Trophy points
1,353
Location
Fremont, CA, USA
Activity points
6,561
But you can refer to prereg <= addbit[0].n1; outside of the generate block. But what you cannot do is refer to addbit[j],n1 where j is a variable. That is because addbit is not an array; it is a block scope. The generate loop creates a unique scope name for each iteration of the loop and appends [NN] to the block name. Because of conditional generates and defparam statements, the contents of each block can be different - unlike a regular array where each element has an identical type.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top