Supported platforms: CODESYS 3.5 SP19 SAFETY
S_HBridgeControllerDO POU implements logic to control and diagnose H-Bridge with DO signals. It can be used to control for example electric motor or linear actuator.
|
POU can be used with DO pins which gives possibility to control both pin high and low side. |
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:
|
|
Do not call Init method when control is active. |
Parameter |
Type |
Unit |
Range |
Description |
S_i_OverCurrentLimit |
SAFEUINT |
mA |
- |
Limit for overcurrent diagnostic. |
S_i_CurrentDiagnosticDelay |
SAFEUINT |
ms |
- |
Diagnostic delay for current diagnostic |
S_i_ControlStopDelay |
SAFEUINT |
ms |
- |
Delay time for waiting motor/actuator stop. |
i_pEventCode |
POINTER TO EventCode |
- |
≠ 0 |
Pointer to application variable where event code is stored. |
TRUE: All initialization parameters ok. |
FALSE: Error in initialization parameter(s). |
POU is in normal operation mode if
• The control is enabled, i.e. i_Enable is TRUE AND no error diagnosed.
In normal operation DO outputs are controlled according to control request signals S_i_Forward and S_i_Backward, see table below.
S_i_Forward |
S_i_Backward |
Motor/Actuator Control Direction |
Pin1 HS DO | Pin2 HS DO | Pin1 LS DO | Pin2 LS DO |
FALSE | FALSE |
- |
FALSE | FALSE | FALSE | FALSE |
TRUE |
FALSE |
Forward |
TRUE | FALSE | FALSE | TRUE |
FALSE |
TRUE |
Backward |
FALSE | TRUE | TRUE | FALSE |
TRUE | TRUE | - | FALSE | FALSE | FALSE | FALSE |
POU's internal state machinePOU's internal state machine
Internally POU has state machine of type HBridgeStates.
State |
Description |
Idle | S_i_Forward = FALSE andS_i_Backward = FALSE. DO outputs are set FALSE. |
StartControl |
|
Control |
Control continues until control request is reset, control direction changes or any error occurs. |
EndControl |
Diagnostic is disabled in this state, because running motor may induce electricity to outputs and cause unnecessary alarms. |
Error | Error is diagnosed. DO outputs are set FALSE. |
ControlDisabled | Control is disabled. see Control_disabled_reasons |
* Pin pair: If pin 1 HS DO is controlled, the pin pair is pin 2. If pin 2 HS DO is controlled, the pin pair is pin 1.
Conditions |
DO outputs |
o_Status. OutputValid |
o_Status error status |
Event code FunctionID |
Event code EventID |
i_Enable = TRUE AND |
FALSE |
FALSE |
ParameterError |
- |
- |
i_Enable rises AND (S_i_Forward OR S_i_Backward is TRUE) |
FALSE |
FALSE |
StartupError |
H_BRIDGE |
STARTUP_ERROR |
i_Enable = TRUE AND (i_Pin1OverCurrentProtectionStatus OR i_Pin2OverCurrentProtectionStatus is TRUE) |
FALSE |
FALSE |
Pin1OverCurrent/ Pin2OverCurrent |
H_BRIDGE |
OVER_CURRENT |
i_Enable = TRUE AND (i_Pin1Current OR i_Pin2Current < 0) |
FALSE |
FALSE |
InputLow |
H_BRIDGE |
INPUT_TOO_LOW |
i_Enable = TRUE AND S_i_Forward = TRUE AND S_i_Backward = TRUE |
FALSE |
FALSE |
ParameterError |
H_BRIDGE |
PARAMETER_ERROR |
i_Enable = TRUE AND (i_Pin1DOStatus OR i_Pin2DOStatus is FALSE when the corresponding output is controlled) |
FALSE |
FALSE |
Pin1ShortToGround/ Pin2ShortToGround1 |
H_BRIDGE1 |
VOLTAGE_SHORTCUT1 |
i_Enable = TRUE AND (i_Pin1DOStatus OR i_Pin2DOStatus is TRUE when the corresponding output is not controlled) |
FALSE |
FALSE |
Pin1ExternalVoltage/ Pin2ExternalVoltage1 |
H_BRIDGE1 |
EXTERNAL_VOLTAGE1 |
i_Enable = TRUE AND (i_Pin1Current OR i_Pin2Current > G_HBRIDGE_CURRENT_LIMIT_CONTROL_OFF (HW specific constant) when the corresponding output is not controlled) |
FALSE |
FALSE |
Pin1CurrentLeak/ Pin2CurrentLeak2 |
H_BRIDGE2 |
OVER_CURRENT2 |
i_Enable = TRUE AND (i_Pin1Current OR i_Pin2Current > S_i_OverCurrentLimit) |
FALSE |
FALSE |
Pin1OverCurrent/ Pin2OverCurrent2 |
H_BRIDGE2 |
OVER_CURRENT2 |
1) After voltage diagnostic delay (60 ms) is elapsed. Note! Diagnostic is disabled when o_BridgeState = EndControl.
2) After diagnostic delay S_i_CurrentDiagnosticDelay is elapsed. Note! Diagnostic is disabled when o_BridgeState = EndControl.
The o_Status error bits and EventCode error are not reset before the rising edge of i_Enable input.
Input variable name |
Data type |
Range |
Description |
i_Enable |
BOOL |
|
Enable POU operation |
S_i_Forward |
BOOL |
|
Run motor forward |
S_i_Backward | BOOL | Run motor backward | |
i_Pin1DOStatus | BOOL | Pin 1 output digital status (DOS) | |
i_Pin2DOStatus | BOOL | Pin 2 output digital status (DOS) | |
i_Pin1Current | BOOL | Measured pin 1 current (mA) | |
i_Pin2Current | BOOL | Measured pin 2 current (mA) | |
i_Pin1OverCurrentProtectionStatus | BOOL | Pin 1 overcurrent status from FW | |
i_Pin2OverCurrentProtectionStatus | BOOL | Pin 2 overcurrent status from FW |
Output variable name |
Data type |
Range |
Description |
o_Pin1HsDO |
BOOL |
|
Pin 1 high side DO control |
o_Pin2HsDO |
BOOL |
|
Pin 2 high side DO control |
o_Pin1LsDO | BOOL | Pin 1 low side DO control | |
o_Pin2LsDO | BOOL | Pin 2 low side DO control | |
o_Status | Status | Status of control outputs | |
o_BridgeState | HBridgeStates | Bridge control sequence state | |
o_Forward | BOOL | Motor/Actuator forward control active | |
o_Backward | BOOL | Motor/Actuator backward control active |
|
o_BridgeState value Error indicates error state. Check o_Status output to identify error.
Control can be retried after resetting POU i.e. set input i_Enable to false and then true. |
Definitions: |
|
hBridgeControl: EPEC_SHB.S_HBridgeControllerDO;
// POU input variables pin1Current: DINT; // DO pin 1 measured current
|
|
Safety Code: |
IF NOT inited THEN // Call POU init method to initialize parameters. S_i_OverCurrentLimit := UINT#6000, S_i_CurrentDiagnosticDelay := UINT#500, S_i_ControlStopDelay := UINT#500, i_pEventCode:= ADR(eventCode));
IF bridgeState = EPEC_SHB.HBridgeStates.ControlDisabled THEN ELSIF bridgeState = EPEC_SHB.HBridgeStates.Error THEN
|
|
Assignments to actual I/O variables is not implemented in this example. |
See also
-
Source file HBridgeControllerDO.htm
Last updated 21-Feb-2025