slavisha Posted April 17 Report Share Posted April 17 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 Quote Link to comment Share on other sites More sharing options...
Martin Barnasconi Posted April 18 Report Share Posted April 18 sca_lsf::sca_add sub1("sub1"); Due to this, your feedback is not negative. Either change the gain to -2.5 or replace sca_lsf::sca_add by sca_lsf::sca_sub. BTW, it is not a good coding practice to instantiate an adder and call it sub1... (difficult to debug) After this change, it should work Quote Link to comment Share on other sites More sharing options...
slavisha Posted April 18 Author Report Share Posted April 18 Thank you very much for you quick reply. It was a copy/paste matter without changing all that was needed. It does work like a charm now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.