您现在所在的是:

西门子SIEMENS

回帖:31个,阅读:6493 [上一页] [1] [2] [3] [4] [下一页]
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 19:59:00
#20楼
Global and local variables
The scope of each variable which is determined by the use of the variable keyword is limited either to a POU or to the whole project. Therefore two types can be distinguished:

Local variables


Global variables
If a variable can be used only within a POU it is called local variable. In those cases the variable keywords VAR, VAR_INPUT and VAR_OUTPUT can be used.

If a variable can be used within the whole project it is called global variable. It has to be declared as VAR_GLOBAL in the global declaration and as VAR_EXTERNAL in each POU where it is used.

It might be useful to declare all I/Os as global variables. In the global variable declaration they should be declared as located variables and in the VAR_EXTERNAL declaration of the POU they should be declared as symbolic variables. The typing effort in case of address changes is less doing it this way.
图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 19:59:00
#21楼
Symbolic variables
Symbolic variables are declared with a symbolic name and a data type. The initial value is optional.

The programming system stores the variable to free memory areas of the PLC memory which are not known to the user.

The following example shows a variable declaration of two symbolic variables:

VAR
   var1:    BOOL;
   var2:    INT (-22..12);
END_VAR

Symbolic variables can be initialized and/or can be declared as retentive variables using the keyword 'RETAIN'.

图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 19:59:00
#22楼
Directly represented and located variables
Directly represented variables are declared without symbolic name but using a logical address.

Located variables are declared using a symbolic name and a logical address.

Both, directly represented and located variables are stored at the declared logical address and it is up to the application programmer to check that no memory address is used twice.

A location declaration consists of the keyword AT, the percent sign "%", a location prefix, a size prefix and the name of the logical address.

Directly represented and located variables can be declared in the global variable worksheet using VAR_GLOBAL or in programs.

The following tables show the location and size prefix for directly represented and located variables:

Location prefix Description
I Physical input
Q Physical output
M Physical address in the PLC memory
Size prefix Description
X Single bit size (only with data type BOOL)
None Single bit size
B Byte size (8 bits)
W Word size (16 bits)
D Double word size (32 bits)
L Long word size (64 bits)


In the following example a declaration of directly represented and located variables is shown:

VAR
   var1    AT %QX 2.4    : BOOL;
   var2    AT %IW4    : WORD;
       AT %QB 7    : BYTE;
END_VAR
图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:00:00
#23楼
Retentive variables
Retentive variables are variables whose values are stored even if the power is switched off. In the case of a warm start the last value of the variable is going to be used.

Retentive variables are declared using the keyword RETAIN as it is shown in the following example:

VAR RETAIN
   var1    :    BOOL    := TRUE;
END_VAR
In this example the variable has got the initial value 'TRUE' which is the initial value for a cold start. In case of a warm start the current value of the variable is used.
图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:00:00
#24楼
Initializing variables
According to IEC 1131-3 initial values can be assigned to variables. This means that a variable which is going to be used for the first time in the PLC program is used with its initial value. Initial values can be given to all kind of variables except in VAR_EXTERNAL declarations.

Initial values have to be inserted at the end of the declaration line of the variable using ':=' as it is shown in the following example:

VAR
   var1:    INT := 28;
   var2:    TIME := T#1s;
   var3:    AT%QX0.0 := TRUE;
END_VAR
It is not possible to initialize variables which are located at physical inputs.

The initial value has to fit to the data type. It is not possible to use e.g. the data type BOOL and an initial value '5'. In this case the system displays an error message.

The initial value is optional. If no initial value is used, the variable is initialized with the default initial value of the data type or with the retained value in case of retentive variables.
图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:00:00
#25楼
Programming languages in IEC 1131-3
IEC 1131-3 defines the syntax of 5 programming languages, defines a certain representation and describes the different elements which can be used in the language.

The programming languages can be differentiated by the physical appearance into 2 textual languages and 3 graphical languages.

The textual languages are Instruction List (IL) and Structured Text (ST).

The graphical languages are Function Block Diagram (FBD), Ladder Diagram (LD) and Sequential Function Chart (SFC).

图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:00:00
#26楼
Instruction List - IL
A code body programmed in the textual language IL consists of a sequence of instructions. Each instruction starts at a new line.

An example of a simple IL instruction sequence is shown in the following figure:

   LD        var1    (* loading operand into accumulator *)
   AND    var2    (* processing accumulator with operand *)
   ST        var3    (* storing accumulator into memory *)
Each line begins with an operator followed by one operand. Additionally modifiers can be used.

In IL code bodies jumps can be used. An example for a jump and the use of its label is shown in the following figure:

       LD        var1
       EQ        INT#100
       JMPC    label
       LD        var2
       ADD    var3
       ST        var4
label:    LD        %IX2.2
In IL code bodies comments can be inserted using asterisks and parentheses.

图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:00:00
#27楼
Structured Text - ST
A code body programmed in the textual language ST consists of statements and expressions.

Different types of statements can be used while editing. All statements have to finish with a semicolon.

An expression is a construct which returns one value for the execution of statements. Expressions consist of operators and operands. The operators have to be applied to the operands in the way that the operator with the highest precedence is followed by the operators with the next lower precedence.

In ST code bodies comments can be inserted using asterisks and parentheses.

图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:01:00
#28楼
Function Block Diagram - FBD
A code body programmed in the graphical language FBD is composed of functions and function blocks which are connected with each other or with variables using lines. These lines can also be connected with each other. In FBD networks it is not possible to connect outputs with outputs.

The set of connected objects is called FBD network.

Connectors can be used in case of large networks for better structuring the elements in the worksheet. Connectors replace connection lines.

Jumps can be used to jump to a label in the current worksheet.

Returns can be inserted to go back to the calling POU.

图
6285
karl 版主
文章数:1703
年度积分:48
历史总积分:6285
注册时间:2003/12/26
发站内信
发表于:2004/11/3 20:01:00
#29楼
Ladder Diagram - LD
A code body programmed in the graphic language LD is composed of contacts and coils. According to IEC 1131-3 different types of contacts and coils can be used. The contacts lead according to their type the power from the left to the right. Coils store the incoming value to Boolean variables.

These contacts and coils are connected with lines and are bounded on the left and on the right with power rails. The state of the left power rail is considered ON all the time. The right rail is optional.

In addition to the serial connections of contacts and coils parallel branches can be created. Parallel branches are also called wired-ORs.

The set of connected objects is called LD network. Every LD network shall at least contain one coil and a left power rail.

Connectors can be used in case of large networks for better structuring the elements in the worksheet. Connectors replace connection lines.

Jumps can be used to jump to a label in the current worksheet.

Returns can be inserted to go back to the calling POU.

Variables in LD code bodies are always Boolean variables. While inserting contacts or coils the variable name can be entered. The variable name is displayed above the contact or coil in the worksheet.

图

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

62.4004