Added safety program pre comissioning and started implementing different modes

This commit is contained in:
Matthias Heisig
2024-03-20 18:08:57 +01:00
parent 57987cb19f
commit ef26159a4f
55 changed files with 10419 additions and 1663 deletions

View File

@@ -6,6 +6,7 @@ VAR_INPUT
sInverterIPAddr : STRING;
xEnable : BOOL;
rPower : REAL;
rReactivePower : REAL := 0.0;
xReset : BOOL;
rMaxBattPower : REAL := 24_000; // 24kW
END_VAR
@@ -47,6 +48,9 @@ VAR
// Unscaled limit for converter power
_iWMaxLimPct : INT;
// Scaling factor for reactive power percent value
_iVarPctSF : INT;
// Reread set power limit
_iWMaxLimPctRead : INT;
_iWMaxLimPctReadScaled : REAL;
@@ -72,6 +76,12 @@ VAR
// Value for commanding the target state of the inverter
_uiPCSSetOperation : UINT;
// Maximum reactive power
_iMaxPowerVar : INT := 0;
// Enable max reactive power percent controller
_iMaxVarPct : INt := 1;
// Holds the state number in which an error occured
_iErrorInState : INT;
@@ -143,6 +153,26 @@ VAR CONSTANT
// SIZE 10
AC_VALUES_START_REGISTER : WORD := 40084;
// Power factor register in cosine of angle
// Size 1, int16 (Range = -32767 .. 32767, Not implemented 0x8000)
//OUT_PF_SET : WORD := 40192;
// Enable power factor controller
// Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
//OUT_PF_SET_ENA : WORD := 40196;
// Reactive power in percent of W_Max
// Size 1, int16 (Range = -32767 .. 32767, Not implemented 0x8000)
VAR_W_MAX_PCT : WORD := 40197;
// Enable percent limited var controller
// Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
VAR_PCT_ENA : WORD := 40204;
// Register for reactive power percent scaling factor
// Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)
VAR_PCT_SF : WORD := 40207;
// Error bits register
// Size 2
EVT_1_REGISTER : WORD := 40110;
@@ -289,6 +319,42 @@ CASE _iState OF
_fbReadRegister(bExecute := FALSE);
END_IF
26: // Read inverter scaling factor for reactive power
_iErrorInState := _iState;
_fbReadRegister(
sIPAddr:= sInverterIPAddr,
nTCPPort:= 502,
nUnitID:= 16#FF, // 16#FF for Modbus TCP
nQuantity:= 1,
nMBAddr:= VAR_PCT_SF,
cbLength:= SIZEOF(_iVarPctSF),
pDestAddr:= ADR(_iVarPctSF),
bExecute:= TRUE,
tTimeout:= T#5S,
bBusy=> ,
bError=> ,
nErrId=> ,
cbRead=> );
// Check if reading mudbus register is done
IF NOT _fbReadRegister.bBusy THEN
// If there was no error then continue
IF NOT _fbReadRegister.bError THEN
_iState := 30;
// Check for valid value
IF (_iVarPctSF < -10) OR (_iVarPctSF > 10) OR (_iVarPctSF = 16#8000) THEN
// Goto error state
_iState := 1000;
END_IF
ELSE
xError := TRUE;
// Goto error state
_iState := 1000;
END_IF
_fbReadRegister(bExecute := FALSE);
END_IF
30: // Read inverter max power
_iErrorInState := _iState;
_fbReadRegister(
@@ -347,6 +413,8 @@ CASE _iState OF
_iState := 50;
_rOldPower := rPower;
_uiMaxLimEn := 1;
// Calculate reactive power setting
_iMaxPowerVar := LREAL_TO_INT((rReactivePower*100)/(_iMaxPowerVar * EXPT(10,_iVarPctSF)));
ELSE
xError := TRUE;
// Goto error state
@@ -355,6 +423,66 @@ CASE _iState OF
_fbWriteRegister(bExecute := FALSE);
END_IF
41: // Set max reactive power in percent
_iErrorInState := _iState;
_fbWriteRegister(
sIPAddr:= sInverterIPAddr,
nTCPPort:= 502,
nUnitID:= 16#FF, // 16#FF for Modbus TCP
nQuantity:= 1,
nMBAddr:= VAR_W_MAX_PCT,
cbLength:= SIZEOF(_iMaxPowerVar),
pSrcAddr:= ADR(_iMaxPowerVar),
bExecute:= TRUE,
tTimeout:= T#5S,
bBusy=> ,
bError=> ,
nErrId=> );
// If writing modbus register is done
IF NOT _fbWriteRegister.bBusy THEN
// And there is no error, then continue
IF NOT _fbWriteRegister.bError THEN
_iState := 42;
ELSE
xError := TRUE;
// Goto error state
_iState := 1000;
END_IF
_fbWriteRegister(bExecute := FALSE);
END_IF
42: // Enable reactive power percent limiting
_iErrorInState := _iState;
_fbWriteRegister(
sIPAddr:= sInverterIPAddr,
nTCPPort:= 502,
nUnitID:= 16#FF, // 16#FF for Modbus TCP
nQuantity:= 1,
nMBAddr:= VAR_PCT_ENA,
cbLength:= SIZEOF(_iMaxVarPct),
pSrcAddr:= ADR(_iMaxVarPct),
bExecute:= TRUE,
tTimeout:= T#5S,
bBusy=> ,
bError=> ,
nErrId=> );
// If writing modbus register is done
IF NOT _fbWriteRegister.bBusy THEN
// And there is no error, then continue
IF NOT _fbWriteRegister.bError THEN
_iState := 50;
ELSE
xError := TRUE;
// Goto error state
_iState := 1000;
END_IF
_fbWriteRegister(bExecute := FALSE);
END_IF
// 45: // Read set power
// _fbReadRegister(
// sIPAddr:= sInverterIPAddr,
@@ -704,11 +832,30 @@ END_CASE]]></ST>
<LineId Id="1171" Count="0" />
<LineId Id="845" Count="33" />
<LineId Id="1172" Count="0" />
<LineId Id="879" Count="33" />
<LineId Id="879" Count="4" />
<LineId Id="1981" Count="1" />
<LineId Id="1991" Count="0" />
<LineId Id="1993" Count="12" />
<LineId Id="1992" Count="0" />
<LineId Id="2006" Count="0" />
<LineId Id="2008" Count="15" />
<LineId Id="2007" Count="0" />
<LineId Id="1983" Count="0" />
<LineId Id="884" Count="28" />
<LineId Id="1173" Count="0" />
<LineId Id="913" Count="29" />
<LineId Id="913" Count="28" />
<LineId Id="2024" Count="1" />
<LineId Id="942" Count="0" />
<LineId Id="1174" Count="0" />
<LineId Id="943" Count="4" />
<LineId Id="1928" Count="3" />
<LineId Id="1934" Count="18" />
<LineId Id="1955" Count="5" />
<LineId Id="1933" Count="0" />
<LineId Id="2030" Count="1" />
<LineId Id="2033" Count="25" />
<LineId Id="2032" Count="0" />
<LineId Id="1932" Count="0" />
<LineId Id="1520" Count="0" />
<LineId Id="1522" Count="17" />
<LineId Id="1541" Count="0" />