I want to use a global method to debounce digital inputs by passing the IO and the desired debounce time to the method and using the returnvalue to set the Bool-Variable. The Method itself is working but I need to instantiate the function block for every input. I would like to further optimize by eliminating the need of instantiation.
Is there a possibility to configure the functionblock/method in order that the runtime allocates the memory and instantiates the method whenever it is being called?
METHOD NO : BOOL
VAR_INPUT
IN : BOOL;
T : TIME;
END_VAR
VAR_INST
_timer : TON;
END_VAR
_timer (IN := IN, PT := T);
IF _timer.Q
THEN
NO := TRUE;
ELSIF _timer.ET < T
THEN
RETURN;
ELSE
NO := FALSE;
END_IF
Call:
debouncedInput := debounce.NO(digitalInput, T#500MS);
where "Debounce" is the local instance of the funtion block.
Thanks in advance for constructive answers.