DEBOUNCE (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


DEBOUNCE is a function block that will debounce a signal on both the active and inactive state. This is especially useful on noisy digital input signals that are driven by switches, relays etc. that can generate switch noise when switched on or off.

 

Note: this function block uses 2 TON function blocks.

 

Input:

in : BOOL (true/false)

This is the signal that will be debounced.

 

db_time : DINT (0..2147483648)

The number of milliseconds the signal must be active/inactive before the state is considered valid.

         

Output:

out : BOOL (true/false)

The "in" signal after debounce. It is also free from noises that are shorter than the time defined in "db_time".

 

Declaration:

FUNCTION_BLOCK Debounce;
VAR_INPUT
  in     : BOOL; | The signal that is to be debounced
  db_time : DINT; | The number of milliseconds the 'in' signal must be stable
END_VAR;
VAR_OUTPUT
  out     : BOOL; | The debounced 'in' signal
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  input1 : BOOL; | Digital input
END_VAR;
 
VAR_OUTPUT
  signal : BOOL; | Noise-free output
END_VAR;
 
VAR
  deb : Debounce; // Declare an instance of the DEBOUNCE functionblock
END_VAR;
 
PROGRAM test;
 
deb(db_time:=100); // Set debounce time to 100 milliseconds
 
BEGIN
  deb(in:= input1); // Input the 'input1' signal to the debounce functionblock
  signal := deb.out; // output will follow the 'input1', but without noise
END;
END_PROGRAM;