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.

Verilog task and fuction

Status
Not open for further replies.

viresh128

Newbie level 3
Joined
Aug 7, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Long Beach
Activity points
1,301
Hi, I am trying to learn task and function in verilog. Here's what i tried-
code-



Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module add_task(a,b,y, clk);
input [3:0] a, b;
output [4:0] y;
input clk;
reg[4:0] y;
 
 always @(posedge clk)
 begin 
 add(a,b,y);
 end
 
 task add;
  input [3:0] in1, in2;
  output [4:0] out;
  reg [4:0]out;
   begin 
   out<=in1+in2; 
   end
 endtask
 
endmodule






and the TESTBENCH-


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module tb_add_task;
 
    reg [3:0] a=0;
    reg [3:0] b=0;
    reg clk=0;
    wire [4:0] y;
    
    add_task uut (.a(a), .b(b), .y(y), .clk(clk));
   always #5 clk=~clk;
    
    always @(negedge clk) 
        begin
        a = $random;
        b = $random;
        end
endmodule



THE PROBLEM IS THAT I AM GETTING A DELAYED OUTPUT, APPROX 10ns. COULD SOMEBODY PLS EXPLAIN WHY IS IT SO? FOR THE FIRST 15ns THE "Y" SIGNAL IS xxxx, ITS ONLY AFTER THIS THE ADDITION VALUES ARE BEING DISPLAYED. :sad::sad: PLEASE HELP.
 
Last edited by a moderator:

The problem with your task is that you are using a non-blocking assignment to assign the output argument, and then immediately leaving the task. The value of out has not been updated at that point, and it is the old value of out that gets copied to y. The next time you call the task, the value of out has been updated, and that it what gets copied out.

I suggest that you do not use a task unless it will consume time by having a delay control inside it (which renders it unsynthesizable for design by most tools)
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top