Counter data retention after a RUN-STOP-RUN transition or a CPU power cycle
If a run mode session is ended with stop mode or a CPU power cycle and a new run mode
session is started, then the counter data stored in the previous run mode session is lost,
unless the counter data structure is specified as retentive (CTU, CTD, and CTUD counters).
When you accept the defaults in the call options dialog after you place a counter instruction
in the program editor, you are automatically assigned an instance DB which cannot be made
retentive. To make your counter data retentive, you must either use a global DB or a Multi-
instance DB.
Assign a global DB to store counter data as retentive data
This option works regardless of where the counter is placed (OB, FC, or FB).
1. Create a global DB:
– Double-click "Add new block" from the Project tree
– Click the data block (DB) icon
– For the Type, choose global DB
– If you want to be able to select individual items in this DB as retentive, be sure the
– Click OK
2. Add counter structure(s) to the DB:
– In the new global DB, add a new static tag using one of the counter data types. Be
– In the "Retain" column, check the box so that this structure will be retentive.
– Repeat this process to create structures for all the counters that you want to store in
– Rename the counter structures if desired.
3. Open the program block for editing where you want to place a retentive counter (OB, FC,
or FB).
4. Place the counter instruction at the desired location.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
symbolic-access-only box is checked.
sure to consider the Type you want to use for your Preset and Count values.
this DB. You can either place each counter structure in a unique global DB, or you can
place multiple counter structures into the same global DB. You can also place other
static tags besides counters in this global DB. Placing multiple counter structures into
the same global DB allows you to reduce your overall number of blocks.
Basic instructions
8.3 Counter operations
247