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.

Change C-script's parameters during simulation. It doesn't work...

0 votes
2,317 views

Hi everyone!

I have built a generic discrete transfer function in a C-script.

This is the code:

Code declaration:

#define u Input(0)

#define y Output(0)

#define a ParamRealData(0,0)

#define b ParamRealData(1,0)

#define c ParamRealData(2,0)

#define alpha ParamRealData(3,0)

#define beta ParamRealData(4,0)

#define gamma ParamRealData(5,0)

#define K ParamRealData(6,0)

#define reset_value ParamRealData(7,0)

#define UL Input(1)

#define LL Input(2)

#define reset Input(3)

double u_prev_1,u_prev_2,y_prev_1,y_prev_2,y_unsat;

Start function:

y=0;

y_prev_1=0;

y_prev_2=0;

u_prev_1=0;

u_prev_2=0;

Output function:

if (reset==0)

{

y_unsat=-(b/a)*y_prev_1-(c/a)*y_prev_2+(K/a)*((alpha)*u+(beta)*u_prev_1+gamma*u_prev_2);

if (y_unsat < LL)

y = LL;

else if (y_unsat > UL)

y = UL;

else

y=y_unsat;

}

else

{

y=(reset_value/100)*LL;

}

Output(1)=K;

Update function:

y_prev_2=y_prev_1;

u_prev_2=u_prev_1;

y_prev_1=y;

u_prev_1=u;

-------------------------------------------

Basically, it converts a 2nd order discrete transfer function in a Linear difference equation.

I write the parameters in the block mask and the C-script has a discrete sample time. (500e-6s)

I would like to change the gain K during simulation but I noticed that it doesn't change at all!

Is it possible? How can I solve ?

Thank you everyone!

asked Oct 6, 2018 by nikilito (113 points)

1 Answer

+1 vote
 
Best answer
The parameters of a C-Script are not tunable, i.e. cannot be changed during a simulation. You can tell this by the fact that the parameter fields in the dialog are greyed out while a simulation is running.

If you want to change a variable during a simulation, you need to feed it into the C-Script as an input signal.
answered Oct 9, 2018 by Wolfgang Hammer (401 points)
selected Oct 9, 2018 by nikilito
Thank you very much!

I'm solving in the way you suggest.. It works!
...