<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
  <POU Name="FB_MotorMockup" Id="{2caa045e-1cb0-4e4b-ae71-f86aa7b0d7a4}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_MotorMockup
VAR_INPUT
	// Enable motor
	xEnable AT%I* : BOOL;
	
	// Motor setpoint
	iSetpoint AT %I* : INT;
END_VAR
VAR_OUTPUT
	// Motor circuit breaker ok
	{attribute 'hide'}
	xMCBOk AT %Q* : BOOL;
	
	// Repair switch ok
	{attribute 'hide'}
	xRepairSwitchOk AT %Q* : BOOL;
	
	// Motor speed feedback
	iMotorSpeedFeedback AT %Q* : INT;
END_VAR
VAR
	_iInternalSetpoint : INT;
	
	_fbRampGenerator : FB_RampGenerator;
	
	{attribute 'hide'}
	_fbValveAnalogInput : FB_AnalogInput('');
	
	_stAnalogScaling : ST_ANALOG_IO_CONFIG := (iAIMax := 32767, iAIMin := 0, rPVMax := 100, rPVMin := 0);
	_stAnalogEWConfig : ST_ANALOG_EW_LEVELS;
	_stAnalogEWDelays : ST_ANALOG_EW_DELAYS;
	
	{attribute 'hide'}
	_fbValveAnalogOutput : FB_AnalogOutput('');
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[// Set MCB and repair switch ok
xMCBOk := TRUE;
xRepairSwitchok := TRUE;

// Turn motor off if enable signal is not set
IF xEnable THEN
	_iInternalSetpoint := iSetpoint;
ELSE
	iSetpoint := 0;
END_IF

// Calculate setpoint 0% - 100%
// from analog value
_fbValveAnalogInput(
	iAnalogValue:= iSetpoint, 
	stScalingConfig:= _stAnalogScaling, 
	stEWConfig:= _stAnalogEWConfig, 
	stEWDelayConfig:= _stAnalogEWDelays, 
	xUnderrange:= FALSE, 
	xOverrange:= FALSE, 
	xErrorCard:= FALSE, 
	xReleaseErrors:= FALSE, 
	xReleaseLimitErrors:= FALSE, 
	xReleaseHardwareErrors:= FALSE, 
	xConfirmAlarms:= , 
	xError=> , 
	xWarning=> , 
	rScaledValue=> , 
	xErrorLow=> , 
	xWarningLow=> , 
	xWarningHigh=> , 
	xErrorHigh=> );

// Ramp generator for speed simulation
_fbRampGenerator(
	rTarget:= _fbValveAnalogInput.rScaledValue, 
	rTargetMin:= 0, 
	rTargetMax:= 100, 
	timRampUp:= T#10S, 
	timRampDown:= T#10S, 
	rSetpoint=> );

// Calculate analog output from ramp generator setpoint
_fbValveAnalogOutput(
	rSetpoint:= _fbRampGenerator.rSetpoint, 
	stScalingConfig:= _stAnalogScaling,
	xReleaseErrors:= FALSE, 
	xReleaseHardwareErrors:= FALSE, 
	xConfirmAlarms:= , 
	iAnalogValue=> iMotorSpeedFeedback, 
	xError=> );]]></ST>
    </Implementation>
    <LineIds Name="FB_MotorMockup">
      <LineId Id="23" Count="0" />
      <LineId Id="9" Count="0" />
      <LineId Id="25" Count="0" />
      <LineId Id="83" Count="0" />
      <LineId Id="75" Count="0" />
      <LineId Id="74" Count="0" />
      <LineId Id="76" Count="0" />
      <LineId Id="81" Count="1" />
      <LineId Id="77" Count="0" />
      <LineId Id="26" Count="0" />
      <LineId Id="35" Count="38" />
      <LineId Id="24" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>