S7-1200 Counter Logic

by Antigravity

CTU: Count Up (SFB 0)

HMI Panel

Current Val (%MW12) 0
Output (%Q0.0)
Network 1: Count Up Logic
%I0.0
--| |--
%I0.1
%MW10
= 5
CTU
CU
R
PV
Q
CV
%Q0.0
--( )--
%MW12
= 0

Timing Diagram (Operation of CTU)

How CTU Works (S7-1200): The CTU counter counts up by 1 when the value of parameter CU changes from 0 to 1.

• If the value of parameter CV (current count value) is greater than or equal to the value of parameter PV (preset count value), then the counter output parameter Q = 1.
• If the value of the reset parameter R changes from 0 to 1, then the current count value is reset to 0.

CTD: Count Down (SFB 1)

HMI Panel

Current Val (%MW16) 0
Output (%Q0.1)
Network 2: Count Down Logic
%I0.2
--| |--
%I0.3
%MW14
= 5
CTD
CD
LD
PV
Q
CV
%Q0.1
--( )--
%MW16
= 0

Timing Diagram (Operation of CTD)

How CTD Works (S7-1200): The CTD counter counts down by 1 when the value of parameter CD changes from 0 to 1.

• If the value of parameter CV (current count value) is less than or equal to zero (0), then the counter output parameter Q = 1.
• If the value of the load parameter LD changes from 0 to 1, then the current count value is loaded with the Preset Value (PV).

CTUD: Count Up and Down (SFB 2)

HMI Panel

Current Val (%MW20) 0
QU (%Q0.2)
QD (%Q0.3)
Network 3: Count Up and Down Logic
%I0.4
--| |--
%I0.5
--| |--
%I0.6
%I0.7
%MW18
= 4
CTUD
CU
CD
R
LD
PV
QU
QD
CV
%Q0.2
--( )--
%Q0.3
--( )--
%MW20
= 0

Timing Diagram (Operation of CTUD)

How CTUD Works (S7-1200): The CTUD counter counts up or down by 1 on the 0 to 1 transition of the CU or CD inputs.

• If CV >= PV, output QU = 1.
• If CV <= 0, output QD=1.
• If LOAD changes to 1, CV is loaded with PV.
• If R changes to 1, CV is reset to 0.
Note: As per Siemens specs, data is lost after a CPU power cycle unless the instance DB is set to retentive.