|
Variable names must also be the same as other key words in the system as shown in Figure 19.3. In addition, these variable must not have the same name as predefined functions, or user defined functions.
Invalid variable names: START, DATA, PROJECT, SFC, SFC2, LADDER, I/O, ASCII, CAR, FORCE, PLC2, CONFIG, INC, ALL, YES, NO, STRUCTURED TEXT
Valid memory/variable name examples: TESTER, I, I:000, I:000/00, T4:0, T4:0/DN, T4:0.ACC
Figure 19.3 Acceptable Variable Names
plc st -19.4
When defining variables one of the declarations in Figure 19.4 can be used. These define the scope of the variables. The VAR_INPUT, VAR_OUTPUT and VAR_IN_OUT declarations are used for variables that are passed as arguments to the program or function. The RETAIN declaration is used to retain a variable value, even when the PLC power has been cycled. This is similar to a latch application.
Declaration
VAR VAR_INPUT VAR_OUTPUT VAR_IN_OUT VAR_EXTERNAL VAR_GLOBAL VAR_ACCESS RETAIN CONSTANT AT
Description
the general variable declaration defines a variable list for a function defines output variables from a function defines variable that are both inputs and outputs from a function
a global variable
a value will be retained when the power is cycled
a value that cannot be changed
can tie a variable to a specific location in memory (without this variable locations are chosen by the compiler
END_VAR marks the end of a variable declaration
Figure 19.4 Variable Declarations
Examples of variable declarations are given below,
plc st -19.5
Text Program Line Description
VAR AT %B3:0 : WORD; END_VAR a word in bit memory
VAR AT %N7:0 : INT; END_VAR an integer in integer memory
VAR RETAIN AT %O:000 : WORD ; END_VAR makes output bits retentive
VAR_GLOBAL A AT %I:000/00 : BOOL ; END_VAR variable A as input bit
VAR_GLOBAL A AT %N7:0 : INT ; END_VAR variable A as an integer
VAR A AT %F8:0 : ARRAY [0..14] OF REAL; END_VAR an array A of 15 real values
VAR A : BOOL; END_VAR a boolean variable A
VAR A, B, C : INT ; END_VAR integers variables A, B, C
VAR A : STRING[10] ; END_VAR a string A of length 10
VAR A : ARRAY[1..5,1..6,1..7] OF INT; END_VAR a 5x6x7 array A of integers
VAR RETAIN RTBT A : ARRAY[1..5,1..6] OF INT; a 5x6 array of integers, filled
END_VAR with zeros after power off
VAR A : B; END_VAR A is data type B
VAR CONSTANT A : REAL := 5.12345 ; END_VAR a constant value A
VAR A AT %N7:0 : INT := 55; END_VAR A starts with 55
VAR A : ARRAY[1..5] OF INT := [5(3)]; END_VAR A starts with 3 in all 5 spots
VAR A : STRING[10] := test; END_VAR A contains test initially
VAR A : ARRAY[0..2] OF BOOL := [1,0,1]; END_VAR an array of bits
VAR A : ARRAY[0..1,1..5] OF INT := [5(1),5(2)]; an array of integers filled with 1
END_VAR for [0,x] and 2 for [1,x]
Figure 19.5 Variable Declaration Examples
Basic numbers are shown below. BACK | NEXT Easy Access To All Pages 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|