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.

my saturation block made in c-script can't work

0 votes
150 views
I made a saturation bolck with c-script, but it can't work normally compared with the code in the help document, which is the inside code about saturation block in the library.

So can you tell me the difference about  two c-scripts?

appreciation.
asked Jun 29 by fire (63 points)

1 Answer

0 votes
 
Best answer
Your implementation does not behave correctly in minor timesteps. This is not obvious in the test model that you have attached, because the scope will only evaluate the output in major timesteps.

The difference becomes obvious if you feed the output of the C-Scripts to an integrator. With your implementation there is an integration error (the output of the integrator does not become 0 after one period), whereas the reference implementation works correctly (see attached model).
answered Jun 30 by Oliver Schwartz (545 points)
selected Jul 12 by fire
Thanks for you answer, but what I want to know is that what caused  the difference? Is the using of the " if .. switch.." ? after all, two c-scripts are so alike.

best wishes;
They are not alike at all. The correct one specifies the behavior in major and minor steps, the other one only the behavior in major steps. The reason why the behavior in minor steps must be specified is given in the help document that you have cited.
...