0% found this document useful (0 votes)
109 views27 pages

Micro1 08E Digit Operat PDF

This document section provides an overview of data types used in STEP 7 programming for SIMATIC S7-1200 controllers. It discusses elementary data types, which include basic types like BOOL, INT, DINT, REAL, and types for timing applications. Complex data types are also introduced, which allow grouping elementary types into arrays, structures, and strings. The document aims to familiarize participants with these data types and their application in acquiring, processing, and outputting digital data with the S7-1200.

Uploaded by

MiguelGonzalez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views27 pages

Micro1 08E Digit Operat PDF

This document section provides an overview of data types used in STEP 7 programming for SIMATIC S7-1200 controllers. It discusses elementary data types, which include basic types like BOOL, INT, DINT, REAL, and types for timing applications. Complex data types are also introduced, which allow grouping elementary types into arrays, structures, and strings. The document aims to familiarize participants with these data types and their application in acquiring, processing, and outputting digital data with the S7-1200.

Uploaded by

MiguelGonzalez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

SIMATIC S7-1200 Basic Course

Contents 8
8. Digital Operations .................................................................................................. 8-2
8.1. Acquiring, Processing and Outputting Data .......................................................................... 8-3
8.1.1. Overview: Data Types in STEP 7 ......................................................................................... 8-4
8.1.2. Elementary Data Types ........................................................................................................ 8-5
8.1.3. Data Types for Timers, Date and Time-of-day ..................................................................... 8-6
8.1.4. Complex Data Types ............................................................................................................ 8-7
8.1.5. Integer (INT, 16-Bit Integer) Data Type ................................................................................ 8-8
8.1.6. Double Integer (DINT, 32-Bit Integer) Data Type ................................................................. 8-9
8.1.7. REAL (Floating-point Number, 32 Bit) Data Type............................................................... 8-10
8.2. Timer / Counter Instance Data Blocks ................................................................................ 8-11
8.3. Task Description: Counting the Transported Parts ............................................................. 8-12
8.3.1. Counters: CTU, CTD, CTUD............................................................................................... 8-13
8.3.2. Counter Function: Inputs..................................................................................................... 8-14
8.3.3. Counter Function: Outputs .................................................................................................. 8-15
8.3.4. Exercise 1: Counting the Transported Parts Commissioning "FC_Count" (FC18)......... 8-16
8.4. Task Description: Monitoring the Transport Sequences for Time .................................. 8-17
8.4.1. Timer Function TON ........................................................................................................... 8-18
8.4.2. Timer Function TON (ON Delay) Pulse Diagram................................................................ 8-19
8.4.3. Exercise 2: Monitoring the Transports for Time Commissioning "FC_Fault" (FC17) ..... 8-20
8.5. Additional Information ......................................................................................................... 8-21
8.5.1. Additional Exercise 3: Counting the Conveyor Faults - Expanding "FC_Fault" (FC17) .. 8-22
8.5.2. Additional Exercise 4: Timely Lock-out of the Conveyor Motor Jogging ............................ 8-23
8.5.3. Move Operations: MOVE .................................................................................................... 8-24
8.5.4. Move Operations: MOVE_BLK ........................................................................................... 8-25
8.5.5. Comparator Operations: IN_RANGE, OUT_RANGE ......................................................... 8-26
8.5.6. Date and Time-of-day: RD_SYS_T .................................................................................... 8-27

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-1
SIMATIC S7-1200 Basic Course

8. Digital Operations

At the end of the chapter the participant will…

... be familiar with the application purpose of data blocks

… be familiar with the S7-1200 data types

… be familiar with the different counter and timer functions

… be able to use and program counter and timer functions


and be able to select a suitable data type

TIA-MICRO1 - Digital Operations


8-2 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.1. Acquiring, Processing and Outputting Data

Operator Panel: Simulator:


Operating Pushbuttons
+ monitoring / Switches,
processes LEDs,
Voltmeter,
Potentiometer

AI/AO DI/DO

Control unit:
(e.g. S7-1200)
Processing
the values

e.g. PROFIBUS

Field devices

Binary/Digital Processing
True logic control systems are recognizable in the fact that they exclusively process binary data.
The performance of today‘s control computer, as well as tasks in the areas of data processing,
quality control, among others, has increased the importance of digital data processing using
PLCs. Digital process variables can be found in all areas of open-loop control - such as in
connected devices for process operating and monitoring or in the control of field devices.

Operating and Monitoring


