Micro1 08E Digit Operat PDF
Micro1 08E Digit Operat PDF
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
8. Digital Operations
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.
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.
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)
User-defined
data types • PLC data type UDT (User Defined DataType)
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
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
Timers
TIME 32 T#2h46m30s630ms
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.
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
Display Formats:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 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
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.
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
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
Sign
negative
numbers
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.
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
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.
Function
OB1
FC10
DBy
Function
FC20
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.
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)
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.
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.
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 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.
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'.
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.
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
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.
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.
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.
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.
"M_Fault"
(M 17.0)
3
Conv. Fault 2
Counter
1
0
"P_Operation"
(Q 4.0)
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).
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
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.
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".
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.
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.
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.