UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer rganesaa
Observer
5,573 Views
Registered: ‎09-18-2016

How to use `define statement

Jump to solution

Dear Sir/Madam,

 

I am trying to use `define statement in system Verilog to define global constants and functions. I am using Vivado 2015.2 64 bit edition. After writing a lengthy program, I found while the program works well with parameter replacing parameter with `define macros does not work. Hence I have written the following small program to check my understanding of `define macro.

 

Following is the source code:

// Module Name: NoC_Example_include
//`define PI 3.1214

module NoC_Example_include(input o1);
wire [31:0] o1;
endmodule

 

Following is its test bench:

`timescale 1ns / 1ps
`define PI 3.1214
module tb_NoC_Example_include();
reg [31:0] o1;
NoC_Example_include  N1(.o1(o1));
initial
begin
o1=PI;
$monitor ("o1 = %d",o1);
end
endmodule

 

I expected the program to print out o1 = 3.1214. The program does not run with error message: PI is not declared.

 

Moving PI from test bench to main module where it should be anyway does not help either.

 

Any help in diagnosing why the program is not giving expected results will be deeply appreciated.

 

Thanking you,

 

Yours sincerely,

R. Ganesan.

0 Kudos
1 Solution

Accepted Solutions
Teacher muzaffer
Teacher
9,295 Views
Registered: ‎03-31-2012

Re: How to use `define statement

Jump to solution
you need to say
o1 = `PI;
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
4 Replies
Teacher muzaffer
Teacher
9,296 Views
Registered: ‎03-31-2012

Re: How to use `define statement

Jump to solution
you need to say
o1 = `PI;
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Observer rganesaa
Observer
5,556 Views
Registered: ‎09-18-2016

Re: How to use `define statement

Jump to solution
Thank you muzaffer.

You are always available and your replies are on dot.

Apart from missing 'PI it required PI to be defined in both main module and test bench.

0 Kudos
Historian
Historian
5,517 Views
Registered: ‎01-23-2009

Re: How to use `define statement

Jump to solution

I just want to point out that

 

a) PI is not equal to 3.1214

b) assigning a non-integer number to a reg is pretty much meaningless...

 

Avrum

0 Kudos
Observer rganesaa
Observer
5,394 Views
Registered: ‎09-18-2016

Re: How to use `define statement

Jump to solution
I agree.

Oversight. PI 3.1412

The idea was to check how to use 'define statement, yet your comments are valid.

Thanks.
0 Kudos