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.

Determination od signal start time with a c-script

0 votes
Dear all,

I have an imput impuls and I need to write a c-script code that returs the time at which the impuls changes it's state from 0 to 1 and vice versa? Does anyone have some suggestion how to do this or is there any intern PLECS command in the c-script I could use for this purpose?


Thany You very much for Your help and precious time,


asked Jun 2, 2020 by Nardi (16 points)

You might be able to do this with primitive PLECS blocks as there is a "Clock" block that generates the simulation time and you can do edge detection to determine when the impulse changes, but it depends on what you want to do with the time value? Does this occur only once/twice, or many times during your simulation? Otherwise, there is a "CurrentTime" macro built into the PLECS C-Script block that you can take advantage of and output or print the simulation time using that.


Dear Kris,

Thank You very much for Your answer.

I'm actually trying to write a mean value calculation algorithm on my own (instead of using PLECS' block Periodic Average) which starts to calulate the mean value (which will be the output of the script during the next sample period) from the time the impulse changes from 0 to 1. So the time when the input signal changes it's state must be internally saved beacuse the next discrete time when my output will change will be (t + n*Ts) where t is the time at which the input signal changed from 0 to 1, Ts is the sample period, and n is the number of discrete time intervals passed so far.
Sure, then definitely use the C-Script block for this. The Periodic Average block is already implemented via a C-Script if you look under the mask, but you may be aware of that.

Please log in or register to answer this question.