• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. SystemVerilog task() output signal does not have correct...

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 65
  • Views 10684
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SystemVerilog task() output signal does not have correct value

HoWei
HoWei over 2 years ago

I started recently with SystemVerilog (lets say Verilog in general) and I am trying to create a "task()".

I am using the Virtuoso/Xcelium AMS environment and want to generate a pulse with configurable length.

I am using 2 internal signals in the module "mysignal" and "mysignal2".

"mysignal" is directly assigned with a value inside the task().

"mysignal2" shall get the value from the task() output signal assignment.

Here my code:

`timescale 1 ns / 1 ns

module clk_gen_SV_stim (GEN_ADCCLK, GEN_CLKGEN_ADC_RATE,
GEN_CLKGEN_BYPASS, GEN_CLKGEN_DIV_F, GEN_CLKGEN_EN
);

output logic GEN_CLKGEN_DIV_F;
output logic GEN_CLKGEN_ADC_RATE;
output logic GEN_CLKGEN_EN = 1'b0;
output logic GEN_ADCCLK;
output logic GEN_CLKGEN_BYPASS;
logic mysignal = 1'b0;
logic mysignal2 = 1'b0;

// task
task pulse( input time length, output intsig);
mysignal = 1'b1;
intsig = 1'b1;
$display("intsig =%b at %t",intsig, $time() );
#length
mysignal = 1'b0;
intsig = 1'b0;
//GEN_CLKGEN_EN = 1'b0;
$display("intsig =%b at %t",intsig, $time() );
endtask : pulse

//start with state 0
initial begin
#5ns
pulse(.length(20ns), .intsig(mysignal2)); //call with argument mapping
#25ns
pulse(20ns, mysignal2); //call with positional argument
end

endmodule

The problem is, that "mysignal2" never changes its value.

But internally in the task() the local "intsig" is assigned properly:

Does anyone know why, and whats wrong with the "mysignal2" assignment ?

Ar do I have wrong expectations on "mysignal2" behaviour ?

  • Cancel
Parents
  • StephenH
    StephenH over 2 years ago

    A task's output arguments are copied by value at the end of the task's execution. If you want the changes to happen instantly, make them "ref" instead of "output".

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • HoWei
    HoWei over 2 years ago in reply to StephenH

    I tried and receive a compile error:

    I am not sure I have done that correctly, as i do not (yet) know the difference between ref and output.

    I am wondering when using "output" at what time the assignement to "mysignal2" will happen ?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • HoWei
    HoWei over 2 years ago in reply to StephenH

    I tried and receive a compile error:

    I am not sure I have done that correctly, as i do not (yet) know the difference between ref and output.

    I am wondering when using "output" at what time the assignement to "mysignal2" will happen ?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • StephenH
    StephenH over 2 years ago in reply to HoWei

    Add the "automatic" qualifier to the task:
    task automatic pulse (input time length, ref intsig);
    BTW, one would typically use a clocking event rather that an actual time, unless your design is an asynchronous one. Clocked stimulus is more efficient to simulate.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • HoWei
    HoWei over 2 years ago in reply to HoWei

    Great THX - now it behaves as I expected !

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information