Jump to content

Oscillator modeling with SystemC-AMS


Recommended Posts

Hello everyone,

I'm trying to model a simple harmonic oscillator with SystemC-AMS by using sca_lsf primitives.

There's no non-linearities in my description. However, I don't get what I expect.

I put everything in the main file.

#include <systemc-ams>

int sc_main(int argc, char* argv[])
{

    sc_core::sc_set_time_resolution(1.0, sc_core::SC_FS);

    sca_lsf::sca_signal in;

    double init_value = 0.0;
    double offset = 0.0;
    double amplitude = 0.0;
    double frequency = 1500;
    double phase = 0.0;
    sca_core::sca_time delay = sca_core::sca_time(0, sc_core::SC_MS);

    sca_lsf::sca_source src("src", init_value, offset, amplitude,
            frequency, phase,delay ); // step of 1 unit at t=10ms
    src.y(in);
    src.set_timestep(1, sc_core::SC_MS);

    
    sca_lsf::sca_signal y_dot1_signal;
    sca_lsf::sca_signal y_dot2_signal;
    sca_lsf::sca_signal y_gain1_signal;
    sca_lsf::sca_signal y_signal;

    sca_lsf::sca_integ  integ1("integ1",1.0,1.0);
    sca_lsf::sca_integ  integ2("integ2",1.0,0.0);
    sca_lsf::sca_gain   gain1("gain1",2.5);
    sca_lsf::sca_add    sub1("sub1");
    

    integ1.x(y_dot2_signal);
    integ1.y(y_dot1_signal);

    integ2.x(y_dot1_signal);
    integ2.y(y_signal);


    gain1.x(y_signal);
    gain1.y(y_gain1_signal);


    sub1.x1(in);
    sub1.x2(y_gain1_signal);
    sub1.y(y_dot2_signal);

    // tracing
    sca_util::sca_trace_file* atf = sca_util::sca_create_tabular_trace_file("oscillator");
    
    sca_util::sca_trace(atf, y_dot2_signal, "dot2");
    sca_util::sca_trace(atf, y_dot1_signal, "dot1");
    sca_util::sca_trace(atf, y_signal, "y");

    std::cout << "Simulation started..." << std::endl;

    sc_core::sc_start(10.0, sc_core::SC_SEC);

    std::cout << "Simulation finished." << std::endl;

    sca_util::sca_close_tabular_trace_file(atf);

    return 0;
  }

The code compiles without any error. But I don't get what I expected. I should have a sinusoidal trace in y_signal, but I don't get it at all.

First of all, is it possible to have a right behavior with SystemC-AMS of this simple harmonic oscillator? Simulink gives me what I expect.

Thank you in advance for your feedback.

Slavisha

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...