0
\$\begingroup\$
module tb();
 reg [7:0] a = 1;
 reg [7:0] b;
 initial begin
 AddTask(a, b);
 $display("%d", b);
 end
 task AddTask;
 input [7:0] a;
 output reg[7:0] b;
 begin
 b = a + 1;
 end
 endtask
endmodule

The above code is compiled and simulated correctly; But I want to cut the task "AddTask" from the module "tb.v" and place it in a separate module "AddModule.v"(that is in a separate file) for clear coding. When I do this, modelsim can compile it but can't simulate it and give the error: " Unresolved reference to 'AddTask' ". Although I include AddModule.v, it can't recognize AddTask. Can you help me please, what's the wrong ?

module tb;
 reg [7:0] a = 1;
 reg [7:0] b;
 `include "AddModule.v"
 initial begin
 AddTask(a, b);
 $display("%d", b);
 end
 endmodule

AddTask in a separate file:

module AddModule;
 task AddTask;
 input [7:0] a;
 output reg[7:0] b;
 begin
 b = a + 1;
 end
 endtask
endmodule 
asked Mar 15, 2016 at 8:04
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

The problem is probably the nested module declaration. This is not allowed in Verilog, however is possible in SystemVerilog.
Try to declare only the task AddModule() in a separate file without a surounding module declaration. This file can then be included within the scope of another module, e.g. within your testbench (as in your example code).

answered Mar 15, 2016 at 8:21
\$\endgroup\$
2
  • \$\begingroup\$ Thank's a lot @damage, I declared only AddTask in a separated file 'AddTask.v' without any module declaration and it worked ! \$\endgroup\$ Commented Mar 15, 2016 at 8:34
  • \$\begingroup\$ Also,when I synthesized it in Quartus, at first it didn't synthesize, but when I changed the postfix of files from .v (Verilog) to .sv (System Verilog), it synthesized correctly in Quartus as well as simulated in Modelsim ! \$\endgroup\$ Commented Mar 15, 2016 at 9:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.