Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY, CODESYS 3.5 SP19 SAFETY
This function block is for controlling DO valves more economic with PWM signal to reduce unnecessary current consumption and heating of valve and control unit.
The output diagnostic is done using:
measured output current
over current protection status provided by firmware
output's digital input status (library version 1.3.2.5 or later)
Init method is used to initialize the necessary static calculation parameters for the function block instance.
The method shall be called at least once before the actual function block can be called, i.e. at the application initialization phase.
The method checks the validity of input parameters. However, none of the function block outputs are affected by the initialization.
|
A parameter error is diagnosed if:
|
The G_DO_MAX_DIAG_DELAY constant is the hardware specific maximum value for diagnostic delay.
Parameter |
Data type |
Unit |
Range |
Description |
S_i_ReducedControlDelay |
SAFEUINT |
ms |
- |
Delay time when PWM control is reduced to given ratio after rising edge of S_i_DOControl. |
S_i_ReducedControlRatio |
SAFEDINT |
‰ |
0 - 1000 |
Ratio that PWM control is reduced after delay. |
S_i_BrokenCircuitCurrentLimit |
SAFEDINT |
mA |
>= 0 |
Limit for undercurrent diagnosis. |
S_i_OverCurrentLimit |
SAFEDINT |
mA |
> 0 |
Limit for overcurrent diagnosis. |
S_i_DiagnosticDelay |
SAFEUINT |
ms |
0 - G_DO_MAX_ DIAG_DELAY |
Delay time for diagnostics. |
i_pEventCode |
POINTER TO EventCode |
- |
≠ 0 |
Pointer to application variable which is type EventCode. |
TRUE: All initialization parameters ok. |
FALSE: Error in initialization parameter(s). |
The output o_PWMRatio follows the input S_i_DOControl if:
The control is enabled, i.e. i_Enable is TRUE AND
No fault (including initialization) has been diagnosed
When S_i_DOControl is FALSE, the PWM ratio is set to 0%.
On the rising edge of S_i_DOControl is FALSE, the PWM ratio is set to 100%.
When time of S_i_ReducedControlDelay has elapsed from the rising edge of S_i_DOControl, the output PWM ratio is reduced to S_i_ReducedControlRatio value.
|
From the library version 2 (SP19), the output o_PWMRatio is scaled to HW specific resolution using G_PWM_OUT_MAX_VALUE constant. |
When S_i_DOControl is TRUE, the output o_PWMRatio is set to 0 after given diagnostic delay time S_i_DiagnosticDelay
if the measured output current exceeds limit given with S_i_OverCurrentLimit OR
if the measured output current falls below limit given with S_i_BrokenCircuitCurrentLimit
When S_i_DOControl is FALSE and i_Enable is TRUE, the external voltage error is diagnosed after given diagnostic delay time S_i_DiagnosticDelay if i_DOStatus is TRUE.
The output o_PWMRatio is set to 0‰ immediately if i_Enable is FALSE, or i_OverCurrentProtectionStatus is TRUE.
|
Parameter error during normal operation is diagnosed if i_OutputCurrent is out of range. |
Input variable name |
Data type |
Unit |
Range |
Description |
i_Enable |
BOOL |
- |
- |
Enable POU operation |
S_i_DOControl |
SAFEBOOL |
- |
- |
DO control request |
i_OutputCurrent |
DWORD |
mA |
0 – 2147483647 |
Measured current value of DO pin |
i_OverCurrentProtectionStatus |
BOOL |
- |
- |
Overcurrent protection status of firmware |
i_DOStatus |
BOOL |
- |
- |
Output digital status input |
Output variable name |
Data type |
Unit |
Range |
Description |
o_PWMRatio |
DWORD |
‰ |
0 - 1000 |
PWM ratio of DO after diagnostics |
o_Status |
Status |
- |
- |
Status of output value. See Status struct. |
Input variable name |
Data type |
Unit |
Range |
Description |
i_Enable |
BOOL |
- |
- |
Enable POU operation |
S_i_DOControl |
SAFEBOOL |
- |
- |
DO control request |
i_OutputCurrent |
DINT |
mA |
- |
Measured current value of DO pin |
i_OverCurrentProtectionStatus |
BOOL |
- |
- |
Overcurrent protection status of firmware |
i_DOStatus |
BOOL |
- |
- |
Output digital status input |
Output variable name |
Data type |
Unit |
Range |
Description |
o_PWMRatio |
DWORD |
HW specific |
0 - G_PWM_OUT _MAX_VALUE |
PWM ratio of DO after diagnostics |
o_Status |
Status |
- |
- |
Status of output value. See Status struct. |
See Diagnostic Interface library description of error status and event code functionality.
Conditions |
o_PWMRatio |
o_Status. OutputValid |
o_Status error status |
Event code FunctionID |
Event code EventID |
i_Enable TRUE AND parameter error AND i_pEventCode valid |
0‰ |
FALSE |
ParameterError |
DO_CONTROL _ECO |
PARAMETER_ERROR |
i_Enable TRUE AND init parameter error AND |
0‰ |
FALSE |
ParameterError |
- |
- |
i_Enable rises AND parameters ok AND S_i_DOControl TRUE |
0‰ |
FALSE |
StartupError |
DO_CONTROL _ECO |
STARTUP_ERROR |
i_Enable rises AND init parameters ok AND input valid |
See operation chapter |
TRUE |
- |
NO_FUNC |
NO_ERROR |
i_Enable TRUE AND init parameters ok AND o_PWMRatio > 0 AND S_i_OutputCurrent < S_i_BrokenCircuitCurrentLimit |
0‰ |
FALSE |
BrokenCircuit |
DO_CONTROL _ECO |
INPUT_TOO_LOW |
i_Enable TRUE AND parameters ok AND S_i_OutputCurrent > S_i_OverCurrentLimit |
0‰ |
FALSE |
OverCurrent |
DO_CONTROL _ECO |
INPUT_TOO_HIGH |
i_Enable TRUE AND parameters ok AND i_OverCurrentProtectionStatus TRUE |
0‰ |
FALSE |
OverCurrent |
DO_CONTROL _ECO |
INPUT_TOO_HIGH |
i_Enable TRUE AND init parameters ok AND S_i_DOControl FALSE AND i_DOStatus = TRUE |
0‰ |
FALSE |
External Voltage |
DO_CONTROL _ECO |
INPUT_TOO_HIGH |
|
Used I/O variables must be mapped to I/O-interface. |
|
I/O variables and configuration are provided by MultiTool Creator code template. See also How to control DO & DO ECO |
IO variables: |
|
X1_32_CurrentFeedback: DWORD; // DWORD mA Current feedback X1_32_PWM_Ratio: DWORD; // DWORD 0,1% PWM ratio X1_32_Overcurrent: BOOL; // BOOL OC status from firmware (Status flags bit 2) X1_32_DOS: BOOL; // BOOL output's digital input status
|
Safety Definitions: |
Result: EPEC_SYSTEM.SYSTEM_ERROR_CODES:= EPEC_SYSTEM.SYSTEM_ERROR_CODES.FW_ERR_OK;
PIN_1_32_DO_ECO: EPEC_SHWD.S_DOValveEcoControlAndDiagnostics; PIN_1_32_DO_Status: EPEC_SHWD.Status; PIN_1_32_DO_Control: BOOL := FALSE; PIN_1_32_DO_EC: EPEC_DITF.EventCode; |
Safety Init: |
(* Set IO driver to configuration state *) IF EPEC_SYSTEM.SYSTEM_ERROR_CODES.FW_ERR_OK = Result THEN Result := EPEC_IODRV.IoDrvSetState(i_State:=EPEC_IODRV.IoDrvStates.IODRV_STATE_CONFIGURATION); END_IF
(* Configure pin X1-32 to PWM/DO *) IF EPEC_SYSTEM.SYSTEM_ERROR_CODES.FW_ERR_OK = Result THEN Result := EPEC_IODRV.IoDrvPWMSetMode( EPEC_HW.IO_Channels.PIN_1_32_PWFM, EPEC_IODRV.IoDrvModes.IODRV_MODE_PWM_DIRECT ); END_IF
(* Set IO driver to run state *) EPEC_IODRV.IoDrvSetState(EPEC_IODRV.IoDrvStates.IODRV_STATE_RUN);
(* Init control POU *)
PIN_1_32_DO_EC.DeviceID := BYTE#1; PIN_1_32_DO_EC.ChannelID := BYTE#32; PIN_1_32_DO_EC.FunctionID := EPEC_DITF.FunctionIDs.NO_FUNC; PIN_1_32_DO_EC.EventID := EPEC_DITF.ErrorIDs.NO_ERROR;
PIN_1_32_DO.Init( S_i_ReducedControlDelay := UINT#100, // Reduced current after 100 ms S_i_ReducedControlRatio := DINT#300, // Reduced current ratio 30,0% S_i_BrokenCircuitCurrentLimit := DINT#30, Under current 30 mA S_i_OverCurrentLimit := DINT#300, // Over current 300 mA S_i_DiagnosticDelay := EPEC_HW.Constants.G_DIGITAL_OUTPUT_DIAGNOSTIC_DELAY, i_pEventCode := ADR(PIN_1_32_DO_EC) );
|
Safety Code: |
PIN_1_32_DO_ECO( i_Enable := TRUE, S_i_DOControl := PIN_1_32_DO_Control, i_OutputCurrent := X1_32_CurrentFeedback, i_OverCurrentProtectionStatus := X1_32_Overcurrent, i_DOStatus:=X1_32_DOS, o_PWMRatio => X1_32_PWM_Ratio, o_Status => PIN_1_32_DO_Status );
|
Source file topic100440.htm
Last updated 21-Feb-2025