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.

How to define global variable in verilog?

Status
Not open for further replies.

saurabhs

Newbie level 4
Joined
Aug 6, 2009
Messages
5
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
Varanasi
Activity points
1,307
Hi all
I wanna define global variable in verilog so that i can use them in different module.
How it can be done.
Thanks in advance.
 

Re: Global Variable in Verilog

With verilog, pretty much everything's "global". You can use hierarchical reference to access any variable in any module.

For example:

module glb_var_mod; // define all global vars in this module
reg glb_x = 1'b1;
endmodule

module dut;
glb_var_mod.glb_x = 1'b0; // change value of a global var
endmodule

- Hung
 
Re: Global Variable in Verilog

skyfaye said:
With verilog, pretty much everything's "global". You can use hierarchical reference to access any variable in any module.

For example:

module glb_var_mod; // define all global vars in this module
reg glb_x = 1'b1;
endmodule

module dut;
glb_var_mod.glb_x = 1'b0; // change value of a global var
endmodule

- Hung

Very insightful indeed. Thanks!!

Curious to know can we do the same in VHDL too?
 
Re: Global Variable in Verilog

With verilog, pretty much everything's "global". You can use hierarchical reference to access any variable in any module.

For example:

module glb_var_mod; // define all global vars in this module
reg glb_x = 1'b1;
endmodule

module dut;
glb_var_mod.glb_x = 1'b0; // change value of a global var
endmodule

- Hung

i did so but this error was the result:
Error :(on line 7 ) : near "=": syntax error, unexpected '=', expecting IDENTIFIER or TYPE_IDENTIFIER
what is this?

i did something like this another time on another project , and there was an error "Undersolved reference to 'glb_var_mod"
and what is this?!
 

Re: Global Variable in Verilog

Hi
Maybe you got this error because you didn't use 'always' or 'initial' blocks. Assigning values to reg must be in one of these blocks depending on situation.
For example:
module glb_var_mod; // define all global vars in this module
initial
reg glb_x = 1'b1;
endmodule
 

Re: Global Variable in Verilog

Just a note that global variables are not synthesizable, and in general, not a good programming practice in any language.
If instead you really need a global value, use a `define in Verilog or a parameter declared in a package in SystemVerilog.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top