CTU (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


CTU is an Up counter. This function block will increment the "cv" value with one on each rising edge on the "cu" input. When the "cv" variable reaches "pv", or is above, the output "q" will go high - otherwise it will be low. If a high signal is present on the "r" input, the counter will be reset ("cv" will be set to 0).

 

Input:

cu : BOOL (true/false)

On the leading edge of this input, the "cv" will be incremented with 1. When the "cv" value is equal to, or above, the value for "pv", "q" will be high.

 

r : BOOL (true/false)

Reset input. When this input is high, the counter value will be kept at 0.

 

pv : INT (0..32767)

Preset value for the counter.

         

Output:

cv : INT (-32768..32767)

The current value of the counter.

 

q : BOOL (true/false)

Output from the counter. See description for "cu".

 

Declaration:

FUNCTION_BLOCK CTU;
VAR_INPUT
  cu : BOOL R_EDGE; | Signal that increments the counter by 1 on a rising edge
  r : BOOL;       | Signal that sets 'cv' to 0 when high
  pv : INT;       | Preset value for the counter
END_VAR;
VAR_OUTPUT
  q : BOOL;       | Output from counter
  cv : INT;       | Current counter value          
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  input1 : BOOL; | Input that will reset the counter
  input2 : BOOL; | Input that will increment the counter with one on a rising edge
END_VAR;
 
VAR_OUTPUT
  signal : BOOL; | Output that will follow the q output from the counter
END_VAR;
 
VAR
  counter : CTU; // Declare an instance of the CTU functionblock
END_VAR;
 
PROGRAM test;
 
BEGIN
  // Call the counter, and assign its input variables
  counter(
          pv := 100,   // Preset value for the counter
          r := input1, // The counter will be reset when input1 is high
          cu := input2 // The counter will increment 'cv' with 1 when rising edge on input2
        );
 
  signal:=counter.q; // The output signal will go high when the counter reaches 'pv'
END;
END_PROGRAM;