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+gammau_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!