0
votes

I've got an initial block which calls a task named power_task as below

initial begin
#10;
power_task;
end

Inside the power task, I've two signals power_a and power_b. Initially, power_a goes low and after a certain skew, power_b goes low. As long as both the signals are low, I need to check the output q. Output q should be low during the time window where power_a and power_b signals are low. Since there are no other signals like a clock, I'm not sure how to continuously monitor q. I've written something like below

task power_task;

#1;
power_a=0;
#5; //skew
power_b=0;
   if (power_a==0 && power_b==0 && q==0) begin
   $display("pass");
   end
#50;
power_b=1;
#5;
power_a=1;
end
endtask

In the above task, the if statements check the value of q only after both signals are low and not during the entire 50 ns time window. Can someone please help?

2

2 Answers

1
votes

You can use a wait statement in a fork block

task power_task;
  begin
    reg fail;
    fail = 0;
    #1 power_a=0;
    #5 power_b=0; //skew
    fork : check_q
      wait (q) fail = 1;
      #50 begin
          if (fail) 
            $display("fail");
          else
            $display("pass");
          disable check_q;
        end
    join
    power_b=1;
    #5 power_a=1;
  end
endtask

Not exactly sure why you need to check that power_a/b are still 0 unless there is some other code that could change it.

1
votes

Use an always block outside of the task, a control signal (check_en) and a flag variable (pass):

reg pass = 1;
reg check_en = 0;

always @(check_en, q) begin
    if (check_en && q) begin
        $display("fail");
        pass = 0;
    end
end

initial begin
    #10;
    power_task();
    if (pass) $display("pass");
end

task power_task;
    #1;
    power_a=0;
    #5; //skew
    power_b=0;
    check_en = 1;
    #50;
    check_en = 0;
    power_b=1;
    #5;
    power_a=1;
endtask

The always block will continuously monitor the q signal for any changes when enabled.