Added inverter implementation
This commit is contained in:
@@ -4,25 +4,325 @@
|
||||
<Declaration><![CDATA[PROGRAM MAIN
|
||||
VAR
|
||||
_xEmergencyStopOk AT %I* : BOOL;
|
||||
_xReleaseErrors : BOOL;
|
||||
_xReleaseLimitsErrors : BOOL;
|
||||
_xReleaseErrors : BOOL := TRUE;
|
||||
_xReleaseLimitsErrors : BOOL := TRUE;
|
||||
_xConfirmAlarms : BOOL;
|
||||
_xEnableString : BOOL;
|
||||
_xEnableInverter : BOOL;
|
||||
_fbString : FB_String('String 1');
|
||||
_fbInverter : FB_PowerSupplySunspec;
|
||||
|
||||
_iState : INT;
|
||||
|
||||
// Internal inverter power
|
||||
_rPowerInverter : REAL;
|
||||
|
||||
// Flag for zero power indication
|
||||
_xNoPowerRequested : BOOL;
|
||||
|
||||
// Startup delay for error release during plc startup
|
||||
_tonStartupDelay : TON := (PT := T#10S);
|
||||
|
||||
// Small delay for inverter shutdown
|
||||
_tonBeginShutdown : TON := (PT := T#10S);
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[_fbString(
|
||||
<ST><![CDATA[// Dely release of errors during PLC startup phase
|
||||
_tonStartupDelay(IN := TRUE);
|
||||
|
||||
// Call string 1
|
||||
_fbString(
|
||||
xEnable := _xEnableString,
|
||||
stHMIInterface:= ,
|
||||
xEmergencyStopOk:= _xEmergencyStopOk,
|
||||
xReleaseErrors:= _xReleaseErrors,
|
||||
xReleaseLimitErrors:= _xReleaseLimitsErrors,
|
||||
xConfirmAlarms:= _xConfirmAlarms,
|
||||
xError=> ,
|
||||
xWarning=> );]]></ST>
|
||||
xReleaseErrors:= _xReleaseErrors AND _tonStartupDelay.Q,
|
||||
xReleaseLimitErrors:= _xReleaseLimitsErrors AND _tonStartupDelay.Q,
|
||||
xConfirmAlarms:= _xConfirmAlarms);
|
||||
|
||||
|
||||
// Call inverter
|
||||
//_fbInverter(
|
||||
// sInverterIPAddr:= GVL_CONFIG.sInverterIp,
|
||||
// xEnable:= _xEnableInverter,
|
||||
// rPower:= _rPowerInverter,
|
||||
// xReset:= _xConfirmAlarms,
|
||||
// rMaxBattPower:= DINT_TO_REAL(GVL_CONFIG.diMaxStringDischargePower),
|
||||
// xCloseDCRelais=> ,
|
||||
// rActDCCurrent=> ,
|
||||
// rActDCVoltage=> ,
|
||||
// xError=> ,
|
||||
// xActive=> );
|
||||
|
||||
|
||||
// ===============================
|
||||
// State machine
|
||||
// ===============================
|
||||
CASE _iState OF
|
||||
0: // Idle
|
||||
// Wait for power command
|
||||
IF ABS(GVL_MODBUS.stModbusEMSComm.diSetpointActivePower) > GVL_CONFIG.diMinimumAbsPowerForEnable THEN
|
||||
_iState := 5;
|
||||
END_IF
|
||||
|
||||
5: // Check if power command is within limits
|
||||
IF GVL_MODBUS.stModbusEMSComm.diSetpointActivePower < GVL_CONFIG.diMaxStringDischargePower
|
||||
AND GVL_MODBUS.stModbusEMSComm.diSetpointActivePower > GVL_CONFIG.diMaxStringChargingPower THEN
|
||||
_xEnableString := TRUE;
|
||||
_iState := 10;
|
||||
ELSE
|
||||
// Set error bitmap flag
|
||||
GVL_MODBUS.stModbusEMSComm.lwErrorBitmap.0 := 1;
|
||||
|
||||
// Goto error state
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
10: // Wait for string to be ready
|
||||
IF _fbString.xReady AND (NOT _fbString.xError) THEN
|
||||
_iState := 20;
|
||||
END_IF
|
||||
|
||||
20: // Start main inverter with zero power
|
||||
_rPowerInverter := 0.0;
|
||||
_xEnableInverter := TRUE;
|
||||
_iState := 25;
|
||||
|
||||
25: // Wait for inverter to be ready
|
||||
IF _fbInverter.xActive AND (NOT _fbInverter.xError) THEN
|
||||
GVL_MODBUS.stModbusEMSComm.eBatteryStatus := E_BATTERY_STATUS.ACTIVE;
|
||||
_iState := 30;
|
||||
END_IF
|
||||
|
||||
// Check for errors
|
||||
IF _fbString.xError OR _fbInverter.xError THEN
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
30: // String and inverter enabled
|
||||
// Set inverter power to modbus requested power
|
||||
_rPowerInverter := DINT_TO_REAL(GVL_MODBUS.stModbusEMSComm.diSetpointActivePower);
|
||||
|
||||
// Check if the battery should still be active
|
||||
IF (GVL_MODBUS.stModbusEMSComm.diSetpointActivePower = 0) THEN
|
||||
_xNoPowerRequested := TRUE;
|
||||
ELSE
|
||||
_xNoPowerRequested := FALSE;
|
||||
END_IF
|
||||
|
||||
// Set battery status
|
||||
IF GVL_MODBUS.stModbusEMSComm.diSetpointActivePower > 0 THEN
|
||||
GVL_MODBUS.stModbusEMSComm.eChargeStatus := E_CHARGE_STATUS.DISCHARGING;
|
||||
ELSIF GVL_MODBUS.stModbusEMSComm.diSetpointActivePower < 0 THEN
|
||||
GVL_MODBUS.stModbusEMSComm.eChargeStatus := E_CHARGE_STATUS.CHARGING;
|
||||
ELSE
|
||||
GVL_MODBUS.stModbusEMSComm.eChargeStatus := E_CHARGE_STATUS.UNDEFINED;
|
||||
END_IF
|
||||
|
||||
// Add small delay before shutdown by EMS is detected
|
||||
_tonBeginShutdown(IN := _xNoPowerRequested);
|
||||
|
||||
// shutdown triggered from EMS
|
||||
IF _tonBeginShutdown.Q THEN
|
||||
_tonBeginShutdown(In := FALSE);
|
||||
|
||||
// Set inverter to zero power
|
||||
_rPowerInverter := 0.0;
|
||||
|
||||
// Start string shutdown
|
||||
_xEnableString := FALSE;
|
||||
_iState := 35;
|
||||
END_IF
|
||||
|
||||
// Shutdown triggered by battery fully charged
|
||||
IF GVL_MODBUS.stModbusEMSComm.eChargeStatus = E_CHARGE_STATUS.CHARGING AND (_fbString.rCurrentVoltage >= GVL_CONFIG.rStringFullyChargedVoltage) THEN
|
||||
_tonBeginShutdown(In := FALSE);
|
||||
|
||||
// Set inverter to zero power
|
||||
_rPowerInverter := 0.0;
|
||||
|
||||
// Start string shutdown
|
||||
_xEnableString := FALSE;
|
||||
|
||||
// Change battery status
|
||||
GVL_MODBUS.stModbusEMSComm.eChargeStatus := E_CHARGE_STATUS.FULL;
|
||||
|
||||
_iState := 35;
|
||||
END_IF
|
||||
|
||||
// Shutdown triggered by battery empty
|
||||
IF GVL_MODBUS.stModbusEMSComm.eChargeStatus = E_CHARGE_STATUS.DISCHARGING AND (_fbString.rCurrentVoltage <= GVL_CONFIG.rStringEmptyVoltage) THEN
|
||||
_tonBeginShutdown(In := FALSE);
|
||||
|
||||
// Set inverter to zero power
|
||||
_rPowerInverter := 0.0;
|
||||
|
||||
// Start string shutdown
|
||||
_xEnableString := FALSE;
|
||||
|
||||
// Change battery status
|
||||
GVL_MODBUS.stModbusEMSComm.eChargeStatus := E_CHARGE_STATUS.FULL;
|
||||
|
||||
_iState := 35;
|
||||
END_IF
|
||||
|
||||
// Check for errors
|
||||
IF _fbString.xError OR _fbInverter.xError THEN
|
||||
_tonBeginShutdown(In := FALSE);
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
35: // Wait for string to be in shutdown discharge mode
|
||||
IF _fbString.xInShutdownDischargeMode THEN
|
||||
// Check if we are allowed to discharge during shutdown with inverter
|
||||
IF GVL_CONFIG.xShutdownDischargeWithInverter THEN
|
||||
_iState := 40;
|
||||
ELSE
|
||||
_rPowerInverter := 0.0;
|
||||
_xEnableInverter := FALSE;
|
||||
_iState := 45;
|
||||
END_IF
|
||||
END_IF
|
||||
|
||||
// Check for errors
|
||||
IF _fbString.xError OR _fbInverter.xError THEN
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
40: // Wait for inverter discharge done
|
||||
IF _fbString.xShutdownDischargeAllowed THEN
|
||||
_rPowerInverter := GVL_CONFIG.rAbsShutdownDischargePower;
|
||||
ELSE
|
||||
_rPowerInverter := 0.0;
|
||||
_xEnableInverter := FALSE;
|
||||
_iState := 45;
|
||||
END_IF
|
||||
|
||||
// Check for errors
|
||||
IF _fbString.xError OR _fbInverter.xError THEN
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
45: // Wait for shutdown of string to be done
|
||||
IF (NOT _fbString.xInShutdownDischargeMode) AND _fbString.xOff THEN
|
||||
_iState := 0;
|
||||
END_IF
|
||||
|
||||
// Check for errors
|
||||
IF _fbString.xError OR _fbInverter.xError THEN
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
1000: // Error state
|
||||
_xEnableString := FALSE;
|
||||
_xEnableInverter := FALSE;
|
||||
_rPowerInverter := 0.0;
|
||||
GVL_MODBUS.stModbusEMSComm.eBatteryStatus := E_BATTERY_STATUS.ERROR;
|
||||
_iState := 1010;
|
||||
|
||||
1010: // Wait for reset from error state
|
||||
IF (GVL_MODBUS.stModbusEMSComm.diSetpointActivePower = 0) AND (NOT _fbString.xError) AND (NOT _fbInverter.xError) THEN
|
||||
// Reset modbus error register
|
||||
GVL_MODBUS.stModbusEMSComm.lwErrorBitmap := 0;
|
||||
|
||||
// Reset modbus error flag
|
||||
GVL_MODBUS.stModbusEMSComm.eBatteryStatus := E_BATTERY_STATUS.OFF;
|
||||
|
||||
// Goto init state
|
||||
_iState := 0;
|
||||
END_IF
|
||||
|
||||
END_CASE
|
||||
|
||||
|
||||
// Reset alarm confirmation
|
||||
IF _xConfirmAlarms THEN
|
||||
_xConfirmAlarms := FALSE;
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
<LineIds Name="MAIN">
|
||||
<LineId Id="7" Count="6" />
|
||||
<LineId Id="2" Count="0" />
|
||||
<LineId Id="126" Count="55" />
|
||||
<LineId Id="218" Count="0" />
|
||||
<LineId Id="182" Count="0" />
|
||||
<LineId Id="304" Count="0" />
|
||||
<LineId Id="207" Count="2" />
|
||||
<LineId Id="314" Count="0" />
|
||||
<LineId Id="210" Count="2" />
|
||||
<LineId Id="305" Count="1" />
|
||||
<LineId Id="308" Count="0" />
|
||||
<LineId Id="215" Count="0" />
|
||||
<LineId Id="219" Count="1" />
|
||||
<LineId Id="222" Count="0" />
|
||||
<LineId Id="221" Count="0" />
|
||||
<LineId Id="223" Count="1" />
|
||||
<LineId Id="234" Count="1" />
|
||||
<LineId Id="237" Count="1" />
|
||||
<LineId Id="236" Count="0" />
|
||||
<LineId Id="309" Count="3" />
|
||||
<LineId Id="315" Count="1" />
|
||||
<LineId Id="360" Count="1" />
|
||||
<LineId Id="313" Count="0" />
|
||||
<LineId Id="317" Count="0" />
|
||||
<LineId Id="241" Count="0" />
|
||||
<LineId Id="240" Count="0" />
|
||||
<LineId Id="239" Count="0" />
|
||||
<LineId Id="327" Count="0" />
|
||||
<LineId Id="242" Count="1" />
|
||||
<LineId Id="262" Count="0" />
|
||||
<LineId Id="264" Count="0" />
|
||||
<LineId Id="261" Count="0" />
|
||||
<LineId Id="263" Count="0" />
|
||||
<LineId Id="265" Count="0" />
|
||||
<LineId Id="260" Count="0" />
|
||||
<LineId Id="245" Count="0" />
|
||||
<LineId Id="244" Count="0" />
|
||||
<LineId Id="328" Count="0" />
|
||||
<LineId Id="330" Count="2" />
|
||||
<LineId Id="339" Count="0" />
|
||||
<LineId Id="338" Count="0" />
|
||||
<LineId Id="333" Count="3" />
|
||||
<LineId Id="340" Count="3" />
|
||||
<LineId Id="337" Count="0" />
|
||||
<LineId Id="329" Count="0" />
|
||||
<LineId Id="344" Count="1" />
|
||||
<LineId Id="347" Count="12" />
|
||||
<LineId Id="346" Count="0" />
|
||||
<LineId Id="246" Count="2" />
|
||||
<LineId Id="251" Count="0" />
|
||||
<LineId Id="249" Count="1" />
|
||||
<LineId Id="256" Count="1" />
|
||||
<LineId Id="266" Count="0" />
|
||||
<LineId Id="296" Count="0" />
|
||||
<LineId Id="290" Count="0" />
|
||||
<LineId Id="267" Count="0" />
|
||||
<LineId Id="291" Count="0" />
|
||||
<LineId Id="294" Count="1" />
|
||||
<LineId Id="292" Count="1" />
|
||||
<LineId Id="268" Count="0" />
|
||||
<LineId Id="258" Count="0" />
|
||||
<LineId Id="269" Count="1" />
|
||||
<LineId Id="272" Count="0" />
|
||||
<LineId Id="259" Count="0" />
|
||||
<LineId Id="273" Count="3" />
|
||||
<LineId Id="278" Count="3" />
|
||||
<LineId Id="277" Count="0" />
|
||||
<LineId Id="285" Count="0" />
|
||||
<LineId Id="287" Count="2" />
|
||||
<LineId Id="286" Count="0" />
|
||||
<LineId Id="282" Count="1" />
|
||||
<LineId Id="300" Count="0" />
|
||||
<LineId Id="302" Count="1" />
|
||||
<LineId Id="301" Count="0" />
|
||||
<LineId Id="297" Count="2" />
|
||||
<LineId Id="284" Count="0" />
|
||||
<LineId Id="183" Count="2" />
|
||||
<LineId Id="216" Count="1" />
|
||||
<LineId Id="186" Count="6" />
|
||||
<LineId Id="252" Count="1" />
|
||||
<LineId Id="255" Count="0" />
|
||||
<LineId Id="254" Count="0" />
|
||||
<LineId Id="193" Count="9" />
|
||||
<LineId Id="25" Count="0" />
|
||||
</LineIds>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
Reference in New Issue
Block a user