Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

In C-script, is the time symbol"t" treat as the system clock time or only S-cript block time

0 votes
For example, If we have a if function to let the csript block generates y=sin(2*pi*t) only during simulation time 0.3~0.5sec (Assume we have a simulation time for 1sec). In this 0.3~0.5 sec, the function will be generated. However, what is "t" in function represents, is it "0.3~0.5" or "0~0.2" (Since the C-script only runs for 0.2 sec).
asked Sep 11, 2020 by BenjaminZZZ (14 points)

1 Answer

0 votes

There is a macro "CurrentTime" built into the C-Script engine that you can call in your logic and will get the current simulation time, with respect to t=0. So, 0.3 to 0.5 seconds in your case.


answered Sep 11, 2020 by Kris Eberle (1,511 points)
Hi, what if I want to use 0~0.2 instead of 0.3~0.5? Which is that I dont want to use the system clock, I want to use a independent C-script block which runs its own clock.
Would you be able to post a simple version of your model and script?

You could code a counter (if using fixed sample time) or integrator that would act as a "local clock" within the C-Script.  For example, if you want to have a one-shot timer.  Or you could reference simulation time, but use a time delay or store the time of the input event to calculate a time difference.