CTD (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


CTD is a Down counter. This function block will count the "cv" value one down on each rising edge on the "cd" input. When the "cv" variable reaches 0, the output "q" will go high - otherwise it will be low. If a high signal is present on the "ld" input, the value from "pv' will be copied to "cv".

 

Input:

cd : BOOL (true/false)

On the leading edge of this input the "cv" will be decremented with 1. When the "cv" value is equal to 0, "q" will be high

 

ld : BOOL (true/false)

Load input. When this input is high, the "cv" will set to the value in "pv".

 

pv : INT (0..32767)

Preset value for the counter.

         

Output:

cv : INT (0..32767) Default -1

The current value of the counter.

 

q : BOOL (true/false)

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

 

Declaration:

FUNCTION_BLOCK CTD;
VAR_INPUT
  cd : BOOL R_EDGE; | Signal that decrements the counter by 1 on a rising edge
  ld : BOOL;       | Signal that sets 'cv' to the value in 'pv' 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 load the counter with the preset value
  input2 : BOOL; | Input that will decrement 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 : CTD; // Declare an instance of the CTD functionblock
END_VAR;
 
PROGRAM test;
 
BEGIN
  // Call the counter, and assign its input variables
  counter(
          pv := 100,   // Preset value for the counter
          ld := input1, // The counter will be loaded with the preset value when input1 is high
          cd := input2 // The counter will decrement 'cv' with 1 when rising edge on input2
        );
 
  signal:=counter.q; // The output signal will go high when the counter reaches 0
END;
END_PROGRAM;