DebouncedInputUM
- Namespace
- ZEquipment
- Implements
FUNCTION_BLOCK DebouncedInputUM IMPLEMENTS ZEquipment.IDebouncedInput, ZEquipment.IDigital, ZCore.IUnmanagedObject, ZCore.ITrigger (
[output] Diagnostics : ZCore.DiagnosticMessage)
This function block represents a single digital input, and has basically the same functionality as DigitalInput However, the DebouncedInput function block adds debouncing functionality to the common input, all other functions regarding simulation or triggering edges are the same.
Basically this input returns with Enabled=TRUE if the actual input is enabled for at least the enable time which is set in initialization or with the SetDebouncingDuration(enabledDebouncingTime:=2.0, disabledDebouncingTime:=2.0) method. For the Enabled=FALSE signal the input has to be disabled for at least the disable debouncing time.
The logic of the input can also be specified during initialization or any time in the application. This can either be normal (value in the PLC is the same as on the terminal) or inverted (value in the PLC is the opposite as the one on the input terminal). Also the debouncing times can be set during initialization. One for the HIGH signal and one for the LOW signal.
The debouncing times can also be set dynamically in the application with SetDebouncingDuration(enabled:=2.0, disabled:=2.0) In simulation mode the enable method writes to the simulated input and therefore the parameterized states are also handled correctly.
Note
By default instances are simulated. In order to make use of a physical terminal, the method SetSimulation(on:=FALSE) has to be called.
PROGRAM MAIN
VAR
DebInput : ZEquipment.DebouncedInputUM(debouncingTime:=0.5);
Step : UINT;
END_VAR
------------------------
DebInput.Cyclic();
CASE Step OF
0:
DebInput.SetDebouncingDuration(enabled:=0.5, disabled:=0.6);
DebInput.SetName('Button Start');
Step := 10;
10:
IF DebInput.IsEnabled THEN
Step := 20;
END_IF
20:
;
END_CASE
Outputs
Diagnostics
DiagnosticMessage
Constructor
FB_init
METHOD FB_init (
[input] bInitRetains : BOOL,
[input] bInCopyCode : BOOL,
[input] debouncingTime : LREAL) : BOOL
Inputs
bInitRetains
BOOLif TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode
BOOLif TRUE, the instance afterwards gets moved into the copy code (online change)
debouncingTime
LREALsymmetric debouncing time in seconds, use SetDebouncingDuration for more options
Returns
- BOOL
Properties
DebouncingDurationDisabled
PROPERTY DebouncingDurationDisabled : LREAL
Property Value
- LREAL
DebouncingDurationEnabled
PROPERTY DebouncingDurationEnabled : LREAL
Property Value
- LREAL
Enabled
PROPERTY Enabled : BOOL
This property returns the actual state of the debounced input as boolean. It respects the configured logic and debounced times.
The fieldbus state is the actual value that is represented by your terminal. The software logic of this input can be changed at any time in an application and defaults to Normal. The logic table that links the terminal state to the software state is as follows. See DigitalLogic for details.
Property Value
- BOOL
Simulation
PROPERTY Simulation : BOOL
Every input is able to simulate its behaviour. With activated simulation the function block internally uses a software state-variable and ignores the terminal that has been linked to the function block. With this property the simulation state of the DebouncedInput can be set or retrieved if it is simulated or not.
Property Value
- BOOL
Methods
Cyclic
METHOD Cyclic ()
Enable
METHOD Enable (
[input] on : BOOL)
This method enables the actual input or output which means different states depending on the initialised logic The method is only relevant if the hardward is simulated. It immediately changes the state of the debounced input, ignoring the debouncing durations that have been configured for this instance. For physical inputs no state is changed.
Inputs
FallingTrigger
METHOD FallingTrigger () : BOOL
Consecutive calls to this method returns TRUE
whenever the state of the digital interface switched from IsEnabled
to NOT IsEnabled
.
It is the same as using a FallingTrigger instance or using an F_TRIG
instance on Enabled.
Since Enabled respects the debouncing times,
so does this method.
IF debouncedInput.FallingTrigger()
THEN
// ...
END_IF
<h4 class="section">Returns</h4>
<dl class="parameters">
<dt>BOOL</dt>
<dd></dd>
</dl>
<h3 id="ZEquipment_DebouncedInputUM_HasTriggered" data-uid="ZEquipment.DebouncedInputUM.HasTriggered">
HasTriggered
</h3><a name="HasTriggered"></a>
<div class="codewrapper">
<pre><code class="lang-st hljs">METHOD HasTriggered () : BOOL
</code></pre></div>
Depending on the logic set with [SetTriggerLogic](xref:ZEquipment.DebouncedInputUM#SetTriggerLogic) this method
internally calls [RisingTrigger](xref:ZEquipment.DebouncedInputUM#RisingTrigger) or [FallingTrigger](xref:ZEquipment.DebouncedInputUM#FallingTrigger) and
returns its output.
By default this method is the same as calling [FallingTrigger](xref:ZEquipment.DebouncedInputUM#FallingTrigger).
<h4 class="section">Returns</h4>
<dl class="parameters">
<dt>BOOL</dt>
<dd></dd>
</dl>
<h3 id="ZEquipment_DebouncedInputUM_Invert" data-uid="ZEquipment.DebouncedInputUM.Invert">
Invert
</h3><a name="Invert"></a>
<div class="codewrapper">
<pre><code class="lang-st hljs">METHOD Invert ()
</code></pre></div>
The method is only relevant if the hardward is simulated. It immediately changes the state of the debounced input, ignoring
the debouncing durations that have been [configured](xref:ZEquipment.DebouncedInputUM#Enable) for this instance.
For physical inputs no state is changed.
It is the equivalent to
```st
debouncedInput.Enable(NOT debouncedInput.IsEnabled);
IsInputEnabled
METHOD IsInputEnabled () : BOOL
This method returns the actual state of the terminal as boolean. Here debouncing times are by-passed considered. While debouncing times are ignored by this method, the configured logic is respected. For details refer to Enabled or DigitalLogic.
Returns
- BOOL
Name
METHOD FINAL Name () : ZCore.ZString
This method return the name that has been set with SetName. The name is considered when writing messages to the log.
Returns
RisingTrigger
METHOD RisingTrigger () : BOOL
Consecutive calls to this method returns TRUE
whenever the state of the digital interface switched from IsEnabled
to NOT IsEnabled
.
It is the same as using a RisingTrigger instance or using an F_TRIG
instance on Enabled.
IF digitalInput.RisingTrigger()
THEN
// ...
END_IF
Returns
- BOOL
SetDebouncingDuration
METHOD SetDebouncingDuration (
[input] enabled : LREAL,
[input] disabled : LREAL)
This method sets the debouncing times for each state change.
Calling Enabled will only return TRUE
, if the actual input from the terminal is "stable", which
means that the state did not change for enabled
seconds or disabled
seconds, repectively. Note that the latter states refer
to the logic of the software-state, which is configured by calling SetLogic.
Note
Setting a duration to 0 is not completely the same than simply using a DigitalInput. Since this function blocks updates its internal state through calls to its cyclic method, The shortest duration is the cycle time of the PLC. Thus, when using this function block with duration=0 maybe consider to use the simpler DigitalInput function block instead.
Inputs
enabled
LREALtime in seconds for the stable enabled state (TRUE)
disabled
LREALtime in seconds for the stable disabled state (FALSE)
SetLogger
METHOD SetLogger (
[input] logger : ZCore.ILogger)
Setting a Logger with this method enables the logging functionality of the DebouncedInput function block.
Leaving the IO without logger will not create any log entry and is sometimes, depending on your performance requirements useful. However, the behaviour can also be changed during running of the PLC by changing the LogLevel.
Note
To change the logging behaviour it is sometimes useful to inject a LoggerNameDecorator here.
Inputs
logger
ILoggerinterface of a logger instance or a logger decorator instance
SetLogic
METHOD SetLogic (
[input] logic : DigitalLogic)
According to the process or the used hardware some signals on the fieldbus are high or low active, but in the PLC it is benefical to have these states inverted. This method allows to switch the logic that this class is operating with. Note that almost all methods of the digital make use of the logic that can be set here. (i.e. RisingTrigger, FallingTrigger, Enable, ...).
Inputs
logic
DigitalLogiclogic of the input, available types normal and inverted
SetName
METHOD SetName (
[input] name : ZCore.ZString)
Sets the name of this object as it will show up in any log messages that is created by this object. The name set with this method should be relatable to the name of the input in the electrical plan of your automation project to identify the corresponding input properly. However, please note that logging should not be used for inputs because some of them are switched very often, which leads to a high logging load.
Inputs
name
ZStringname of the input, should not be longer than 30 characters
SetSimulation
METHOD SetSimulation (
[input] on : BOOL)
By default all digital interfaces that extend from this function block are simulated, to disable simulation mode this can be done by this method. Usually, the decision if simulation is used, takes places during initialization phase. However, some applications require to switch between these modes on-the-fly. In the latter case simply call this method at any time.
Inputs
SetTriggerLogic
METHOD SetTriggerLogic (
[input] logic : DigitalLogic)
This method controls the logic of the HasTriggered method. By default, the trigger logic is set to Normal.
Inputs
logic
DigitalLogiclogic of the input or output, available types normal and inverted