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 inputs assigned right before task call - Race condition

Status
Not open for further replies.

pigtwo

Member level 4
Joined
Jul 16, 2015
Messages
70
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,771
Hello all,

I have a fairly simple question about tasks with inputs. I've been working on this problem where I assign some values to a register then use those values as the input to a task. I've found that when I call the task the values it takes is the previous value of the input. I created an example to quickly show what I'm saying. In the below module I assign 'a' a value then give 'a' to a task which gives it to 'b'.

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module task_test( );
 
    reg clk;
    reg[7:0] a, b;
 
    initial begin
        forever #5 clk = ~clk;  
    end
 
    initial begin
        clk = 0;
        a = 0;
        b = 0;
        
        #10
        while(1) begin
            a = a + 1;
            give(a,b);
        end
    end
 
    task give;
    input[7:0] x;
    output[7:0] y;
        begin
        y = x;  
        @(posedge clk);
        end 
    endtask
 
endmodule



Below is the simulation output:
sim.PNG

As you can see the task seems to get the previous value of 'a'. I've found the solution to this by adding a delay before I call the task but I'm curious about why this happens. Is it the simulator reording which statements are called first or is there something I don't understand about calling tasks? This seems strange to me because I'm using blocking assignments so the 'a = a + 1;' should have to finish before going to the task so I'm not sure why the task is getting the previous value. I must be missing something here.

Thank you!
 
Last edited:

You are missing the fact that the value of y does not get copied to auntil the task exits, which is one clock cycle later.
 
  • Like
Reactions: pigtwo

    pigtwo

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top