Use the output of a module inside a class (including task (generator)

In reply to saketa:

Above you have the solution (for Linux). But this requires yyou have the ‘math’ C-lib installed.
You can check this looking for ‘math.h’ in /usr/include or /usr/local/include.

I include here the same code which calculates a few values using your formula. Copy and paste the code to a file and you can run it directly.

module sv_ams_sin_voltage_gen(output real sine_out);
  parameter sampling_time = 5;
  const real pi = 3.1416;
  real time_us, time_s ;
  bit sampling_clock;
  real freq = 20;
  real offset = 2.5;
  real ampl = 2.5;
  real sin_int;
  int count = 0;

  import "DPI-C" pure function real sin(real);

  always sampling_clock = #(sampling_time) ~sampling_clock;

  always @(sampling_clock) begin
    time_us = $time/1000;
    time_s = time_us/1000000;
   end

  assign sine_out = sin_int;

  always @(posedge sampling_clock) begin
    while (count < 5) begin
      freq = freq/2;
      sin_int = offset + (ampl * sin(2*pi*freq));
      $display("freq = %0f, sine_out = %0f", freq, sin_int);
      count++;
    end  
    $stop;
  end

endmodule