The goal of process monitoring is to provide the operator with up-to-the-minute information about
the working machine or system quickly, concisely and clearly as well as the opportunity to
intervene and control and influence the process. While in the past mostly simple, that is, "dumb"
input and output devices, such as 7-segment displays and thumbwheel buttons were used to
display and enter digital values, today "intelligent" operating and monitoring devices are
frequently connected to a PLC. Depending on the type of device connected, different number
formats for the coding of data are used to transmit data between device and PLC, as well as for
storing and processing data in the PLC.

Field Devices
Today as well, field devices that acquire process data or that control the process are supplied
directly with digital variables through field bus systems. The connection of field devices, such as
drives or weighing systems, using analog input and output modules is becoming more and more
a thing of the past.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-3
SIMATIC S7-1200 Basic Course

8.1.1. Overview: Data Types in STEP 7

Elementary • Bit data types (BOOL, BYTE, WORD, DWORD, CHAR, WCHAR)
data types • Mathematical data types (INT, DINT, REAL,SINT,USINT, UINT, UDINT, LREAL)
(up to 64 bits)
• Time types (TIME, DATE, TIME_OF_DAY)

• Time type (DTL)


Complex • Array (ARRAY)
data types
• Structure (STRUCT)
• Character string (STRING, WSTRING)

User-defined
data types • PLC data type UDT (User Defined DataType)

Elementary Data Types


Elementary data types are predefined in accordance with IEC 61131-3. They always have a
length less than or equal to 64 bits and can be further processed with elementary STEP 7
instructions.

Complex Data Types


Complex data types contain data structures that can be made up of elementary and/or complex
data types. Complex data types can be used for the declaration of variables only in global data
blocks and within blocks for the declaration of local variables (TEMP, STAT) as well as
parameters (IN, OUT and INOUT).

PLC Data Types


PLC data types are data types defined by you that are used as templates for declaring
parameters and variables of complex data types (e.g. structure variables). UDTs are created with
the Data Block Editor and contain a data structure that is made up of elementary and/or complex
data types. In the declaration of a variable according to data type UDTx, a structure variable is
created whose inner data structure is defined by a UDT. UDTs can be used for the declaration of
variables in global data blocks and within blocks for the declaration of local variables (TEMP,
STAT) as well as parameters (IN, OUT and INOUT).

TIA-MICRO1 - Digital Operations


8-4 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.1.2. Elementary Data Types

Data type Length (in bits) Constants Variables

BOOL 1 1 or 0 I 1.0
BYTE 8 B#16#A9 MB70
WORD 16 W#16#12AF MW72
DWORD 32 DW#16#ADAC1EF5 QD40

CHAR 8 'w' DBB4


WCHAR (as off FW 4.1) 16 WCHAR#'a' MW50
INT 16 123 #Value
DINT 32 L#65539 MD80
REAL 32 1.2 or 34.5E-12 DBD60
SINT 8 +/-50 MB24
USINT 8 50 MB24
UINT 16 12654 IW22
UDINT 32 4875678 DBD64
LREAL 64 LREAL#1.0e-5

BOOL, BYTE, WORD, DWORD, CHAR


Variables of the data type BOOL consist of one bit. Variables of the data types BYTE, WORD,
DWORD are bit sequences of 8, 16 or 32 bits. The individual bits are not evaluated in these data
types. Special forms of these data types are the BCD numbers and the count value as it is used
in conjunction with the count function as well as the data type CHAR which represents a
character in the ASCII code and WCHAR for representing characters in the extended character
set (Format Unicode). For S7-1200, WCHAR can only be used as of FW V4.1.

INT, DINT, REAL


Variables of these data types represent numbers that can be used in mathematical operations.

Extensions of INT, DINT, REAL

U - Unsigned
Variables with the extension U represent an integer without sign.
Data types: USINT, UINT, UDINT
S - Short
Variables with the extension S represent an integer with a length of 8 bits.
Data types: SINT, USINT
L - Long
Variables with the extension L represent a number with a length of 64 bits of the data type.
Data types: LREAL

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-5
SIMATIC S7-1200 Basic Course

8.1.3. Data Types for Timers, Date and Time-of-day

Data type Length (in bits) Example

Timers

TIME 32 T#2h46m30s630ms

Date and Time-of-day

DATE 32 D#1984-01-01
TIME_OF_DAY (TOD) 32 TOD#18:15:18:999
DTL 96 DTL#1984-01-01-18:00:30:250

