Using " `define X" directive; Verilog syntax quest

The favorite HDL language in North America

Using " `define X" directive; Verilog syntax quest

Postby Yassen » Tue Apr 20, 2010 9:18 am

Hi guys,

I have implemented a Verilog code that normally works at high clock speed. My design consists of multiple modules, separated in multiple files. For simulation purposes I need to lower the clock a bit, so I am using the compiler directive
Code: Select all
`define
like this:
Code: Select all
`define DEBUG
and then checking
Code: Select all
      `ifdef DEBUG
         // some code
      `else
         // some code
      `endif

The code works fine so far, but I have to go through many files and to change DEBUG / NO_DEBUG every time when I need to simulate.
My question is: Is it possible to declare the `define directive only in the top level module and then to access it from some inner modules? I have tried this, but unsuccessfully. And one more thing: I know that Verilog can read the <include ...> statement. Can you give me some example of using <include ...>. Is it suitable for synthesis? Preferably, I am using Verilog 2001 and 2005.

Thank you
Yassen
Yassen
 
Posts: 70
Joined: Thu Jun 08, 2006 6:46 pm

Postby NickH » Tue Apr 20, 2010 10:11 am

[Well traditionally, Verilog would concatenate all source files together, so if you `define something the first file, it would be seen everywhere. However, this antique behaviour can't be relied upon!]

Yes, you can `include a file from every source file, just put
Code: Select all
`include "definitions.vh"

at the top of each Verilog source file, and make a file "definitions.vh" in the same directory, containing:
Code: Select all
`define DEBUG

If you're using an IDE you may need to register the new file with the IDE as a "header file". Then just comment and uncomment the `define, to change behaviour. It should work for synthesis.

Or, depending on what tools you're using, there may be a way to specify some `defines on the command line, or in some top-level project configuration. It might already define certain symbols automatically, for simulation or synthesis?

Regards,

Nick
NickH
 
Posts: 88
Joined: Tue Sep 02, 2008 1:53 pm

Postby Yassen » Tue Apr 20, 2010 7:09 pm

Hi, Nick!

Thank you for your help. I have just tried this and it worked perfect. There's always something good to learn :)
I am using Xilinx ISE - it does not accept the '.vh' file extension, but obviously any extension works, so now I am happy :)
And, yes, I've heard about that Verilog "tradition" that you have mentioned, but with my design tool and Verilog version the tradition is not what it is.

Yassen
Yassen
 
Posts: 70
Joined: Thu Jun 08, 2006 6:46 pm


Return to Verilog HDL