924 lines
26 KiB
XML
924 lines
26 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
|
|
<POU Name="FB_PowerSupplySunspec" Id="{a826dd09-442c-45c5-8ae3-9b71f293003c}" SpecialFunc="None">
|
|
<Declaration><![CDATA[FUNCTION_BLOCK FB_PowerSupplySunspec
|
|
VAR_INPUT
|
|
sInverterIPAddr : STRING;
|
|
xEnable : BOOL;
|
|
rPower : REAL;
|
|
rReactivePower : REAL := 0.0;
|
|
xReset : BOOL;
|
|
rMaxBattPower : REAL := 24_000; // 24kW
|
|
END_VAR
|
|
VAR_OUTPUT
|
|
// Output for SCS DC-Relais
|
|
xCloseDCRelais AT %Q*: BOOL;
|
|
|
|
// Inverter active
|
|
xActive : BOOL;
|
|
|
|
// FB error
|
|
xError : BOOL;
|
|
|
|
// Current inverter values
|
|
stCurrentValues : ST_SUNSPEC_CURRENT_VALUES;
|
|
END_VAR
|
|
VAR
|
|
// Current state
|
|
_iState : INT := 0;
|
|
|
|
// FB for reading Modbus holding registers
|
|
_fbReadRegister : FB_MBReadRegs;
|
|
|
|
// FB for writing Modbus holding registers
|
|
_fbWriteRegister : FB_MBWriteRegs;
|
|
|
|
// Timer for checking if the inverter started in a reasonable amount of time
|
|
_tonInverterStartup : TON;
|
|
|
|
// converter max power scaling factor
|
|
_iWMaxSF : INT;
|
|
|
|
// Unscaled converter max power
|
|
_iWMax : UINT;
|
|
|
|
// Scaled converter max power
|
|
_rWMax : REAL;
|
|
|
|
// Unscaled limit for converter power
|
|
_iWMaxLimPct : INT;
|
|
|
|
// Scaling factor for reactive power percent value
|
|
_iVarPctSF : INT;
|
|
|
|
// Reread set power limit
|
|
_iWMaxLimPctRead : INT;
|
|
_iWMaxLimPctReadScaled : REAL;
|
|
|
|
// Scaling factor for power limiting
|
|
_iWMaxLimPctSF : INT;
|
|
|
|
// Unscaled maximum power from type label
|
|
_iWRTGSF : INT;
|
|
|
|
// Scaling for maximum power from type label
|
|
_rWRTGScaling : REAL;
|
|
|
|
// Current state of the inverters internal statemachine
|
|
_uiInverterState : UINT;
|
|
|
|
// Last written power to the inverter
|
|
_rOldPower : REAL;
|
|
|
|
// Value to enable or dissable the Power limiting feature
|
|
_uiMaxLimEn : UINT;
|
|
|
|
// 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;
|
|
|
|
// Time for polling for current dc values and check for inverter error
|
|
_timPollingDelay : TIME := T#250MS;
|
|
|
|
// Timer for polling of current values
|
|
_tonPollingTimer : TON;
|
|
|
|
// Current DC values (DCA, DCA_SF, DCV, DCV_SF, DCW, DCW_SF) in word array for efficient modbus reading
|
|
_awCurrentDCValues : ARRAY[0..5] OF WORD;
|
|
|
|
// Current AC values (W, W_SF, Hz, Hz_SF, VA, VA_SF, VAr, VAr_SF, PF, PF_SF) in word array for efficient modbus reading
|
|
_awCurrentACValues : ARRAY[0..9] OF WORD;
|
|
|
|
// Inverter error bits
|
|
_dwErrorBits : DWORD;
|
|
|
|
// Inverter reset errors command
|
|
_uiResetInverter : UINT := 1;
|
|
|
|
END_VAR
|
|
VAR CONSTANT
|
|
// Inverter statemachine status register
|
|
// Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
|
|
STATUS_REGISTER : WORD := 40108;
|
|
|
|
// Throttled power register
|
|
// Size 1, int16 (Range = -32767 .. 32767, Not implemented 0x8000)
|
|
W_MAX_LIM_PCT_REGISTER : WORD := 40187;
|
|
|
|
// Throttled power register scaling factor
|
|
// Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)
|
|
W_MAX_LIM_PCT_SF_REGISTER : WORD := 40205;
|
|
|
|
// Control register to enable and dissable if the power throttleing should be active
|
|
// Size1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
|
|
W_MAX_LIM_EN_REGISTER : WORD := 40191;
|
|
|
|
// Register to reset latched alarms in the inverter
|
|
// Size 1, uint16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
|
|
PCS_ALARM_RESET_REGISTER : WORD := 40230;
|
|
|
|
// Control register to set the target state of the inverters state machine
|
|
// Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
|
|
PCS_SET_OPERATION_REGISTER : WORD := 40231;
|
|
|
|
// Maximum inverter output power
|
|
// Size 1, uint16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
|
|
W_MAX_REGISTER : WORD := 40152;
|
|
|
|
// Maximum inverter output power scaling factor
|
|
// Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)
|
|
W_MAX_SF_REGISTER : WORD := 40172;
|
|
|
|
// Maximum inverter output power from type label
|
|
// Size 1, uint16 (Range = 0 .. 65534, Not implemented = 0xFFFF)
|
|
W_RTG_REGISTER : WORD := 40125;
|
|
|
|
// Maximum inverter output power from type label scaling factor
|
|
// Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)
|
|
W_RTG_SF_REGISTER : WORD := 40126;
|
|
|
|
// Start of register with the current dc values
|
|
// Size 4
|
|
DC_VALUES_START_REGISTER : WORD := 40097;
|
|
|
|
// Start of register with the current ac values
|
|
// 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;
|
|
END_VAR
|
|
]]></Declaration>
|
|
<Implementation>
|
|
<ST><![CDATA[// Clamp rPower to maximum allowed power
|
|
IF (rPower > rMaxBattPower) THEN
|
|
rPower := rMaxBattPower;
|
|
END_IF
|
|
|
|
IF (rPower < -rMaxBattPower) THEN
|
|
rPower := -rMaxBattPower;
|
|
END_IF
|
|
|
|
// State machine
|
|
CASE _iState OF
|
|
|
|
0: // Off
|
|
// If enable and INTLK Ok
|
|
IF xEnable THEN
|
|
_iState := 10;
|
|
xCloseDCRelais := TRUE;
|
|
END_IF
|
|
|
|
10: // Wait for inverter to be online and in state STANDBY(8)
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= STATUS_REGISTER,
|
|
cbLength:= SIZEOF(_uiInverterState),
|
|
pDestAddr:= ADR(_uiInverterState),
|
|
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 and the state is STANDBY(8) then continue
|
|
IF NOT _fbReadRegister.bError AND _uiInverterState = 8 THEN
|
|
_iState := 20;
|
|
END_IF
|
|
|
|
// If the inverter is not ready wait some time before polling again
|
|
IF NOT _fbReadRegister.bError AND _uiInverterState <> 8 THEN
|
|
_iState := 15;
|
|
END_IF
|
|
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
// If not enable, go back to idle
|
|
IF NOT xEnable THEN
|
|
_fbReadRegister(bExecute := FALSE);
|
|
_iState := 0;
|
|
END_IF
|
|
|
|
15: // Delay polling inverter ready
|
|
_tonPollingTimer(IN := TRUE, PT := _timPollingDelay);
|
|
IF _tonPollingTimer.Q THEN
|
|
_tonPollingTimer(IN := FALSE);
|
|
_iState := 10;
|
|
END_IF
|
|
|
|
// If not enable, go back to idle
|
|
IF NOT xEnable THEN
|
|
_tonPollingTimer(IN := FALSE);
|
|
_iState := 0;
|
|
END_IF
|
|
|
|
|
|
20: // Read inverter max power scaling
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= W_MAX_SF_REGISTER,
|
|
cbLength:= SIZEOF(_iWMaxSF),
|
|
pDestAddr:= ADR(_iWMaxSF),
|
|
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 := 25;
|
|
// Check for valid value
|
|
IF (_iWMaxSF < -10) OR (_iWMaxSF > 10) OR (_iWMaxSF = 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
|
|
|
|
25: // Read inverter Max power limit scaling
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= W_MAX_LIM_PCT_SF_REGISTER,
|
|
cbLength:= SIZEOF(_iWMaxLimPctSF),
|
|
pDestAddr:= ADR(_iWMaxLimPctSF),
|
|
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 (_iWMaxLimPctSF < -10) OR (_iWMaxLimPctSF > 10) OR (_iWMaxLimPctSF = 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
|
|
|
|
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(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= W_MAX_REGISTER,
|
|
cbLength:= SIZEOF(_iWMax),
|
|
pDestAddr:= ADR(_iWMax),
|
|
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 := 40;
|
|
// Reading a register with scaling factor = value * 10^SF
|
|
_rWMax := LREAL_TO_REAL(_iWMax * EXPT(10,_iWMaxSF));
|
|
|
|
// Calculate power to write to register
|
|
_iWMaxLimPct := LREAL_TO_INT((rPower*100)/(_rWMax * EXPT(10,_iWMaxLimPctSF)));
|
|
ELSE
|
|
xError := TRUE;
|
|
// Goto error state
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
40: // Set power limit
|
|
_iErrorInState := _iState;
|
|
_fbWriteRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= W_MAX_LIM_PCT_REGISTER,
|
|
cbLength:= SIZEOF(_iWMaxLimPct),
|
|
pSrcAddr:= ADR(_iWMaxLimPct),
|
|
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;
|
|
_rOldPower := rPower;
|
|
_uiMaxLimEn := 1;
|
|
// Calculate reactive power setting
|
|
//_iMaxPowerVar := LREAL_TO_INT((rReactivePower*100)/(_iMaxPowerVar * EXPT(10,_iVarPctSF)));
|
|
ELSE
|
|
xError := TRUE;
|
|
// Goto error state
|
|
_iState := 1000;
|
|
END_IF
|
|
_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,
|
|
// nTCPPort:= 502,
|
|
// nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
// nQuantity:= 1,
|
|
// nMBAddr:= W_MAX_LIM_PCT_REGISTER,
|
|
// cbLength:= SIZEOF(_iWMaxLimPctRead),
|
|
// pDestAddr:= ADR(_iWMaxLimPctRead),
|
|
// bExecute:= TRUE,
|
|
// tTimeout:= T#5S,
|
|
// bBusy=> ,
|
|
// bError=> ,
|
|
// nErrId=> ,
|
|
// cbRead=> );
|
|
|
|
// // Check if reading mudbus register is done
|
|
// IF NOT _fbReadRegister.bBusy THEN
|
|
// IF NOT _fbReadRegister.bError THEN
|
|
// _iWMaxLimPctReadScaled := LREAL_TO_INT(_rWMax * _iWMaxLimPctRead * EXPT(10,_iWMaxLimPctSF)*0.01);
|
|
// _iState := 50;
|
|
// END_IF
|
|
// _fbReadRegister(bExecute := FALSE);
|
|
// END_IF
|
|
|
|
|
|
50: // Enable Power limiting (THROTTLED)
|
|
_iErrorInState := _iState;
|
|
_fbWriteRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= W_MAX_LIM_EN_REGISTER,
|
|
cbLength:= SIZEOF(_uiMaxLimEn),
|
|
pSrcAddr:= ADR(_uiMaxLimEn),
|
|
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 := 60;
|
|
_uiPCSSetOperation := 1;
|
|
ELSE
|
|
xError := TRUE;
|
|
// Goto error state
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbWriteRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
60: // Switch to THROTTLED mode
|
|
_iErrorInState := _iState;
|
|
_fbWriteRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= PCS_SET_OPERATION_REGISTER,
|
|
cbLength:= SIZEOF(_uiPCSSetOperation),
|
|
pSrcAddr:= ADR(_uiPCSSetOperation),
|
|
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 := 65;
|
|
ELSE
|
|
// Goto error state
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbWriteRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
65: // Wait for polling timer
|
|
_tonPollingTimer(IN := TRUE, PT := _timPollingDelay);
|
|
IF _tonPollingTimer.Q THEN
|
|
_tonPollingTimer(IN := FALSE);
|
|
_iState := 70;
|
|
ELSIF ABS(rPower - _rOldPower) > 0.1 THEN
|
|
_tonPollingTimer(IN := FALSE);
|
|
// If power has ben changed, goto set power limit mode
|
|
_iState := 40;
|
|
// Calculate power to write to register
|
|
_iWMaxLimPct := LREAL_TO_INT((rPower*100)/(_rWMax * EXPT(10,_iWMaxLimPctSF)));
|
|
END_IF
|
|
|
|
// check if inverter should shut down
|
|
IF NOT xEnable THEN
|
|
_uiPCSSetOperation := 3;
|
|
// Goto shutdown sequence
|
|
_iState := 200;
|
|
END_IF
|
|
|
|
70: // Enabled, check for error
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= STATUS_REGISTER,
|
|
cbLength:= SIZEOF(_uiInverterState),
|
|
pDestAddr:= ADR(_uiInverterState),
|
|
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 and the converter has no error continue
|
|
IF NOT _fbReadRegister.bError AND (_uiInverterState <> 7) THEN
|
|
_iState := 80;
|
|
IF (_uiInverterState = 4) OR (_uiInverterState = 5) THEN
|
|
xActive := TRUE;
|
|
ELSE
|
|
xActive := FALSE;
|
|
END_IF
|
|
ELSE
|
|
xError := TRUE;
|
|
// Read error register
|
|
_iState := 990;
|
|
END_IF
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
80: // Read current DC values
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 6,
|
|
nMBAddr:= DC_VALUES_START_REGISTER,
|
|
cbLength:= SIZEOF(_awCurrentDCValues),
|
|
pDestAddr:= ADR(_awCurrentDCValues),
|
|
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 and the converter has no error continue
|
|
IF NOT _fbReadRegister.bError THEN
|
|
_iState := 85;
|
|
stCurrentValues.rActDCCurrent := LREAL_TO_REAL(WORD_TO_UINT(_awCurrentDCValues[0]) * EXPT(10,WORD_TO_INT(_awCurrentDCValues[1])));
|
|
stCurrentValues.rActDCVoltage := LREAL_TO_REAL(WORD_TO_UINT(_awCurrentDCValues[2]) * EXPT(10,WORD_TO_INT(_awCurrentDCValues[3])));
|
|
stCurrentValues.rActDCPower := LREAL_TO_REAL(WORD_TO_INT(_awCurrentDCValues[4]) * EXPT(10,WORD_TO_INT(_awCurrentDCValues[5])));
|
|
ELSE
|
|
// Read error register
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
85: // Read current ac values
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 10,
|
|
nMBAddr:= AC_VALUES_START_REGISTER,
|
|
cbLength:= SIZEOF(_awCurrentACValues),
|
|
pDestAddr:= ADR(_awCurrentACValues),
|
|
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 and the converter has no error continue
|
|
IF NOT _fbReadRegister.bError THEN
|
|
// Go back to polling state
|
|
_iState := 65;
|
|
stCurrentValues.rActACPower := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[0]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[1])));
|
|
stCurrentValues.rActACFreq := LREAL_TO_REAL(WORD_TO_UINT(_awCurrentACValues[2]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[3])));
|
|
stCurrentValues.rActApparentPower := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[4]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[5])));
|
|
stCurrentValues.rActReactivePower := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[6]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[7])));
|
|
stCurrentValues.rActPowerFactor := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[8]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[9])));
|
|
ELSE
|
|
// Read error register
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
200: // Shutdown sequence
|
|
_iErrorInState := _iState;
|
|
_fbWriteRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= PCS_SET_OPERATION_REGISTER,
|
|
cbLength:= SIZEOF(_uiPCSSetOperation),
|
|
pSrcAddr:= ADR(_uiPCSSetOperation),
|
|
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 := 210;
|
|
stCurrentValues.rActDCCurrent := 0.0;
|
|
stCurrentValues.rActDCVoltage := 0.0;
|
|
ELSE
|
|
// Goto error state
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbWriteRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
210: // Wait for poll timer to
|
|
_tonPollingTimer(IN := TRUE, PT := _timPollingDelay);
|
|
IF _tonPollingTimer.Q THEN
|
|
_tonPollingTimer(IN := FALSE);
|
|
_iState := 220;
|
|
END_IF
|
|
|
|
220: // Poll and wait for standby state
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= STATUS_REGISTER,
|
|
cbLength:= SIZEOF(_uiInverterState),
|
|
pDestAddr:= ADR(_uiInverterState),
|
|
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 and the converter has no error continue
|
|
IF NOT _fbReadRegister.bError THEN
|
|
_iState := 0;
|
|
xActive := FALSE;
|
|
xCloseDCRelais := FALSE;
|
|
END_IF
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
990: // Read error register
|
|
_iErrorInState := _iState;
|
|
_fbReadRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 2,
|
|
nMBAddr:= EVT_1_REGISTER,
|
|
cbLength:= SIZEOF(_dwErrorBits),
|
|
pDestAddr:= ADR(_dwErrorBits),
|
|
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 and the converter has no error continue
|
|
IF NOT _fbReadRegister.bError THEN
|
|
_iState := 1000;
|
|
END_IF
|
|
_fbReadRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
1000: // Error state, wait for reset
|
|
IF xReset AND (NOT xEnable) THEN
|
|
_iState := 1010;
|
|
END_IF
|
|
|
|
1010: // Try to clear all latched events
|
|
_fbWriteRegister(
|
|
sIPAddr:= sInverterIPAddr,
|
|
nTCPPort:= 502,
|
|
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
|
nQuantity:= 1,
|
|
nMBAddr:= PCS_ALARM_RESET_REGISTER,
|
|
cbLength:= SIZEOF(_uiResetInverter),
|
|
pSrcAddr:= ADR(_uiResetInverter),
|
|
bExecute:= TRUE,
|
|
tTimeout:= T#5S,
|
|
bBusy=> ,
|
|
bError=> ,
|
|
nErrId=> );
|
|
|
|
IF NOT _fbWriteRegister.bBusy THEN
|
|
_iState := 0;
|
|
xError := FALSE;
|
|
_fbWriteRegister(bExecute := FALSE);
|
|
END_IF
|
|
|
|
END_CASE]]></ST>
|
|
</Implementation>
|
|
<LineIds Name="FB_PowerSupplySunspec">
|
|
<LineId Id="774" Count="10" />
|
|
<LineId Id="1550" Count="0" />
|
|
<LineId Id="785" Count="28" />
|
|
<LineId Id="1701" Count="5" />
|
|
<LineId Id="814" Count="1" />
|
|
<LineId Id="1714" Count="0" />
|
|
<LineId Id="1719" Count="0" />
|
|
<LineId Id="1715" Count="0" />
|
|
<LineId Id="1718" Count="0" />
|
|
<LineId Id="1716" Count="1" />
|
|
<LineId Id="1707" Count="1" />
|
|
<LineId Id="1710" Count="2" />
|
|
<LineId Id="1709" Count="0" />
|
|
<LineId Id="1713" Count="0" />
|
|
<LineId Id="1720" Count="0" />
|
|
<LineId Id="1722" Count="1" />
|
|
<LineId Id="1726" Count="0" />
|
|
<LineId Id="1725" Count="0" />
|
|
<LineId Id="1721" Count="0" />
|
|
<LineId Id="1433" Count="0" />
|
|
<LineId Id="816" Count="28" />
|
|
<LineId Id="1171" Count="0" />
|
|
<LineId Id="845" Count="33" />
|
|
<LineId Id="1172" Count="0" />
|
|
<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="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" />
|
|
<LineId Id="1548" Count="0" />
|
|
<LineId Id="1542" Count="2" />
|
|
<LineId Id="1521" Count="0" />
|
|
<LineId Id="1493" Count="0" />
|
|
<LineId Id="948" Count="23" />
|
|
<LineId Id="1175" Count="0" />
|
|
<LineId Id="972" Count="42" />
|
|
<LineId Id="1560" Count="1" />
|
|
<LineId Id="1015" Count="3" />
|
|
<LineId Id="1127" Count="0" />
|
|
<LineId Id="1019" Count="25" />
|
|
<LineId Id="1097" Count="1" />
|
|
<LineId Id="1100" Count="1" />
|
|
<LineId Id="1099" Count="0" />
|
|
<LineId Id="1045" Count="0" />
|
|
<LineId Id="1176" Count="0" />
|
|
<LineId Id="1046" Count="6" />
|
|
<LineId Id="1063" Count="20" />
|
|
<LineId Id="1090" Count="0" />
|
|
<LineId Id="1092" Count="0" />
|
|
<LineId Id="1775" Count="0" />
|
|
<LineId Id="1084" Count="4" />
|
|
<LineId Id="1062" Count="0" />
|
|
<LineId Id="1736" Count="1" />
|
|
<LineId Id="1739" Count="19" />
|
|
<LineId Id="1781" Count="0" />
|
|
<LineId Id="1759" Count="2" />
|
|
<LineId Id="1774" Count="0" />
|
|
<LineId Id="1776" Count="1" />
|
|
<LineId Id="1762" Count="4" />
|
|
<LineId Id="1738" Count="0" />
|
|
<LineId Id="1093" Count="1" />
|
|
<LineId Id="1102" Count="19" />
|
|
<LineId Id="1166" Count="1" />
|
|
<LineId Id="1122" Count="4" />
|
|
<LineId Id="1054" Count="0" />
|
|
<LineId Id="1295" Count="4" />
|
|
<LineId Id="1128" Count="0" />
|
|
<LineId Id="1300" Count="1" />
|
|
<LineId Id="1129" Count="0" />
|
|
<LineId Id="1132" Count="20" />
|
|
<LineId Id="1163" Count="0" />
|
|
<LineId Id="1294" Count="0" />
|
|
<LineId Id="1161" Count="1" />
|
|
<LineId Id="1130" Count="1" />
|
|
<LineId Id="1055" Count="0" />
|
|
<LineId Id="1177" Count="20" />
|
|
<LineId Id="1199" Count="1" />
|
|
<LineId Id="1169" Count="0" />
|
|
<LineId Id="1265" Count="2" />
|
|
<LineId Id="1269" Count="3" />
|
|
<LineId Id="1274" Count="11" />
|
|
<LineId Id="1273" Count="0" />
|
|
<LineId Id="1289" Count="1" />
|
|
<LineId Id="1293" Count="0" />
|
|
<LineId Id="2235" Count="0" />
|
|
<LineId Id="1291" Count="1" />
|
|
<LineId Id="1056" Count="0" />
|
|
<LineId Id="12" Count="0" />
|
|
</LineIds>
|
|
</POU>
|
|
</TcPlcObject> |