Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Honored Contributor I
2,349 Views

header file in verilog / a better way to define global constants

Hello, I am working on a verilog project and I need to use some constants parameters in almost all of my modules. So, instead of defining them for every module, I was thinking it makes more sense to have a separate file with all the parameters and constants and include it in each module. However, I am not sure how I can do that. I tried defining them (i.e. defies.v) in a separate file and including it in my module (just like header in C/C++) with `include "defines.v". However compiler is not accepting that and I think, I am doing something wrong.  

 

I would appreciate any suggestion in this regard.
0 Kudos
4 Replies
Highlighted
Honored Contributor I
150 Views

That is the correct way. 

You may be doing something wrong..
0 Kudos
Highlighted
Honored Contributor I
150 Views

Showing the syntax error message would help. 

 

If you can use SystemVerilog, the putting them in a package is the way to go.
0 Kudos
Highlighted
Honored Contributor I
150 Views

Thanks for the input. I am kinda swamped with some other projects now. I will definitely look into it. I might be doing something wrong.

0 Kudos
Highlighted
Honored Contributor I
150 Views

Keep in mind that if your header file is just a collection of constants it is not a compile-able unit. For example, if defines.v is: 

 

localparam FOO = 6; localparam BAR = "BAR";  

 

This code needs to be scoped inside a module. So, if you are passing defines.v in a list of files to your compiler, that is your problem. Instead, you'll need to add the path to defines.v in your Verilog include path. 

 

As an aside, I (and at least a few other people I've seen online) use .vh as the file extension for Verilog files which will be `included. This allows you to see which files define modules and which files define constants, functions, etc. Also, some tools will search a given path for files to compile based on module instantiation. This convention prevents such modes of operation from stumbling on code which can't be compiled on its own.
0 Kudos