TIME
A variable of the data type TIME (duration in [ms]) occupies a double word. This variable is
used, for example, for specifying time values in IEC timer functions. The contents of the variable
are interpreted as a DINT number in milliseconds and can be either positive or negative (for
example: T#1s=L#1 000, T#24d20h31m23s647ms = L#2147486470).
DATE
A variable of the data type DATE is stored in a word in the form of an unsigned integer. The
contents of the variable represent the number of days since 01.01.1990 (for example: D#2003-
10-31 = W#16#13BB).
TOD
The data type TOD (TIME_OF_DAY) occupies a double word and stores the number of
milliseconds since the beginning of the day (0:00 o’clock) as an unsigned integer.
DTL
The data type DTL has a length of 12 bytes and stores information on date and time-of-day
precise to the nanosecond since 1.1.1970 in a pre-defined structure.
Advantage: the individual values (day, hour, etc.) are easier to read out.

Byte Component Data type Value range


0-1 Year UINT 1970 to 2554
2 Month USINT 1 to 12
3 Day USINT 1 to 31
1 (Sunday) to 7 (Saturday)
4 Weekday USINT
The weekday is not considered in the value entry.
5 Hour USINT 0 to 23
6 Minute USINT 0 to 59
7 Second USINT 0 to 59
8 -11 Nanosecond UDINT 0 to 999 999 999

TIA-MICRO1 - Digital Operations


8-6 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.1.4. Complex Data Types

Data type Length (in bits) Example


STRING 8 * (number of ´This is a String´
(character string with characters +2) ´SIEMENS´
max. 254 characters)

WSTRING 16 * (number of WSTRING#´A String in the extended


(character string with characters +2) format UNICODE´
max. 254 characters) (as off FW 4.1)

ARRAY User-
(Group of components defined Measured values: ARRAY[1..20] of INT
of the same data type)
STRUCT User- Motor: STRUCT
(Structure, Group of defined Speed : INT
components of different Current : REAL
data types) END_STRUCT
UDT UDT as block UDT as array element
(User Defined Data Type = User-
"Template" consisting of defined STRUCT Drive: ARRAY[1..4]
elementary or complex Speed : INT of UDT1
data types Current : REAL
END_STRUCT

Complex Data Types


Complex data types (arrays and structures) consist of groups of elementary or complex data
types.
They enable you to create data types suitable for your problem with which you can structure large
quantities of data and process it symbolically.
Complex data types cannot be processed directly with STEP 7 instructions all at once. Only one
component at a time can be processed.
The lengths of complex data types are defined by the user.
Variables with complex data types can only be declared within global data blocks and as
parameters or local variables of logic blocks.

User-defined Data Type (UDT)


User-defined data types represent self-defined structures. This structure is stored in UDT blocks
and can be used as a "template" in another variable‘s data type. You can save typing time when
you input a data block if you need the same structure several times.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-7
SIMATIC S7-1200 Basic Course

8.1.5. Integer (INT, 16-Bit Integer) Data Type

Value range -32768 to +32767 Arithmetic


(without sign: 0 to 65535) operations: e.g. + I, * I, <I, ==I

Display Formats:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: + 662 BIN.: 2# 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0 HEX: W#16 #0 2 9 6


+2
9 without
Sign 2
7
sign 0

+2
4 6 x 16 = 6
positive 2 1
numbers +2 1 9 x 16 =144
+2 2 x 16
2
= 512
+ 662 662

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: - 662 BIN.: 2# 1 1 1 1 1 1 0 1 0 1 1 0 1 0 1 0 HEX:W#16# F D 6 A


15
-2 14 without
+2 13 sign
Sign
negative +2 12 0
+2 11 10 x 16 =10
numbers 1
6 x 16 = 96
+2 10 2
8 6
+2 +2 +2 5 13 x 16 = 3328
3 1 3
Representation as +2 +2 +2 15 x 16 = 61440
Twos complement - 662 64874

Integer (16-Bit) Data Type


An Integer data type value is a whole number value, that is, a value without a decimal point.
SIMATIC S7 stores Integer data type values with sign in 16 bit code. This results in the value
range shown in the picture above. As well, SIMATIC S7 provides arithmetic operations for
processing Integer values.

Decimal
STEP7 uses the Decimal (not BCD!) display format to specify the constants of the Integer data
type with sign and without explicit format description. The use of constant Integer values in the
Binary and Hexadecimal display formats is possible in principle, but because of the poor legibility,
they are more or less not suitable. For this reason, the syntax of STEP7 provides the specification
of Integer values only in the decimal display format.

Binary
In a digital computer system, all values are stored in a binary-coded form. Only the digits 0 and 1
are available in the binary number system. Base 2 of this number system results from the number
of available digits. Accordingly, the value of every bit of a binary number results from a power of
Base 2. This is also expressed in the format specification 2#.... .
Negative values are represented as binary numbers in twos complement. In this representation,
15
the most significant bit (bit no. 15 for the Integer data type) has the value -2 . Since this value is
greater than the sum of all residual values, this bit also has the sign information. That is, if this bit
= 0, then the value is positive; if the bit is = 1, then the value is negative. The conversion of a
binary number into a decimal number is made by adding the values of the bits that have a 1 (see
picture).

Note
For UINT, bit no. 15 has the value 215 and so no negative numbers can be represented. The value
range lies between 0 and 65535.

TIA-MICRO1 - Digital Operations


8-8 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.1.6. Double Integer (DINT, 32-Bit Integer) Data Type

Value range L# -2147483648 to L#+2147483647 Operations: e.g. + D, * D, <D, ==D


(without sign: 0 to 4294967295)

Display Formats:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: L# +540809 BIN.: 2# 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1

Sign
positive
numbers

HEX: DW#16# 0 0 0 8 4 0 8 9
(without sign)

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: L# -540809 BIN.: 2# 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 1 1 1

Sign
negative
numbers

Representation as HEX: DW#16# F F F 7 B F 7 7


Twos complement
(without sign)

Double Integer (32-Bit Integer)


SIMATIC S7 stores Double Integer data type values with sign as 32 bit code. This results in the
value range shown in the picture above. As well, SIMATIC S7 provides arithmetic operations for
processing DINT values.

Decimal
STEP7 uses a decimal number (not BCD!) to specify a constant of the Double Integer data type
with sign and the format L# for "long" (double word, 32 bit). When a value smaller than -32768 or
greater than 32767 is specified, the format L# is automatically added. For negative numbers
smaller than -32768, the user must specify the format as L# - (for example: L# -1). This is
imperative if the value is to be further processed arithmetically as a double integer since you
would otherwise work with false values (value + sign)!

Hexadecimal
The hexadecimal number system provides 16 different digits (0 to 9 and A to F). This results in
Base 16 of this numbers system. Accordingly, the value of every bit of a hexadecimal number
results from a power of Base 16. Hexadecimal numbers are specified with the format W# for the
dimension (W = word = 16 bit) or DW# (DW = double word = 32 bit) and 16# for identifying the
basic numbering system. The number of specifiable bits is variable from 1 to 8 whereby missing
(unspecified) bits are filled with leading zero digits. The digits A to F correspond to the decimal
values 10 to 15. The value 15 is the last value that can be binary-coded - without sign - with 4
bits. Out of this correlation, the simple conversion of a binary number into a hexadecimal number
and vice versa can be obtained. In this way, four binary bits each can easily make up one digit of
a hexadecimal number.

Note
31
For UDINT, bit no. 31 has the value 2 , and so, just as with UINT, no negative numbers can be
represented. The value range lies between 0 and 4294967295.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-9
SIMATIC S7-1200 Basic Course

8.1.7. REAL (Floating-point Number, 32 Bit) Data Type

Value range -3.402823•10+38 to -1.175495•10-38 , 0.0, +1.175495•10-38 to +3.402823•10+38

Operations: e.g. + R, * R, <R, ==R


sin, acos, ln, exp, SQR

General format of a Real number = (Sign) • (1.f) • (2e-127)

Example: 0.75

Sign of
Real no. e = Exponent (8 Bit) f = Mantissa (23 Bit)

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
27 26 25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-23
.....

Real no. = +1.5 * 2 126-127 = 0.75

Real
The previously described INT and DINT data types are used to store whole number values with
sign. Accordingly, only operations that supply a whole number value as the result can be
performed with these values. In cases where analog process variables such as voltage, current,
and temperature have to be processed, it becomes necessary to use Real values (real numbers,
"decimal numbers"). In order to be able to represent such values, binary digits have to be defined
whose value is less than 1 (power of base 2 with negative exponent).

Real Format
In order to be able to form the greatest possible value range within a defined memory capacity
(see picture), you must be able to select the decimal point position as required. Early on, IEEE
defined a format for floating-point numbers. This format was laid down in IEC 61131 and was
included in STEP 7. This format makes it easy to process a variable decimal point position. In a
binary coded floating-point number, a portion of the binary digits contain the mantissa (23 Bit) and
the rest contain the exponent (8 Bit) and the sign of the floating-point number. When you specify
real values, you do so without specifying the format. After you enter a constant real value (for
example: 0.75), the Editor automatically makes a conversion to scientific notation (for example:
7.5000e-001).

Application
Floating-point numbers are used for "analog value processing", among other things. A great
advantage of floating-point numbers is in the number of operations possible with such numbers.
These include, in addition to the standard operations such as: +, -, * , / also instructions such as
sin, cos, exp, ln, etc, that are used mainly in closed-loop control algorithms.

Value Range LREAL:


-1.7976931348623158e+308 to -2.2250738585072014e-308
±0.0
+2.2250738585072014e-308 to +1.7976931348623158e+308

TIA-MICRO1 - Digital Operations


8-10 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.2. Timer / Counter Instance Data Blocks

Data block for Global data

Function
OB1
FC10

DBy

Function
FC20

Instance DB for FBx


or Counter / Timer function
Function block
FBx or
DBx
Counter / Timer
function

Data Blocks
Data blocks are used for storing user data. They occupy memory space in the user memory of
the CPU. Data blocks contain variable data (such as numeric values) with which the user
program works. The user program can access the data in a data block. Access can be made
symbolically or absolutely.

Area of Application
Data blocks are used with two different purposes:
• Global data blocks: These contain information that all the logic blocks in the user program can
access.
• Instance data blocks: These are always assigned to a particular FB or functions such as
counters and timers. The data of these instance DBs should only be processed by the
associated FB or counter / timer function.

Creation of DBs
Global DBs are created either with the Program Editor or according to a previously created "user-
defined data type". Instance data blocks are generated when a function block or a counter / timer
function is called.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-11
SIMATIC S7-1200 Basic Course

8.3. Task Description: Counting the Transported Parts

4711

DI 0V
1Hz flashing light
S_OperationON
when ACT = SETPOINT (=3)
I 0.0
S_OperationOFF
I 0.1 (NC) -10V +10V
Poti
I 0.2 S_Right
"B_Bay1" "B_Bay2" "B_LB"
I 0.3 S_Left (I 8.5) (I 8.6) (I 8.0)
DO
P_Operation Q 4.0

"K_Left" "K_Right"
(Q 8.6) (Q 8.5)

"S_Bay1" "S_Bay2" "S_Bay_LB"


(I 8.1) (I 8.2) (I 8.4)
"P_Bay1" "P_Bay2" "P_Bay_LB"
(Q 8.1) (Q 8.2) (Q 8.4)

Function Up Till Now


When "P_Operation" (Q4.0) is switched on, parts are transported from Bay 1 or Bay 2 through the
light barrier. The transport sequence starts as soon as a part is placed on Bay 1 or Bay 2 and the
associated bay’s pushbutton is pressed and it ends as soon as the part has passed the light
barrier.

Task
• When "P_Operation" (Q4.0) is switched on, the transported parts are to be counted as soon
as they have passed through the "B_LB" (I 8.0) light barrier ("B_LB" 0  1).
• The number of transported parts (ACTUAL quantity) is to be recorded with a counter and
stored in the variable "MW_ACT" (MW20).
• If the ACTUAL quantity has reached the SETPOINT quantity of 3, the indicator light
"P_Bay_LB" (Q8.4) shows a continuous light and the indicator lights at Bay 1 and 2 are dark
(= a new part must not be placed on the conveyor -> lock-out in FC14) and no further
transport sequence can be started (-> lock-out in FC16)).
• The counter is reset to ‘0’ when "P_Operation" (Q4.0) is switched on or when
ACTUAL=SETPOINT is acknowledged via the pushbutton "S_Bay_LB".

The described functions are already programmed in the block "FC_Count" (FC18) which is stored
in the "Micro1_Lib" global library. The block still contains errors and is to be commissioned by you
in the next exercise.

TIA-MICRO1 - Digital Operations


8-12 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.3.1. Counters: CTU, CTD, CTUD

Counters
Counters are used to count events, record quantities, etc. There are up counters and down
counters as well as counters that can count in both directions.

Value Range of a Counter


The count or value range of a counter depends on its data type (see picture) which is always an
integer. The various selectable Integer data types merely differentiate themselves in their value
range and thus determine the count range of the counter.

Instance Data Block


In addition to internally required variables, the counter also stores its current counter value in a
so-called instance data block which must be specified when programming a counter. The
specified instance data block is automatically generated by the Editor with exactly the internal
structure that the counter requires. The user has no further programming effort with this data
block other than having to download it into the CPU.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-13
SIMATIC S7-1200 Basic Course

8.3.2. Counter Function: Inputs

Parameter Declaration Data type Memory area Description

CU Input BOOL I, Q, M, D, L or constant Count up input

CD Input BOOL I, Q, M, D, L or constant Count down input

R Input BOOL I, Q, M, D, L, P or constant Reset input

LD Input BOOL I, Q, M, D, L, P or constant Load input

PV Input Integers I, Q, M, D, L, P or constant Value at which the QU output


is set. / Value to which the CV
output is set with LD = 1.

Input CU and CD
With a positive edge at input CU, the current count is increased by one; with a positive edge at
input CD, the current count is decreased by 1. If a positive edge is detected at both inputs
simultaneously or in the same cycle, the current count remains unchanged. If the upper or lower
limit of the specified data type is reached, the count is no longer increased or decreased for a
positive edge at CU or CD.

Input R
The input R acts statically, that is, as long as RLO '1' is at input R, the count is set to 0 and rising
edges or RLO '1' at the inputs CU, CD and LD have no effect on the current count.

Input LD (Load, Only for Down Counters)


The input LD acts statically, that is, as long as RLO '1' is at input LD, the current count is set to
the value that is passed to the input PV, and positive edges at the inputs CU and CD have no
effect on the count.

Input PV
The value to which the count is to be set must be passed to the input PV as long as RLO '1' is at
input LD. The variable or constant passed to the input must be compatible with the data type of
the counter.

TIA-MICRO1 - Digital Operations


8-14 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.3.3. Counter Function: Outputs

Parameter Declaration Data type Memory area Description


QU Output BOOL I, Q, M, D, L Status of the up counter

QD Output BOOL I, Q, M, D, L Status of the down counter

CV Output Integers, I, Q, M, D, L, P Current counter value


CHAR,
WCHAR,
DATE
(INT)

Output QD (Only for Down Counters)


The current status of the down counter can be checked at the output QD. As long as the current
count is less than or equal to zero, the output QD has Status "1", otherwise, Status '0'.

Output CV
The current count is output at output CV. The variable passed to the output must be compatible
with the data type of the counter.

Output QU
The current status of the up counter can be checked at the output QU. As long as the current
count is greater than or equal to the value of the parameter PV, the output QU has Status '1',
otherwise, Status '0'.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-15
SIMATIC S7-1200 Basic Course

8.3.4. Exercise 1: Counting the Transported Parts


Commissioning "FC_Count" (FC18)

Task
When "P_Operation" (Q4.0) is switched on, the transported parts are to be counted and the
ACTUAL quantity is to be stored in the variable "MW_ACT" (MW20). If the ACTUAL quantity has
reached the SETPOINT quantity of 3, the indicator light "P_Bay_LB" (Q8.4) shows a continuous
light. As long as this is not acknowledged via "S_Bay_LB" (I 8.4), the indicator lights "P_Bay1"
(Q8.1) and "P_Bay2" (Q8.2) are dark and no new part transportation can be started.

What to Do
1. From the "Micro1_Lib" global library, copy the "FC_Count" (FC18) function into the "Program
blocks" container using drag & drop as shown in the picture.
2. In "FC_Count" (FC18), pass the "DB_CTU_Parts" (DB180) data block as a single instance
DB to the count function (is automatically created in the System blocks -> Program resources
container, see picture)
3. Program the call of "FC_Count" (FC18) in "OB_Cycle" (OB1). Download all blocks into the
CPU and check the program function.
4. Correct the "FC_Count" (FC18) function in such a way that the parts are counted correctly
(the "DB_CTU_Parts" (DB180) data block is error-free!)
5. In the blocks "FC_Indicate" (FC14) and "FC_ConvMotor" (FC16), program the required lock-
outs.
6. Download all modified blocks into the CPU and check the program function.

TIA-MICRO1 - Digital Operations


8-16 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.4. Task Description:


Monitoring the Transport Sequences for Time

4711

DI 0V
I 0.0 S_OperationON
S_OperationOFF
I 0.1 (NC) -10V +10V
Poti
I 0.2 S_Right

I 0.3 S_Left
DO
P_Operation Q 4.0

I 1.0 S_Acknowledge

P_Fault Q 5.0

Function Up Until Now


When "P_Operation" (Q4.0) is switched on, parts are transported from Bay 1 or 2 until they are
through the light barrier. A transport sequence starts as soon as a part is placed on the conveyor
at Bay 1 or 2 and the associated bay pushbutton is pressed. The transport sequence ends as
soon as the part has passed the light barrier.

Task Description
The automatic transport sequences are to be monitored for time. The monitoring is to function as
follows:
• If a transport sequence takes longer than the 6 second monitoring time, there is a fault and
the conveyor motor is automatically switched off.
• A fault is displayed with a 2Hz flashing light on the simulator LED "P_Fault" (Q 5.0).
• A fault can be acknowledged via the simulator switch "S_Acknowledge" (I 1.0).
• As long as there is an unacknowledged fault, no new transport sequence can be started.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-17
SIMATIC S7-1200 Basic Course

8.4.1. Timer Function TON

Data Type TIME


The contents of a variable or constant of the data type TIME is interpreted as an integer number
in milliseconds and stored in the memory as a 32-bit integer with sign. The representation
contains information for days (d), hours (h), minutes (m), seconds (s) and milliseconds (ms).
Examples:
Length (bits) Format Value range Examples of value input
T#-24d20h31m23s648ms
T#10d20h30m20s630ms,
32 Signed duration to
TIME#10d20h30m20s630ms
T#+24d20h31m23s647ms

Data Block
In addition to internally required variables, the timer function also stores the current already
expired time in a data block which must be specified when programming the timer function. The
specified data block is automatically generated by the Editor with exactly the internal structure
that the timer function requires. The user has no further programming effort with this data block
other than having to download it into the CPU.

TIA-MICRO1 - Digital Operations


8-18 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.4.2. Timer Function TON (ON Delay) Pulse Diagram

TON
The timer function "ON Delay" is started with a rising edge at input IN. So that the time expires,
RLO must continue to be '1'. The timer function supplies a '1' signal at output Q, as soon as the
specified time (variable or constant of data type TIME) at input PT has expired and as long as the
start signal at input IN still exists. The already expired time can be queried at output ET by
passing a variable of data type TIME.

Parameter Data type Memory area Description


IN BOOL I, Q, M, D, L, P Start input

Duration of the on delay.


PT TIME I, Q, M, D, L, P the value of the PT parameter must be
positive.
Operand that is set when the timer PT
Q BOOL I, Q, M, D, L, P
expires

ET TIME I, Q, M, D, L, P Current time value

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-19
SIMATIC S7-1200 Basic Course

8.4.3. Exercise 2: Monitoring the Transports for Time


Commissioning "FC_Fault" (FC17)

Drag & Drop

Task
The transport sequences are to be monitored for time as previously described. If a transport
sequence takes longer than 6 seconds, the conveyor motor is automatically switched off and the
fault is displayed with a 2Hz flashing light on the simulator. As long as a fault is not
acknowledged, no new transport sequence can be started.

What to Do
1. From the "Micro1_Lib" global library, copy the "FC_Fault" (FC17) function into the "Program
blocks" container using drag & drop as shown in the picture.
2. Create the user constant "max_Time" of the data type Time with the value T#6s as shown in
the picture.
3. In "FC_Fault" (FC17), pass the "DB_TON_Fault" (DB170) data block as a single instance DB
to the timer function and as the time period the user constant "max_Time".
4. Program the call of "FC_Fault" (FC17) in "OB_Cycle" (OB1).
5. In the "FC_ConvMotor" (FC16) block, program the required switching off of the conveyor
motor when there is a conveyor fault.
6. In "FC_Indicate" (FC14), program the relevant lock-outs so that the indicator lights "P_Bay1"
(Q8.1) and "P_Bay2" (Q8.2) show the required behavior.
7. Download all modified blocks into the CPU and check the program function.
8. Correct "FC_Fault" (FC17) in such a way that the monitoring function is fulfilled as required.

TIA-MICRO1 - Digital Operations


8-20 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.5. Additional Information

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-21
SIMATIC S7-1200 Basic Course

8.5.1. Additional Exercise 3: Counting the Conveyor Faults -


Expanding "FC_Fault" (FC17)

"M_Fault"
(M 17.0)

3
Conv. Fault 2
Counter
1
0

"P_Operation"
(Q 4.0)

Function Up Until Now


When "P_Operation" (Q4.0) is switched on, the transport sequences are monitored for time. If a
transport sequence takes longer than the monitoring time of 6 seconds, there is a conveyor fault
and the conveyor motor is automatically switched off (logically linked in "FC_ConvMotor" (FC16)).

Task:
When "P_Operation" (Q4.0) is switched on, the conveyor faults are to be counted. After 3
conveyor faults have occurred, "P_Operation" (Q4.0) is to be switched off for safety reasons. To
start a new transport sequence, the fault (as already programmed) must be acknowledged and
"P_Operation" (Q4.0) must be switched on once again.

What to Do:
1. In "FC_Fault" (FC17), in a new network, program the counting of the conveyor faults. The
counter counts up 1 every time a conveyor fault occurs ("M_Fault" (M17.0) = "1").
2. In "FC_Fault" (FC17), pass any bit memory you like to the counter output Q.
3. In "FC_Mode" (FC15), program the switching off (reset) of "P_Operation" (Q4.0) after three
conveyor faults. For this, use the bit memory which you passed to the counter output Q in
"FC_Fault" (FC17).

TIA-MICRO1 - Digital Operations


8-22 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.5.2. Additional Exercise 4: Timely Lock-out of the Conveyor Motor Jogging

Lock-out
time LEFT

"S_Right"
(I 0.2)

"K_Right"
(Q8.5)

Lock-out
TOF Right

"S_Left"
(I 0.3) lock-out
time RIGHT

"K_Left"
(Q8.6)

Lock-out
TOF Left

Function Up Until Now


When "P_Operation" (Q4.0) is switched off, the conveyor motor can be jogged to the RIGHT and
LEFT using the simulator switches "S_Right" (I 0.2) and "S_Left" (I 0.3).

Task:
In order to avoid too great a load change, it should only be possible to jog the conveyor motor in
the opposite direction after it has been jogged to the RIGHT or to the LEFT after a lock-out time
of 2 seconds (see picture). If, for example, the motor has been jogged to the RIGHT, then it can
only be jogged back to the LEFT after the lock-out time of 2 seconds has expired.

What to Do:
1. In "FC_ConvMotor" (FC16), program two TOF timers (Off Delay) as the lock-out timers
RIGHT and LEFT and assign one bit memory each to the Timer result Q.
2. Gate these bit memories to the jog conditions.
3. Download the modified "FC_ConvMotor" (FC16) into the CPU and check the program
function.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-23
SIMATIC S7-1200 Basic Course

8.5.3. Move Operations: MOVE

Parameter Data type Memory Description


area
EN BOOL I, Q, M, D, L Enable input

ENO BOOL I, Q, M, D, L Enable


Output

IN All I, Q, M, D, L Source
elementary or constant value
data types,
DTL,
STRUCT,
ARRAY
OUT1 All I, Q, M, D, L Destination
elementary address
data types,
DTL,
STRUCT,
ARRAY

MOVE
You use the "MOVE - Move value" instruction to transfer the content of the operand at the IN
input to the operand at the OUT1 output. The transfer is always made in the direction of
ascending address.
The operation is only executed if the signal state is "1" at the enable input EN. In this case, the
ENO output also has signal state "1".

TIA-MICRO1 - Digital Operations


8-24 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.5.4. Move Operations: MOVE_BLK

Copies the contents


of the source area to
the destination area

Source area Destination area

MOVE_BLK
You can use the "Move block" instruction to move (copy) the content of a memory area (source
area) to another memory area (destination area). The number of elements to be moved (copied)
to the destination area is specified at input COUNT. The width of the elements to be moved
(copied) is defined by the width of the element at input. The copy operation is always made in the
direction of ascending address.

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-25
SIMATIC S7-1200 Basic Course

8.5.5. Comparator Operations: IN_RANGE, OUT_RANGE

100 500
IN_RANGE

OUT_RANGE

IN_RANGE
You can use the "Value within range" instruction to determine if the value at the VAL input is
within a specific value range. You specify the limits of the value range with the MIN and MAX
inputs. When the query is processed, the "Value within range" instruction compares the value at
the VAL input with the values of the MIN and MAX inputs and sends the result to the box output.
If the value at the VAL input fulfills the comparison MIN <= VAL or VAL <= MAX, the box output
has the signal state "1". If the comparison is not fulfilled, the box output has the signal state "0".
The comparison function can only be executed if the values to be compared are of the same data
type and the box output is interconnected.

OUT_RANGE
You can use the "Value outside range" instruction to determine if the value at the VAL input is
outside of a specific value range. You specify the limits of the value range with the MIN and MAX
inputs. When the query is processed, the "Value outside range" instruction compares the value at
the VAL input to the values of the MIN and MAX inputs and sends the result to the box output. If
the value at the VAL input fulfills the comparison MIN > VAL or VAL > MAX, the box output has
signal state "1". The box output returns the signal state "0", if the value at input VAL does not
satisfy the MIN > VAL or VAL > MAX condition.
The comparison function can only be executed if the values to be compared are of the same data
type and the box output is interconnected.

TIA-MICRO1 - Digital Operations


8-26 Training Document V13.01.01
SIMATIC S7-1200 Basic Course

8.5.6. Date and Time-of-day: RD_SYS_T

RD_SYS_T
You use the RD_SYS_T instruction to read the current date and current time-of-day of the CPU
clock. The read dates are output in DTL format at the OUT output parameter of the instruction.
The provided value does not include information about the local time zone or daylight saving time.
You can query whether errors have occurred during execution of the instruction in the RET_VAL
output.

Byte Component Data type Value range


0-1 Year UINT 1970 to 2554
2 Month USINT 1 to 12
3 Day USINT 1 to 31
1 (Sunday) to 7 (Saturday)
4 Weekday USINT
The weekday is not considered in the value entry.
5 Hour USINT 0 to 23
6 Minute USINT 0 to 59
7 Second USINT 0 to 59
8 -11 Nanosecond UDINT 0 to 999 999 999

TIA-MICRO1 - Digital Operations


Training Document V13.01.01 8-27

You might also like