PRO1 08E Digital Operations
PRO1 08E Digital Operations
PRO1 08E Digital Operations
T4
I 0.7 S_ODT
Q8.5
S Q
S5T#35s BI MW0
TV
I 0.5
R BCD QW12
Contents Page
Digital Operations ............................................................................................................................. 2
Objectives ........................................................................................................................................ 3
Acquiring, Processing and Outputting Data ...................................................................................... 4
Integer (INT, 16-Bit Integer) Data Type ............................................................................................ 5
Double Integer (DINT, 32-Bit Integer) Data Type ............................................................................. 6
REAL (Floating-point Number, 32 Bit) Data Type ............................................................................. 7
The BCD Code for Inputting and Outputting Integers ........................................................................ 8
Exercise 1: Number Formats ............................................................................................................ 9
Loading and Transferring Data ......................................................................................................... 10
Data Storage in Accumulator 1 ......................................................................................................... 11
Traditional Counter Functions ........................................................................................................... 12
Counters: Function Diagram ............................................................................................................. 13
Exercise 2: Counting the Transported Parts (FC 18, FC14) .............................................................. 14
Traditional Timer Functions .............................................................................................................. 15
Example of Timer Function: ON Delay (SD) ..................................................................................... 16
Exercise 3: Monitoring the Transport Functions (FC17) ................................................................... 17
Exercise 4: Counting the Conveyor Belt Fault Conditions (FC17) ...................................................... 18
Conversion Operations BCD <-> Integer .......................................................................................... 19
Comparison Operations ................................................................................................................... 20
Basic Mathematical Functions .......................................................................................................... 21
Exercise 5: Counting the Transported Parts (FC 18) ......................................................................... 22
T4
I 0.7 S_ODT
Q8.5
S Q
S5T#35s BI MW0
TV
I 0.5
R BCD QW12
Contents Page
If You Want to Know More ............................................................................................................... 23
Counters: Bit Instructions ................................................................................................................ 24
Time Formats for Traditional S5 Timers in STEP 7 ........................................................................... 25
Timers: Bit Instructions ................................................................................................................... 26
Conversion Operations I -> DI -> REAL .......................................................................................... 27
Digital Logic Operations .................................................................................................................. 28
Application Example: Digital Edge Detection ............................................................................... 29
... be familiar with the INT, DINT, REAL data types and the
BCD display
Operating 0248
Thumbwheel
+ monitoring V buttons,
processes Potentiometer,
0 8 1 5 7-segment
display
Operator Panel
DI/ AI/
DO AO
such as PROFIBUS
Binary/Digital True logic control systems are recognizable in the fact that they exclusively
Processing process binary data.
The performance of today‘s control computer, as well as tasks in the data
processing, quality control areas, 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 The goal of process monitoring is to provide the operator with up-to-the-minute
Monitoring 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.
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.
Formats 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.
Display Formats:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Integer Data Type An Integer data type value is a whole number 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 slide 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
numbers system results from the number of available digits. Accordingly, the
value of every position 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, the most significant bit (bit no. 15 for the Integer data type) has
the value - 215. 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 positions
that have a 1 (see slide).
Specifying constants in the binary display format is not only used for specifying
Integer values, but more often to specify bit patterns (such as in digital logic
operations) in which the Integer value represented by the bit pattern is of no
interest. The number of specifyable bits is variable from 1 to 32. Missing bits are
filled with leading zero digits.
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
Double Integer SIMATIC® S7 stores Double Integer data type values with sign as 32 bit code.
(32-Bit Integer) This results in the value range shown in the slide 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# -32769). This is imperative if
the value is to be further processed arithmetically as a double integer. Otherwise
you would work with false values (value + sign)!
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 data types.
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 (for SIMATIC® S7: double word, 32 bit) (see slide), you must
be able to select the decimal point position. 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 (for example: 7.5000e-001).
Application Floating-point numbers are used for "analog value processing", among others.
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.
0 2 9 6
16 Bit: BIN.: 2# 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
Sign (+) 2 9 6
Sign (+) 0 0 0 0 2 9 6
32 Bit: BIN.: 2# 0 x x x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
Origin In the past, the specification and visualization of whole numbers was done
exclusively using simple, mechanical thumbwheel buttons and digital displays.
These thumbwheel buttons and digital displays were connected to the PLC‘s
digital input and output modules through parallel wiring. The structure could also
be cascaded, without having to change the mechanical coding of a digit.
BCD Code Each digit of a decimal number is encoded in four bit positions. Four bits are
used because the highest decimal digit, 9, requires at least four bit positions in
binary code.
Negative Numbers So that negative numbers can also be specified using a BCD thumbwheel
button, STEP 7 codes the sign in the most significant bit of the most significant
digit (see slide). A sign bit = 0 indicates a positvie number. A sign bit = 1
indicates a negative number.
STEP 7 recognizes 16-bit-coded (sign + 3 digits) and 32-bit-coded (sign + 7
digits) BCD numbers.
Data Formats There is no data format for specifying BCD-coded values in STEP 7. You can,
however, specify the decimal number whose BCD code is to be given, as a HEX
number. The binary code of the HEX number and that of the BCD-coded
decimal number is identical.
As you can see in the slide, the DEC data format is not suitable for specifying
BCD coded numbers!
Display Formats Different display formats can be selected in both the "Monitor / Modify Variables"
and the "Monitor (Block)" test function when displaying variables or register
contents in STL.
Every variable can be monitored with several display format options. Depending
on the variable‘s data type, it becomes apparent that monitoring with the
appropriate display format makes more sense.
BOOL: Display of a single bit
(only possible for a variable of the BOOL data type)
BIN: Display of the individual bits of a variable
(makes sense for variables of the BYTE, WORD, DWORD data
types)
HEX: Display the contents of a variable as hexadecimal number (BCD)
(makes sense for variables of the BYTE, WORD, DWORD data
types)
DEC: Display the contents of a variable as decimal number (not BCD!)
with sign (makes sense for variables of the INT, DINT data types)
FLOATING_ Display of the contents of a variable as floating-point number
POINT (makes sense for variables of the REAL data type)
Task You are to use the different display formats to display numbers to find the
appropriate display format.
What to Do 1. With the SIMATIC Manager, open the project TIA - PRO1_Participant
2. Copy the "Number Formats" variable table from the S7 program called
"C8_Demo_Number_Formats" into your current project.
3. Establish an online connection to the CPU and monitor the different number
representations. Change the number values through the simulator or by
changing the modify value.
Accumulator 1
MOVE (LAD/FBD) If the EN input is active, the value at input "IN" is copied to the address at output
"OUT". "ENO" has the same signal state as "EN".
L and T (STL) Load and transfer instructions are executed regardless of the RLO. Data is
exchanged through the accumulator.
Standard / ACCU1 Accumulator 1 is the main register in the CPU. The load instruction writes the
value from the source address right-justified into the (standard) accumulator 1
and pads the remaining bits (32 bits in all) with "0"s.
The transfer instruction copies some or all of the contents of accumulator 1 to
the specified destination without clearing the contents of accumulator 1 (see
next page).
All arithmetic and digital operations store their result in accumulator 1.
ACCU2 When a load instruction is executed, the old contents of accumulator 1 are first
shifted to accumulator 2 and accumulator 1 is cleared (reset to "0") before the
new value is written into accumulator 1.
TAK The TAK instruction swaps the contents of accumulator 1 with the contents of
accumulator 2. The instruction is executed without taking the status bits into
consideration or influencing them. The contents of accumulator 3 and
accumulator 4 remain unchanged (for CPUs with four accumulators).
L MB 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB0
31 23 15 7 0
Load 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB0 MB1
L MW 0
31 23 15 7 0
T QD 4
QD 4
Transfer T QW 4
QW 4
T QB 4
QB 4
General Accumulators are auxiliary memories in the CPU for data exchange between
various addresses as well as for comparison and mathematical operations.
The S7-300™ has two accumulators which are 32 bits each and the S7-400™
has four accumulators also with 32 bits each.
Load The load instruction loads the contents of the specified byte, word or double
word into accumulator (ACCU) 1.
Transfer When a transfer instruction is executed, the contents of ACCU 1 are retained.
Therefore, the same information can be transferred to different destinations. If
only one byte is transferred, the eight bits farthest to the right are used (see
slide).
Note The following graphic explains by means of an example the structure of a word
definition in SIMATIC S7 (valid for accesses to PII, PIQ, peripherals, bit
memories and data blocks):
MB 80 MB 81
A I 0.4
C5 C5
CU C5
S_CUD S_CUD A I 0.5
I 0.4 Q 8.3
CU Q
Q I 0.4 CU CD C5
A I 0.3
I 0.5
L C#5
CD CV MW 4 I 0.5 CD
S C5
I 0.3 A I 0.7
S CV_BCD QW 12 I 0.3 S CV MW 4 R C5
L C5
C#5 PV C#5 PV CV_BCD QW 12 T MW4
Q 8.3 LC C5
I 0.7
R I 0.7 R Q
Q = T QW12
A C5
= Q8.3
Counter Value A 16-bit word is reserved for each counter in the system data memory. This word is used
for storing the counter’s value (0 to 999) in binary code.
Count Up When the RLO at the "CU" input changes from "0" to "1", the counter’s current value is
incremented by 1 (upper limit = 999).
Count Down When the RLO at the "CD" input changes from "0" to "1", the counter’s current value is
decremented by 1 (lower limit = 0).
Set Counter When the RLO at the "S" input changes from "0" to "1", the counter is set to the value at
the "PV" input.
Reset Counter When the RLO at the Reset changes from "0" to "1", the counter’s value is set to zero. If
the reset condition is fulfilled (stays "high"), the counter cannot be set and counting in
either direction is not possible.
PV The preset value (0 to 999) is specified in BCD format at the "PV" input as:
• as a constant (C#...)
• a BCD format through a data interface.
CV / CV_BCD The counter value can be loaded into the accumulator at the binary output as an Integer
value (CV) or at the decimal output as a BCD number (CV_BCD) and then transferred
from there to other addresses.
CU
CD
5
4
3
Count
2
1
0
Notes When the counter reaches its maximum value (999), the next count up signal
does not affect the counter. Likewise, when the counter reaches its minimum
value (0), the next count down signal does not affect the counter. The counters
do not count above 999 of lower than zero.
If an up count and a down count signal occur at the same time, the count
remains the same.
ACTUAL quantity
QW 6
Count + display
Expansion transported
2 Hz flashing parts
Acoustic light
Signalizing “L_Bay_1“
in “L_Bay_2“
Jog mode During
conveyor
movement
Function Up Till Now In AUTO mode, parts are transported from Bay 1 or Bay 2 to the Final Control
or until they pass through the light barrier. The transportation function starts as
soon as a part is placed on Bay 1 or 2 and the associated pushbutton at that
bay is pressed and it ends as soon as the part has passed through the light
barrier.
Task (1): • The parts transported in AUTO mode are to be counted as soon as they
have passed through the "LB" light barrier ("LB" 0 -> 1).
• The number of transported parts (ACTUAL quantity) is to be displayed on
the BCD digital display.
• The counter is to be reset when the system is switched off (Q 4.1 = ´0 ´).
What to Do 1. Program the counting of the transported parts in the FC 18 block. Use the
S5 counter (C 18) in FC 18 for this and give FC 18 the symbolic name
"FC_Count".
2. Program the call of FC 18 in OB 1.
Task (2): 1. While the conveyor is moving, the associated indicator light "L_Bay_1" or
"L_Bay_2" is to flash with the flashing frequency of 2 Hertz. Program this
new function in an FC 14 with the symbolic name "FC_Signalizing".
2. In "Manual Mode", the horn is to be pulsed on the conveyor with 2 Hertz
when "Jog left" or "Jog right" actions take place so as to acoustically signal
the manual mode. Expand the FC 14 function.
Note Please make sure that only real parts passing through the light barrier may be
counted.
General In control engineering, the following traditional timer functions (S5 timer
functions) have long since established themselves:
- Pulse Timer (S_PULSE or SP),
- Extended Pulse (S_PEXT or SE),
- ON Delay (S_ODT or SD),
- Stored ON Delay (S_ODTS or SS),
- OFF Delay (S_OFFDT or SF)
Memory Timers have their own reserved memory area in the CPU. This memory area
reserves one 16-bit word for every timer function. To find out how many timer
words and thus timer functions are available in your CPU, please check the
CPU‘s technical data.
Time Value With the following syntax, you can load a predefined time value:
· - S5T#aH_bM_cS_dMS
T4 T4
I 0.7 S_ODT Q8.5 S_EVERZ A I 0.7
S Q I 0.7 S BI MW0 L S5T#35s
S5T#35s TV BI MW0 S5T#35s QW12
SD T4
TV BCD
I 0.5 Q8.5 A I 0.5
R BCD QW12 I 0.5 R Q = R T4
L T4
T MW0
RLO at S
LC T4
RLO at R T QW12
A T4
Time = Q8.5
operation
Example
Start The timer starts when the RLO at the Start input "S" changes from "0" to "1".
The timer starts with the time value specified at the Time Value "TV" for as long
as the signal state at input "S" =1.
Reset When the RLO at the Reset input "R" changes from "0" to "1", the current time
value and the time base are deleted and the output "Q" is reset.
Digital Outputs The current time value can be read as a binary number at the "BI" output and as
a BCD number at the "BCD" output.
The current time value is the initial value of "TV" minus the value for the time
that has elapsed since the timer was started.
Binary Output The signal at the "Q" output changes to "1" when the timer has expired without
error and input "S" has signal state "1".
If the signal state at the "S" input changes from "1" to "0" before the timer has
expired, the timer stops running and output "Q" has a signal state "0".
Note In STEP 7, you can also implement IEC conforming timers using SFBs.
The use of system function blocks is dealt with in an advanced programming
course.
I 1.0 Ackn_Fault
Timed lock-out
“Jog Manual“
Timed
monitoring
of conveyor
movement
Task (2): To avoid too great a load change, switching directions once the conveyor is
moving (Mode_Manual) will only to be possible after a 2 second lock-out time. If
the motor direction was jogged to the RIGHT, for example, it can only be jogged
to the LEFT after the 2 second lock-out time has run out.
• In FC 16, program the S5 timers T 15 and T 16 as OFF-Delays (S_OFFDT
or SF), for the lock-out times RIGHT and LEFT.
Download the modified FC 16 (Conveyor), FC 17 and FC 14 blocks into the
CPU and test your program under the modified conditions.
Note Use the STEP 7 Online Help to familiarize yourself with the timer functions
SP, SE, SD, SS, SF .
Coveyor belt
fault condition
M 17.0
3
Conveyor belt
fault condition 2
counter C 17 1
0
Mode_Auto
Q 4.3
Function Up Till Now The transport functions in AUTO mode are monitored. If the transport function
takes longer than the 6 second monitoring time (if a part does not pass through
the light barrier within 6 seconds of its start time), then there is a conveyor belt
fault condition in the system and the conveyor motor is automatically switched
off (logic in FC 16).
Task: The conveyor belt fault conditions in AUTO mode are to be counted. After 3
conveyor belt fault conditions have occurred, the AUTO mode is to be switched
off for safety reasons. To start a new transport function, the fault condition must
be acknowledged (as already programmed) and the AUTO mode must be
switched on once more.
What to Do: 1. In FC 17, in a new network, program the counting of the conveyor belt fault
conditions using the S5 counter C 17 as the count down counter.
- When the "Auto" mode is switched on, the counter is set to 3 (number of
conveyor belt fault conditions until the AUTO mode is switched off)
- The counter counts down 1 every time a conveyor belt fault condition
occurs (M 17.0 = 1).
2. In FC 15 (mode section), program the switching off (reset) of the AUTO
mode after three conveyor belt fault conditions. The AUTO mode must
switch off when the counter C 17 has counted down from 3 to 0 or when its
binary state changes from 1 -> 0. In FC 15 "FC_Modes", use the bit memory
M 15.7 as auxiliary bit memory to record the negative edge of C 17.
Number Conversion
Entered in BCD 0 81 5 BCD->Integer
User program
Task
with Integer
math operations
Number Conversion
displayed 0 2 4 8 BCD<-Integer
in BCD
Example A user program is to perform mathematical functions using values entered with
thumbwheel buttons and display the result on a digital display. Mathematical
functions cannot be performed in BCD format, so the format must be changed.
EN, ENO If RLO is =1 at Enable input EN, the conversion is performed. Enable output
ENO delivers Status ‘1‘ if the conversion could be performed without an error.
OUT The result of the conversion is stored at the address at the OUT output.
BCD_I / BTI (Convert BCD to integer) reads the contents of the IN parameter as a three-digit
BCD number (+/- 999) and converts it to an integer value (16 bits).
I_BCD / ITB (Convert integer to BCD) reads the contents of the IN parameter as an integer
value (16 bits) and converts this value to a three-digit BCD number (+/- 999). If
an overflow occurs, ENO = 0.
BCD_DI / BTD Converts a BCD number (+/- 9999999) to a double integer (32 bits).
DI_BCD / DTB Converts a double integer to a seven-digit BCD number (+/- 9999999). If an
overflow occurs, ENO = 0.
CMP You can use comparison instructions to compare the following pairs of
numerical values:
I Compare integers (on the basis of 16 bit fixed-point number)
D Compare integers (on the basis of 32 bit fixed-point number)
R Compare floating-point numbers (on 32 bit real number basis =
IEEE floating-point numbers).
If the result of the comparison is "true", then the RLO of the operation is "1",
otherwise it is "0".
The values at inputs IN1 and IN2 are compared for conformity with the specified
condition :
IN1, IN2 The value at IN1 is read in as the first address and the value at IN2 as the
second.
OUT The result of the mathematical operation is stored at the address at output OUT.
Note The advanced mathematical functions (ABS, SQR, SQRT, LN, EXP, SIN, COS,
TAN, ASIN, ACOS, ATAN) use 32 bit floating point definitions and are discussed
in Programming 2.
DI DO
Q 4.... ACT quantity
I 0.0 System_ON Fault .0
I 0.1 System_OFF System .1
I 0.2 Jog_RIGHT MANUAL .2
I 0.3 Jog_LEFT AUTO .3
I 0.4 AUTO / MANUAL .4 QW 6
I 0.5 Accept .5
I 0.6 .6
I 0.7 .7
I 1.0 Ackn_Fault
SETPOINT quantity
0 8 1 5
IW 2 Acknowledgement
pushbutton
Function Up Till Now: • The parts transported in AUTO mode are counted (with the S5 counter C18)
in FC 18 as soon as they have passed through the light barrier "LB" ("LB" 0->1)
• The number of transported parts (ACT quantity) is displayed on the BCD
digital display.
• The counter is reset when the system is switched off (Q 4.1 = ´0´).
Task: • Counting the transported parts is no longer to be done with the S5 counter
C 18, but rather by addition using MW 20 to store the sum. Use the M 18.0
memory bit as the auxiliary memory marker for the necessary edge
detection.
• The SETPOINT quantity of how many parts are to be transported can be set
using the BCD thumbwheel. When the given SETPOINT quantity is reached,
it is displayed on the red LED (Q 8.4) at the Final Control.
• As long as the message SETPOINT quantity reached (red LED) exists, no
other transport function can be started (lock-out in FC 16).
• The message can be acknowledged with the pushbutton at the Final Control.
The acknowledgement resets the ACTUAL quantity (MW 20) to 0, just as
when the system is switched off.
What to Do: 1. Insert the OB 121 organization block into your program and download it into
the CPU. A program in OB 121 is not necessary. By downloading the
"empty" OB 121 you prevent the CPU from going into the STOP state
because of a "rebound" by the BCD thumbwheel when you set the
SETPOINT quantity.
2. Adapt your current FC 18 for counting the parts to the new task (delete S5
counter, program the counting by addition)
3. Modify the FC 16 control logic for the conveyor motor according to the task.
Note The following pages contain either further information or are for reference to
complete a topic.
For more indepth study we offer advanced courses and self-learning mediums.
Network 1: C5
I 0.0 SC
I 0.0 C5
A I 0.0
SC L C#20
C#20 CV
C#20 S C5
Network 2:
C5
I 0.1 C5
I 0.1 CU A I 0.1
CU
CU C5
Network 3:
I 0.2 C5 C5
A I 0.2
CD I 0.2 CD CD C5
Network 4:
C5 Q 4.0 Q 4.0
A C5
C5 = = Q 4.0
Bit Instructions All counter functions can also operate with simple bit instructions. The
similarities and differences between this method and the counter functions
discussed so far are as follows:
• Similarities:
- Setting conditions at the "SC" input
- Specification of the counter value
- RLO change at the "CU" input
- RLO change at the "CD" input
• Differences:
- It is not possible to check the current counter value since
there are no Binary (CV) or BCD (CV_BCD) outputs.
- There is no binary output Q in the graphical representation.
01 3 5 2
29 28 27 26 25 24 23 22 21 20
Accu 1 contents after “L T...” exec. X X X X X X 0 1 0 1 1 0 0 0 0 0
01 3 5 2
Time Specification Time values can be fixed and are specified as time constants. The permissible
range in which the time values are found ranges from S5T#10ms to
S5T#2h46m30s0ms.
Variable times can be specified using variables (such as memory words or data
words) containing the S5TIME data type. The user must make sure that the
appropriate time base and the number of units of time, as shown in the slide, are
stored in the variable in his program.
Time Base The time base defines the interval at which the number of units of time is to be
decremented by one unit when the timer runs. Bits 12 and 13 of the variable
must contain the time base as a binary-coded number:
Units of Time The number of units of time must be specified as a BCD-coded number. When
the number of units of time are multiplied by the time base, this results in the
desired time value. The range from 1 to 999 is possible. When there is a time
specification using a constant (S5T#...), the system automatically uses the
smallest possible time base and the number of units of time.
L / BI At output "BI" or with the instruction "L T..." , the residual time value (number of
units of time) of the timer is queried as an integer without time base.
LC / BCD At output "BCD" or with the instruction "LC T..." , the residual time value
(number of units of time) of the timer is queried as a BCD-coded number with
the time base in Bit 12 and 13.
Network 1:
T4
I 0.0 T4 I 0.0 & SD A I 0.0
SD L S5T#5s
S5T#5s TV SD T4
S5T#5s
Network 2:
T4 Q 8.0 Q 8.0
A T4
T4 & =
= Q 8.0
Network 3:
T4
I 0.1 T4 A I 0.1
R I 0.1 & R R T4
Bit Instructions All timer functions can also be started with simple bit instructions. The
similarities and differences between this method and the timer functions
discussed so far are as follows:
• Similarities:
- Start conditions at the "S" input
- Specification of the time value
- Reset conditions at the "R" input
- Signal response at output "Q"
• Differences (for LAD and FBD):
- It is not possible to check the current time value (there are no "BI" and
"BCD" outputs).
F STL
I_DI
B MD14
EN OUT
D DI_R
ENO EN OUT MD26
MW12 IN L MW12
LAD ENO ITD
MD14 IN
DTR
T MD26
I_DI DI_R
EN ENO EN ENO
Example A user program that works with integers also needs to perform division, which is
likely to result in values less than 1. Since these values can be represented only
as real numbers, conversion to real numbers is necessary. To do this, the
integer must first be converted to a double integer.
WXOR_W L IW 0
WOR_W
L W#16#5F2A
WAND_W
AW / OW / XOW
EN ENO
T MW10
IW0 IN1
OUT MW10 15 0
W#16#5F2A IN2
IW0 = 0 1 0 0 0 0 0 0 0 0 1 1 0 0 1 0
W#16#5F2A = 0 1 0 1 1 1 1 1 0 0 1 0 1 0 1 0
AND OR XOR
WAND_W The "AND Word" operation gates the two digital values at inputs IN1 and IN2 bit
by bit in accordance with the AND truth table. The result of the AND operation is
stored at the address at output OUT.
The instruction is executed when EN = 1.
Example: Masking out the 4th decade of the thumbwheel buttons :
IW4= = 0100 0100 1100 0100
W#16#0FFF = 0000 1111 1111 1111
MW30 = 0000 0100 1100 0100
WOR_W The "OR Word" operation gates the two digital values at inputs IN1 and IN2 bit
by bit in accordance with the OR truth table. The result of the OR operation is
stored at the address at output OUT.
The instruction is executed when EN = 1.
Example: Setting bit 0 in MW32 :
MW32 = 0100 0010 0110 1010
W#16#0001 = 0000 0000 0000 0001
MW32 = 0100 0010 0110 1011
WXOR_W The "Exclusive OR Word" operation gates the two digital values at inputs IN1
and IN2 bit by bit in accordance with the XOR truth table. The result of the OR
operation is stored at the address at output OUT. The result of the XOR
operation is stored at the address at output OUT.
The instruction is executed when EN=1.
Example: detecting signal changes in IW0 :
IW0 = 0100 0100 1100 1010
MW28 = 0110 0010 1011 1001
MW24 = 0010 0110 0111 0011
General The program example displayed in the slide implements a logic for detecting a
signal change of 16 binary digits (edge detection for 16 bit) using digital word
instructions.
Network 1 For the detection of a positive edge detection, that is, the detection of a signal
change from 0 Æ 1, it suffices to carry out a digital AND operation of the change
pattern (MW 220) with the new signal states (IW 0).
Network 2 If only the 1 Æ changes are to be detected, a digital AND operation of the
change pattern with the old signal states is to be carried out.
Network 3 Save the old states so that the signal state change can be detected.