Siemens TIA Portal Example: Configuring a button with access protection

Publisher:芳华逝水Latest update time:2023-08-04 Source: 机器人及PLC自动化应用Author: Lemontree Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Logical operators are used for logical operations on Boolean variables, constants, and simple logical expressions formed with the help of comparison operators.

Operators Number of operands illustrate
NOT 1 reverse
AND 2 Logical "AND"
2 Logical "OR"
EXOR 2 XOR

The operands of a logic operation must be of type BOOL. The result is also always of type BOOL. The following table shows the possible results of the operation:

operate NOT A A AND B A OR B A EXOR B
A = TRUE B = TRUE FALSE TRUE TRUE FALSE
A = TRUE B = FALSE FALSE FALSE TRUE TRUE
A = FALSE B = TRUE TRUE FALSE TRUE TRUE
A = FALSE B = FALSE TRUE FALSE FALSE FALSE

This table also applies to operations performed with bitwise operators.

Example Even multiple operations are allowed.

...

DECL BOOL A,B,C

...

A=TRUE ;A=TRUE

B =NOTA ;B=FALSE

C = (A AND B)OR NOT (B EXORNOTA) ;C=TRUEA = NOTNOT C ;A=TRUE

...

Bitwise Operators

Bitwise operators operate on integers by performing logical operations on their individual bits in sequence. The result of the operation is equal to the result of the logical operator.

A bit value of 1 is equivalent to TRUE.

A bit value of 0 is equivalent to FALSE.

Operators Number of operands illustrate
B_NOT 1 Bit Reversal
B_AND 2 Bitwise AND
B_OR 2 Bitwise OR operation
B_EXOR 2 Bitwise XOR

Bitwise operators can be applied to INT and CHAR data types.

INT has 32 bits in KRL and must be marked with a positive or negative sign. CAHR has 8 bits and does not need to be marked with a positive or negative sign.

The following examples of B_AND, B_OR, and B_EXOR with integer values ​​result in a positive number (most significant bit = 0). As with unsigned values, the result can be converted directly to decimal.

28 leading zeros of an operand are represented by “00 [...]”.

B_AND

Example: Operation on integer values ​​5 and 12

B_OR

Example: Operation on integer values ​​5 and 12

B_EXOR

Example: Operation on integer values ​​5 and 12

B_NOT

For this integer example, the operation results in a negative number (highest value bit = 1). Therefore, the result cannot be converted to decimal in the same way as an unsigned number.

Example: B_NOT with integer value 10

In order for the user to understand the decimal result converted by the robot, he must know the rules for interpreting two's complement numbers. These rules are not the subject of this article.

The decimal result of a B_NOT operation with signed operands can be determined as follows:

1. Decimal value of the operand plus 1

2. Change the positive and negative signs

Other Examples

...

DECL INT A

...

A = 10B_AND9 ;A=8

A = 10B_OR 9 ;A=11

A = 10B_EXOR9 ;A=3

A = B_NOT 197 ; A = -198

A =B_NOT'HC5' ;A=-198

A =B_NOT'B11000101' ;A=-198

A =B_NOT "E" ;A=154

...

Setting and checking bits:

B_AND and B_OR can be used to specifically set individual bits of a bit sequence to 1 or 0. The remaining bits remain unchanged.

A single bit can be set to 0 using B_AND.

With B_OR, you can set a single bit to 1. In addition, you can check whether a single bit is 1 or 0. Example:

There is a digital output with a width of 8 bits. This output can be addressed via the INT variable DIG. Set bits 1, 2 and 6 to 0:

DIG = DIG B_AND 'B10111001'

Set bits 0, 2, 3, and 7 to 1:

DIG = DIG B_OR 'B10001101'

Checks whether bits 0 and 7 are set to 1. If so, my_result becomes TRUE:

DECL BOOL my_result
...
my_result = DIG B_AND ('B10000001') > 0

Operator precedence

The precedence gives the order in which operators are executed within an instruction.

Priority Operators
1 NOT; B_NOT
2 *; /
3 +; -
4 AND; B_AND
5 EXOR; B_EXOR
6 OR; B_OR
7 ==, <>; <, >, <=, >=

In principle, the following applies:

Edit the enclosed expression first.

Unquoted expressions are parsed according to their precedence.

Operations performed with operators of the same precedence are analyzed from left to right.

Mathematical standard functions

Function Numeric range independent variable Numerical range results
ABS(X)
Total
REAL_MIN…REAL_MAX 0 …REAL_MAX
SQRT(X)
square root
0 …REAL_MAX 0 …REAL_MAX
SIN(X)
Sine
REAL_MIN…REAL_MAX -1 …+1
COS(X)
cosine
REAL_MIN…REAL_MAX -1 …+1
TAN(X)
tangent
REAL_MIN…REAL_MAX REAL_MIN…REAL_MAX
OS(X)
arccosine
-1 … +1 0 …+180
ATAN2(Y,X)
inverse tangent
REAL_MIN…REAL_MAX -180 …+180

Data type of all functions: REAL. Data type of all independent variables: REAL.


Absolute value ABS(X) calculates the sum of X.

Example:

B = -3.4

A = 5*ABS(B); A=17.0

Square Root SQRT(X) Calculates the square root of X.

Example:

A = SQRT(16.0801) ;A=4.01

Sine SIN(X) Calculates the sine of angle X.

Example:

A = SIN(30) ;A=0,5

Cosine COS(X) Calculates the cosine of the angle X.

Example:

B = 2*COS(45) ;B=1.41421356

Tangent TAN(X) Calculates the tangent of an angle X.

Example:

The tangent of the following sum is infinite:

 ±90°

 +90° + k*180° (where k = ± integer)

If such a value is attempted, this will result in an error message.

C = TAN(45) ;C=1.0

Arc Cosine ACOS(X) is the inverse function of COS(X).

Example:

A = COS(60) ;A=0.5

B = ACOS(A); B = 60

Inverse sine

There is no predefined function for the inverse function of SIN(X), the inverse cosine. However, the inverse sine can be easily calculated based on the formula SIN(X) = COS(90°-X).

Example:

A=SIN(60) ;A=0.8660254
B=90-ACOS(A) ;B=60

Inverse tangent

The tangent of an angle is defined as the adjacent side (X) of a right triangle divided by the opposite side (Y). If the lengths of the two sides are known, the inverse tangent can be used to calculate the angle between the adjacent side and the hypotenuse.

For a full circle, the decisive factor is the sign of X and Y. If only the quotient is considered, the inverse tangent can only be used to calculate angles between 0° and 180°. This is usually the case with pocket calculators.

Here: A positive value of the inverse tangent yields an angle between 0° and 90°. A negative value of the inverse tangent yields an angle between 90° and 180°.

By specifying the signs for Y and X, the quadrant that lies within this angle is determined explicitly. This also allows the calculation of angles within quadrants III and IV.

Example:

A=ATAN2(0.5,0.5) ;A=+45
B=ATAN2(0.5,-0.5) ;B=+135
C=ATAN2(-0.5,-0.5) ;C=-135
D=ATAN2(-0.5,0.5 ) ;D=-45

Using X and Y in the ATAN(Y,X) function






Review editor: Liu Qing

Reference address:Siemens TIA Portal Example: Configuring a button with access protection

Previous article:What is a phonon laser? How can you make one using two ions?
Next article:Advantages and challenges of robots in injection molding processing

Latest robot Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号