This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Simatic S7 SCL reference: Counters ====== Back to reference overview: [[de:s7:scl_reference|Simatic S7 SCL reference with examples]] ===== IEC Counters ===== 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: [[de:s7:scl_reference_timers#iec_timers|IEC Timers]]. ===== CTU: Count up ===== {{anchor:ctu}} 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 [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#usint|USINT]] * CTU_INT / CTU_UINT: the calculation goes with the variable types [[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#uint|UINT]] * CTU_DINT / CTU_UDINT: the calculation goes with the variable types [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#udint|UDINT]] * CTU_LINT / CTU_ULINT: the calculation goes with the variable types [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#ulint|ULINT]] (only on S7-1500 PLC) \\ \\ |< 100% 15% 15% 15%>| |<color white/orange>[[de:s7:tia_knowhow#fb|_FB_]]</color> **CTU (**| | | | | |<color blue>**CU:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Counter signal:** The function monitors the positive edge of this binary signal. The counter counted, if signal change from "FALSE" to "TRUE".| | |<color blue>**R:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Reset:** Reset CV value.| | |<color blue>**PV:**</color> [[de:s7:tia_datatypes#int|INT]] **,** |input|**Set value to Q:** Value at which the Q output is set| | |<color blue>**Q:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|output|**Result:** When the counter reaches "PV".| | |<color blue>**CV:**</color> \\ [[de:s7:tia_datatypes#int|INT]] / \\ [[de:s7:tia_datatypes#char|CHAR]] / \\ [[de:s7:tia_datatypes#wchar|WCHAR]] / \\ [[de:s7:tia_datatypes#date|DATE]] |output|**Current counter value**| |**);**|||| ==== Example ==== {{:de:s7:ctu_example.png|CTU example}} <WRAP center round download 80%> The example program below can be downloaded here: {{ :de:s7:ctu_example.scl |ctu_example.scl}}. \\ \\ Here is a description of how to import the downloaded program to the TIA Portal: [[de:s7:tia_knowhow#import|Import source code to the TIA portal]]. </WRAP> ===== CTD: Count down ===== {{anchor:ctd}} 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 [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#usint|USINT]] * CTD_INT / CTD_UINT: the calculation goes with the variable types [[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#uint|UINT]] * CTD_DINT / CTD_UDINT: the calculation goes with the variable types [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#udint|UDINT]] * CTD_LINT / CTD_ULINT: the calculation goes with the variable types [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#ulint|ULINT]] (only on S7-1500 PLC) \\ \\ |< 100% 15% 15% 15%>| |<color white/orange>[[de:s7:tia_knowhow#fb|_FB_]]</color> **CTD (**| | | | | |<color blue>**CD:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Counter signal:** The function monitors the positive edge of this binary signal. The counter downcounted, if signal change from "FALSE" to "TRUE".| | |<color blue>**LD:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Reset:** Load PV value to CV. (Counter newstart)| | |<color blue>**PV:**</color> [[de:s7:tia_datatypes#int|INT]] **,** |input|**Downcounter start value:** The value from which the counter counts down. It can be reloaded with the LD parameter.| | |<color blue>**Q:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|output|**Result:** If the current counter value is less than or equal to zero, the parameter is set to signal state "TRUE".| | |<color blue>**CV:**</color> \\ [[de:s7:tia_datatypes#int|INT]] / \\ [[de:s7:tia_datatypes#char|CHAR]] / \\ [[de:s7:tia_datatypes#wchar|WCHAR]] / \\ [[de:s7:tia_datatypes#date|DATE]] |output|**Current counter value**| |**);**|||| ==== Example ==== {{:de:s7:ctd_example.png|CTD example}} <WRAP center round download 80%> The example program below can be downloaded here: {{ :de:s7:ctd_example.scl |ctd_example.scl}}. \\ \\ Here is a description of how to import the downloaded program to the TIA Portal: [[de:s7:tia_knowhow#import|Import source code to the TIA portal]]. </WRAP> ===== CTUD: Count up ===== {{anchor:ctud}} 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 [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#usint|USINT]] * CTUD_INT / CTUD_UINT: the calculation goes with the variable types [[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#uint|UINT]] * CTUD_DINT / CTUD_UDINT: the calculation goes with the variable types [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#udint|UDINT]] * CTUD_LINT / CTUD_ULINT: the calculation goes with the variable types [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#ulint|ULINT]] (only on S7-1500 PLC) \\ \\ |< 100% 15% 15% 15%>| |<color white/orange>[[de:s7:tia_knowhow#fb|_FB_]]</color> **CTUD (**| | | | | |<color blue>**CU:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Counter up signal:** The function monitors the positive edge of this binary signal. The counter counted up, if signal change from "FALSE" to "TRUE".| | |<color blue>**CD:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Counter down signal:** The function monitors the positive edge of this binary signal. The counter downcounted, if signal change from "FALSE" to "TRUE".| | |<color blue>**R:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Reset upcounter:** Reset upcounter CV value.| | |<color blue>**LD:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|input|**Reset downcounter:** Load PV value to CV. (Downcounter newstart)| | |<color blue>**PV:**</color> [[de:s7:tia_datatypes#int|INT]] **,** |input|**Set 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.| | |<color blue>**QU:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|output|**Result:** When the counter reaches "PV".| | |<color blue>**QD:**</color> [[de:s7:tia_datatypes#bool|BOOL]] **,**|output|**Result:** If the current counter value is less than or equal to zero, the parameter is set to signal state "TRUE".| | |<color blue>**CV:**</color> \\ [[de:s7:tia_datatypes#int|INT]] / \\ [[de:s7:tia_datatypes#char|CHAR]] / \\ [[de:s7:tia_datatypes#wchar|WCHAR]] / \\ [[de:s7:tia_datatypes#date|DATE]] |output|**Current counter value**| |**);**|||| de/s7/scl_reference_counters.txt 2022/04/21 15:01()