de:s7:scl_reference_counters

Simatic S7 SCL reference: Counters

Back to reference overview: Simatic S7 SCL reference with examples

Counters - similar to IEC times - can be called in two ways, embedded or with a separate DB. I don't feel like describing this separately, please take a look at the times: IEC Timers.

The function that only counts upwards.

The CTU counts the positive edges of the „CU:“ parameter. As soon as it reaches the value of „PV“ with the calculation, the output „Q“ changes to „TRUE“. The function continues to count. The function can be restarted with the „R“ input.

CTU types:

  • CTU_SINT / CTU_USINT: the calculation goes with the variable types SINT, USINT
  • CTU_INT / CTU_UINT: the calculation goes with the variable types INT, UINT
  • CTU_DINT / CTU_UDINT: the calculation goes with the variable types DINT, UDINT
  • CTU_LINT / CTU_ULINT: the calculation goes with the variable types LINT, ULINT (only on S7-1500 PLC)



_FB_ CTU (
CU: BOOL ,inputCounter signal: The function monitors the positive edge of this binary signal. The counter counted, if signal change from „FALSE“ to „TRUE“.
R: BOOL ,inputReset: Reset CV value.
PV: INT , inputSet value to Q: Value at which the Q output is set
Q: BOOL ,outputResult: When the counter reaches „PV“.
CV:
INT /
CHAR /
WCHAR /
DATE
outputCurrent counter value
);

CTU example

The example program below can be downloaded here: ctu_example.scl.

Here is a description of how to import the downloaded program to the TIA Portal: Import source code to the TIA portal.

The function that only counts downwards.

The CTD counts the positive edges of the „CD“ parameter, the current counter value of the CV parameter is decremented by one. The function can be restarted with „LD“ input, in this case, the countdown starts again from the „PV“ value. If the current counter value is less than or equal to zero, the „Q“ parameter is set to signal state „TRUE“.

CTD types:

  • CTD_SINT / CTD_USINT: the calculation goes with the variable types SINT, USINT
  • CTD_INT / CTD_UINT: the calculation goes with the variable types INT, UINT
  • CTD_DINT / CTD_UDINT: the calculation goes with the variable types DINT, UDINT
  • CTD_LINT / CTD_ULINT: the calculation goes with the variable types LINT, ULINT (only on S7-1500 PLC)



_FB_ CTD (
CD: BOOL ,inputCounter signal: The function monitors the positive edge of this binary signal. The counter downcounted, if signal change from „FALSE“ to „TRUE“.
LD: BOOL ,inputReset: Load PV value to CV. (Counter newstart)
PV: INT , inputDowncounter start value: The value from which the counter counts down. It can be reloaded with the LD parameter.
Q: BOOL ,outputResult: If the current counter value is less than or equal to zero, the parameter is set to signal state „TRUE“.
CV:
INT /
CHAR /
WCHAR /
DATE
outputCurrent counter value
);

CTD example

The example program below can be downloaded here: ctd_example.scl.

Here is a description of how to import the downloaded program to the TIA Portal: Import source code to the TIA portal.

The function that counts up- and downwards.

The CTUD counts up the positive edges of the „CU“ input, and counts down with „CD“ input. As soon as it reaches the value of „PV“ with the calculation, the output „QU“ changes to „TRUE“. The function continues to count. The function can be restarted with the „R“ input. The downcounts function can be restarted with „LD“ input, in this case, the countdown starts again from the „PV“ value. If the current counter value is less than or equal to zero, the „QD“ parameter is set to signal state „TRUE“.

CTUD types:

  • CTUD_SINT / CTUD_USINT: the calculation goes with the variable types SINT, USINT
  • CTUD_INT / CTUD_UINT: the calculation goes with the variable types INT, UINT
  • CTUD_DINT / CTUD_UDINT: the calculation goes with the variable types DINT, UDINT
  • CTUD_LINT / CTUD_ULINT: the calculation goes with the variable types LINT, ULINT (only on S7-1500 PLC)



_FB_ CTUD (
CU: BOOL ,inputCounter up signal: The function monitors the positive edge of this binary signal. The counter counted up, if signal change from „FALSE“ to „TRUE“.
CD: BOOL ,inputCounter down signal: The function monitors the positive edge of this binary signal. The counter downcounted, if signal change from „FALSE“ to „TRUE“.
R: BOOL ,inputReset upcounter: Reset upcounter CV value.
LD: BOOL ,inputReset downcounter: Load PV value to CV. (Downcounter newstart)
PV: INT , inputSet value to Q / startpoint for downcounter Value at which the Q output is set / The value from which the counter counts down. It can be reloaded with the LD parameter.
QU: BOOL ,outputResult: When the counter reaches „PV“.
QD: BOOL ,outputResult: If the current counter value is less than or equal to zero, the parameter is set to signal state „TRUE“.
CV:
INT /
CHAR /
WCHAR /
DATE
outputCurrent counter value
);
  • de/s7/scl_reference_counters.txt
  • 2022/04/21 15:01
  • ()