Files
BasicComponents/BasicComponents/Components/Controller/POUs/FB_RampGenerator.TcPOU
m.heisig cf9501ea01 Changed all components to use HAL structs as in and outs
- All components now use HAL structs as inputs and outputs
- Restructured library folders
- FB_Axis_PTP now implements the execute pattern with E_CmdResult
- Bumped version number to 2.0.0
2026-03-19 12:17:10 +01:00

91 lines
2.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
<POU Name="FB_RampGenerator" Id="{61136989-8ee2-49fa-af2b-1b579e85353f}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK FB_RampGenerator
VAR_INPUT
xEnable : BOOL; // Output equals input
xHold : BOOL := FALSE; // Freeze current value
rTarget : REAL; // Targetvalue
rRiseRate : REAL; // Positive rise rate in units/s
rFallRate : REAL; // Negative rise rate in units/s (only positive values)
END_VAR
VAR_OUTPUT
rOut : REAL; // Generated ramp output
xBusy : BOOL; // TRUE until target value reached
END_VAR
VAR
_xFirstCycle : BOOL := TRUE;
_rT : REAL := 0.0; // Task cycle time
_rDiff : REAL := 0.0;
_rStep : REAL := 0.0;
// Output buffer
_rOut : REAL;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[IF _xFirstCycle THEN
_xFirstCycle := FALSE;
// Get cycle time
_rT := F_GetTaskCycleTime();
END_IF
// If not enabled output equals input
IF (NOT xEnable) THEN
_rOut := rTarget;
rOut := _rOut;
xBusy := FALSE;
RETURN;
END_IF
// Freezes the ramp at the current value
IF xHold THEN
xBusy := (ABS(rTarget - _rOut) > 0.0);
RETURN;
END_IF
// Calculate diff to target
_rDiff := rTarget - _rOut;
// Check if we need to ramp up or down
IF _rDiff > 0 THEN
// Ramp up
_rStep := ABS(rRiseRate) * _rT;
// Clamp to target value
IF _rStep > _rDiff THEN
_rOut := rTarget;
ELSE
_rOut := _rOut + _rStep;
END_IF
ELSIF _rDiff < 0 THEN
// Ramp down
_rStep := ABS(rFallRate) * _rT;
// Clamp to target value
IF _rStep > ABS(_rDiff) THEN
_rOut := rTarget;
ELSE
_rOut := _rOut - _rStep;
END_IF
END_IF
// Handle busy flag
xBusy := (ABS(rTarget - _rOut) > 0.0);
// Copy internals to outputs
rOut := _rOut;]]></ST>
</Implementation>
<Method Name="M_SetStart" Id="{f7326067-d944-49e6-a19b-12711f9b3f19}">
<Declaration><![CDATA[METHOD M_SetStart
VAR_INPUT
rStartValue : REAL;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[_rOut := rStartValue;
rOut := _rOut;]]></ST>
</Implementation>
</Method>
</POU>
</TcPlcObject>