|
As normal expressions that are the most deeply nested between brackets will be solved first. (Note: when in doubt use brackets to ensure you get the sequence you expect.)
! () XPY, ** SQR, TOD, FRD, NOT, NEG, LN, LOG, DEG, RAD, SIN, COS, TAN, ASN, ACS, ATN *, /, MOD +, - AND (for word) XOR (for word) OR (for word) >, >=, =, <=, <, <> AND (bit) XOR (bit) OR (bit) ladder instructions
Figure 19.13 Operator Precedence
plc st -19.10
• Language structures include those below,
IF-THEN-ELSIF-ELSE-END_IF; normal if-then structure
CASE-value:-ELSE-END_CASE; a case switching function
FOR-TO-BY-DO-END_FOR; for-next loop
WHILE-DO-END_WHILE;
Figure 19.14 Flow Control Functions
• Special instructions include those shown below.
RETAIN() causes a bit to be retentive IIN(); immediate input update EXIT; will quit a FOR or WHILE loop EMPTY
Figure 19.15 Special Instructions
• Consider the program below to find the average of five values in floating point memory.
plc st -19.11
F8:10 := 0; FOR (N7:0 := 0 TO 4) DO F8:10 := F8:10 + F8:[N7:0]; END_FOR;
Figure 19.16 A Program To Average Five Values In Memory With A For-Loop
• Consider the program below to find the average of five values in floating point memory.
F8:10 := 0;
WHILE (N7:0 < 5) DO F8:10 := F8:10 + F8:[N7:0]; N7:0 := N7:0 + 1;
END_WHILE;
Figure 19.17 A Program To Average Five Values In Memory With A While-Loop
• The example below will set different outputs depending upon the stat of an input.
plc st -19.12
IF (I:000/00 = 1) THEN O:001/00 := 1;
ELSIF (I:000/01 = 1 AND T4:0/DN = 1) THEN O:001/00 := 1; IF (I:000/02 = 0) THEN O:001/01 := 1; END_IF;
ELSE O:001/01 := 1; END_IF;
Figure 19.18 Example With An If Statement
• The example below will set output bits 00-03 depending upon the value of the integer in N7:0, if the value is not between 0 and 3 the outputs will all go off.
CASE N7:0 OF
0: O:000/00 := 1;
1: O:000/01 := 1;
2: O:000/02 := 1;
3: O:000/03 := 1; ELSE
O:000 := 0; END_CASE;
Figure 19.19 Use of a Case Statement
• The example below accepts a BCD input from (I:000) and will use it to change
plc st -19.13
the delay time for an on delay timer that will examine input I:002/00 drive output O:001/
00.
FRD (I:000, DELAY_TIME); IF (I:002/00) THEN TON (T4:0, 1.0, DELAY_TIME, 0); ELSE
RES (T4:0); END_IF; O:001/00 := T4:0.DN;
Figure 19.20 Function Data Conversions
• Try the example below,
plc st -19.14
Write a structured text program to control a press that has an advance and retract with limit switches. 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
|