MDG1
Member
Hello all,
I'm stuck on some code I want to write. The idea is to have a formula that accepts a DINT tag setpoint, compares it to the previous value, and uses the ABS difference between them to create an increment value so that the Current_Value = New_Value over 30 seconds.
IF Current_Value <> New_Value THEN
Difference:= Current_Value - New_Value;
Absolute_Difference:= ABS(Difference);
Ramp_Value:= Absolute_Difference / 30;
Ramp_Timer.PRE:= 1000;
Ramp_Timer.TimerEnable:= 1;
Ramp_Timer.Reset:= Ramp_Timer.DN;
IF Ramp_Timer.DN AND New_Speed > Current_Speed THEN
Current_Value:= Current_Value + Ramp_Value;
ELSIF Ramp_Timer.DN AND New_Speed < Current_Speed THEN
Current_Value:= Current_Value - Ramp_Value;
END_IF;
END_IF;
This almost does what I want but my problem is the Absolute_Difference changes with every increment, when I don't want it to. Is there a way I can 'capture' a constant initial value for the Absolute_Difference? Nothing I've tried has worked, but it feels like I'm missing something simple here, any ideas would be appreciated.
Thank you.
I'm stuck on some code I want to write. The idea is to have a formula that accepts a DINT tag setpoint, compares it to the previous value, and uses the ABS difference between them to create an increment value so that the Current_Value = New_Value over 30 seconds.
IF Current_Value <> New_Value THEN
Difference:= Current_Value - New_Value;
Absolute_Difference:= ABS(Difference);
Ramp_Value:= Absolute_Difference / 30;
Ramp_Timer.PRE:= 1000;
Ramp_Timer.TimerEnable:= 1;
Ramp_Timer.Reset:= Ramp_Timer.DN;
IF Ramp_Timer.DN AND New_Speed > Current_Speed THEN
Current_Value:= Current_Value + Ramp_Value;
ELSIF Ramp_Timer.DN AND New_Speed < Current_Speed THEN
Current_Value:= Current_Value - Ramp_Value;
END_IF;
END_IF;
This almost does what I want but my problem is the Absolute_Difference changes with every increment, when I don't want it to. Is there a way I can 'capture' a constant initial value for the Absolute_Difference? Nothing I've tried has worked, but it feels like I'm missing something simple here, any ideas would be appreciated.
Thank you.