Lab5 - Nguyễn Hoàng - Eeaciu22164
Lab5 - Nguyễn Hoàng - Eeaciu22164
I. OBJECTIVES
1. Introduction of a number of math functions that are supported in TIA PORTAL;
2. Apply to an experiment and exercises.
II. INTRODUCTION
The introduction of mathematical operations in the PLC provided major benefits to control logic.
Numeric data could be combined with logic to provide more powerful control strategies. For
instance, decisions could be made concerning mathematical operations concerning counts of
products, weights of a product, the temperature of an oven or any numeric variable in a process.
The instructions are briefly divided into three categories: Compare, Math, and Move.
1. Compare
Compare instructions
Figure 1
The compare instructions are used to compare two values of the same data type (6 types: Int, DInt,
Real, Word, Dword). When the LAD contact comparison is TRUE, then the contact is activated.
Relation type TRUE/ FALSE
== IN1 equals to IN2
<> IN1 does not equal to IN2
>= IN1 is greater than or equal to IN2
<= IN1 is less than or equal to IN2
> IN1 is greater than IN2
< IN1 is less than IN2
Figure 2
The IN_RANGE and OUT_RANGE instructions are used to test whether an input value is in or out
of a specified value range. If the comparison is TRUE, then the box output is TRUE. The input
parameters MIN, VAL, and MAX must be the same data type.
2. Math
Figure 3
When enabled (EN = 1), the math instruction performs the specified operation on the input values
(IN1 and IN2) and stores the result in the memory address specified by the output parameter
(OUT). After the successful completion of the operation, the instruction sets ENO = 1. Note
that, ENO is the status to indicate whether there is error in the calculation. EN0=1 indicates that
there is no error while ENO=0 indicates the error depending on the situation that the process has
made error.
Limit instructions
Figure 4
The LIMIT instruction is used to test if the value of parameter IN is inside the value range
specified by parameters MIN and MAX. The OUT value is clamped at the MIN or MAX value,
if the IN value is outside this range.
• If the value of parameter IN is inside specified range, then the value of IN is stored in
parameter OUT.
• If the value of parameter IN is outside of the specified range, then the OUT value is the
value of parameter MIN (if the IN value is less than the MIN value) or the value of
parameter MAX (if the IN value is greater than the MAX value).
3. Move
Use the MOVE instructions to copy data elements to a new memory address and convert from one
data type to another. The source data is not changed by the move process. There are some types of
Move instructions such as:
i. MOVE: Copies a data element stored at a specified address to a new address
ii. MOVE_BLK: Interruptible move that copies a block of data elements to a new address
iii. UMOVE_BLK: Uninterruptible move that copies a block of data elements to a new Address
Rules for data copy operations
i. To copy the Bool data type, use SET_BF, RESET_BF, R, S, or output coil (LAD)
ii. To copy a single elementary data type, use MOVE
iii. To copy an array of an elementary data type, use MOVE_BLK or UMOVE_BLK
iv. To copy a structure, use MOVE
v. To copy a string, use S_CONV
vi. To copy a single character in a string, use MOVE
vii. The MOVE_BLK and UMOVE_BLK instructions cannot be used to copy arrays or
structures to the I, Q, or M memory areas.
Description of MOVE, MOVE_BLK, UMOVE_BLK
a)
b)
c)
Figure 5
The MOVE instruction (Figure 5a) copies a single data element from the source address
specified by the IN parameter to the destination address specified by the OUT parameter. The
MOVE_BLK (Figure 5b) and UMOVE_BLK (Figure 5c) instructions have an additional
COUNT parameter. The COUNT specifies how many data elements are copied. The number of
bytes per element copied depends on the data type assigned to the IN and OUT parameter tag
names in the PLC tag table.
Besides, MOVE_BLK and UMOVE_BLK instructions differ in how interrupts are handled:
1. Interrupt events are queued and processed during MOVE_BLK execution. Use the
MOVE_BLK instruction when the data at the move destination address is not used
within an interrupt OB subprogram or, if used, the destination data does not have to
be consistent. If a MOVE_BLK operation is interrupted, then the last data element
moved is complete and consistent at the destination address. The MOVE_BLK
operation is resumed after the interrupt OB execution is complete.
2. Interrupt events are queued but not processed until UMOVE_BLK execution is
complete. Use the UMOVE_BLK instruction when the move operation must be
completed and the destination data consistent, before the execution of an interrupt
OB subprogram
The summary of the three listed Move instructions is described in the following table:
Convert:
The CONVERT instruction is used to convert a data element from one data type to another data
type. Click below the box name and then select IN and OUT data types from the dropdown list.
Figure 6
After selecting the (convert from) data type, a list of possible conversions is shown in the
(convert to) dropdown list. Notice that Conversions from and to BCD16 are restricted to the Int
data type. Conversions from and to BCD32 are restricted to the DInt data type.
Exercise 2. Use Convert instruction to change a BCD value in the memory MW30 to become a
Real data in the memory MD96.
Ans:
IV. EXPERIMENTS
Experiment 1. Write a PLC algorithm to count the number of products which are carried on a
conveyor belt to a storage house. The procedure is described as follows
1. Press START to allow the conveyor belt to transport the products to the storage house. A
light sensor PEB is used to detect the number of products which have been transported to the
storage house.
2. If there is any product in the storage house, the light Stor_not_Empty is ON.
3. If there are 5 products in the storage house, the light Stor_50%_Full is ON.
4. If there are 9 products in the storage house, the light Stor_90%_Full is ON.
5. If there are 10 products in the storage house, the light Stor_Full is ON and the belt stops
transporting the products.
6. The system only restarts working after all the products have been moved out from the storage
house and the START button is pressed
7. Note that the operator can press STOP to cancel the working process in emergency case.
After the fault has been dealt, the operator can press START to resume working.
b) Result:
Start simulation:
c) discussion:
- In this lab, we apply the concepts of Math Instructions and review the functionality of
the CTU (Count Up) block. By utilizing Compare instructions, we address all problem
requirements effectively.
- Through this process, we evaluate the values of Compare contacts and determine the
appropriate relationship type for each case.
- Upon completing the problem, we gain a clear understanding of how to use Compare
contacts in the TIA Portal and how to define their required inputs accurately.