Académique Documents
Professionnel Documents
Culture Documents
Release 1.1
User Manual
Because of the variety of uses for the products described in this
publication, those responsible for the application and use of this control
equipment must satisfy themselves that all necessary steps have been
taken to assure that each application and use meets all performance and
safety requirements, including any applicable laws, regulations, codes
and standards.
The illustrations, charts, sample programs and layout examples shown in
this guide are intended solely for purposes of example. Since there are
many variables and requirements associated with any particular
installation, Allen-Bradley does not assume responsibility or liability
(to include intellectual property liability) for actual use based upon the
examples shown in this publication.
Allen-Bradley publication SGI-1.1, Safety Guidelines for the Application,
Installation, and Maintenance of Solid State Control (available from your
local Allen-Bradley office), describes some important differences between
solid-state equipment and electromechanical devices that should be taken
into consideration when applying products such as those described in
this publication.
Reproduction of the contents of this copyrighted publication, in whole
or in part, without written permission of Allen-Bradley Company, Inc.,
is prohibited.
Throughout this manual we use notes to make you aware of
safety considerations:
ATTENTION: Identifies information about practices or
circumstances that can lead to personal injury or death, property
damage or economic loss.
Attention statements help you to:
identify a hazard
avoid the hazard
recognize the consequences
Important: Identifies information that is critical for successful application
and understanding of the product.
Important User Information
Structured Text User Manual
i
Summary of Changes
This release of the publication contains updated information.
For this updated information: See:
corrected the smallest and largest floating point values chapter 1
rule about using a single % character in a structured text file chapter 1
information about using and exiting iterative loops chapter 2
memory requirements for constructs chapter 2
how to access the database editor and the data monitor from
the structured text editor
chapter 3
information about accepting structured text edits chapter 3
information about editing structured text files in multiple
Windows sessions
chapter 3
clarification about how the PowerText feature intensifies
addresses with NOT operands
chapter 4
how to toggle between displaying addresses and symbols
when monitoring structured text
chapter 4
correction to the programming example for creating a
configurable data monitor with a structured text file
chapter 4
additional programming example for a sort routine appendix A
information about debugging structured text programs appendix A
new appendix that lists the supported processor instructions,
syntax, valid operands, and whether an instruction requires a
false-to-true transition before executing
appendix B
new appendix that shows an example of an ASCII structured
text file that you can import into 6200
appendix C
To help you find new information in this publication, we included change
bars as shown to the right of this paragraph.
Whats New
Preface
Structured Text User Manual
i
Structured Text User Manual
6200 Programming Software
Structured Text
Your PLC-5
series C, revision C
and later processors. To use release 1.1 of structured text, you must install
release 5.0 of 6200 PLC-5 programming software (catalog number
62xx-PLC5) and then install release 1.1 of PLC-5 structured text (catalog
number 6203-ST5).
Important: Install the 6200 programming software first; then install the
structured text disk last. For information on installing this disk, see the
next section. For more information, see the PLC-5 Configuration and
Maintenance manual, publication 6200-6.4.6.
1. Turn on the computer.
2. When the DOS prompt appears, insert the structured text disk into the
disk drive. Type:
A: Return
INSTALL C: Return
Chapter Objectives
Using Structured Text
Installing the Software
Writing Structured Text
Chapter 1
1-2
Structured Text User Manual
You see:
*
*
*
*
*
*
*
*
***********************************************************************
Press Any Key to Start Installation
*
*
*
*
*
*
*
*
Allen-Bradley Company, Inc., Copyright 1995, All rights reserved.
Allen-Bradley Company, Inc. grants you a license to install
and use this software on a single processing unit. You are not licensed to
install the software on more than one processing unit or to distribute it in
any way. Support and updates will be provided to registered customers
only. To register your software, return the enclosed registration card as
soon as possible.
WARNING
THIS SOFTWARE IS PROTECTED UNDER THE COPYRIGHT LAWS OF THE UNITED STATES.
UNAUTHORIZED REPRODUCTION OF COPYRIGHTED SOFTWARE VIOLATES U.S. COPYRIGHT
LAWS. CRIMINAL PENALTIES
MAY INCLUDE FINES OR IMPRISONMENT.
******************************************************************
******************************************************************
Contents: PLC-5 Prog Structured Text Programming Option
Catalog Number: 6203-ST5
Part Number: XXXXXX-XX
Release Number: 1.1 Quantity 1 Disk
Press any key
Press
Contents: PLC-5 Prog Structured Text Programming Option
Catalog Number: 6203-ST5
Part Number: XXXXXX-XX
Release Number: 2.0 Quantity 1 Disk
Product Registration Information
Company Name:
Address:
:
Serial Number:
Instructions
Enter your company name and address.
You can find the serial number on the front
of the product box. Format is AA0AA0AA.
Enter product registration info and press F9
When you are finished, press
F9
1
2
3
4
Return
Company Name: Allen-Bradley
Address: 747 Alpha Drive
: Highland Hts OH 44143
Serial Number:: XXOXXOXX
Press ENTER to continue with the installation
Writing Structured Text
Chapter 1
1-3
Structured Text User Manual
After you enter the product registration, you see:
Contents: PLC-5 Prog Structured Text Programming Option
Catalog Number: 6203-ST5
Part Number: XXXXXXXXX
Release Number: 1.1 Quantity x Disks
Instructions
The File Copy portion of Install is Complete: Press ENTER
Status
98% Complete
0% 25% 50% 75% 100%
Copy UPD.EXE to C:\IPDS\UPD.EXE
Enter
After structured text is installed,
press
The percent completion bar
advances as the installation
progresses.
The file names display as they
are copied to your hard disk.
5
To write structured text, you need to understand the following definitions:
a structured text command. Depending on its function, a construct may
require one or more lines. For example,
REPEAT
N7:0 := N7:0 + 1;
UNTIL N7:0 > (N7:10 / 10)
END_REPEAT;
any standard PLC-5 operand address. An operand can also be a symbol.
For example, N7:0.
any standard PLC-5 bit operand address. For example, B3/0.
a constant number, integer, or floating point, appearing directly in the
expression. Valid integers must fall within the range of -32768 to +32767.
The largest floating point magnitude is 3.402823e
+38
. The smallest
floating point magnitude is 5.877472e
-39
.
If an integer value falls outside of these ranges, it is truncated to 16 bits.
No error is flagged.
Writing Structured Text
construct
operand
bit operand
immediate
Writing Structured Text
Chapter 1
1-4
Structured Text User Manual
a sequence of operands and/or immediates separated by math operators or
acted on by a math function. See the following list of operators.
Operator: Function: Operator: Function:
+ add LN natural log
subtract LOG log to the base 10
/ divide DEG degree (convert radians to degrees)
* multiply RAD radian (convert degrees to radians)
modulo (MOD) returns the remainder of an integer divide SIN sine
SQR square root COS cosine
FRD convert from BCD TAN tangent
TOD convert to BCD ASN arc sine
NOT logical NOT ACS arc cosine
NEG negate ATN arc tangent
a sequence of 2 operands, immediates, and/or math expressions separated
by one of the following operators.
Operator: Function:
< less than
> greater than
= equal
<= less than or equal
>= greater than or equal
<> not equal
any valid ladder input instruction (excluding LBL and SBR) or compare
expression. You can examine the state of a bit by specifying the address of
the bit you want (i.e. I:0/0). This operand or expression is true if the
specified bit is a logical 1. To invert the logic (the operand or expression is
true if the bit is a logical 0) precede the bit address with a ! (i.e. !I:0/0).
For example, XIC (I:0/0).
math expression
compare expression
input instruction
Writing Structured Text
Chapter 1
1-5
Structured Text User Manual
a sequence of input instructions separated by boolean AND, OR, or XOR.
(You can only use XOR with bit operands and compare expressions. You
can implement a ladder function extension by assigning the logic state to a
bit and using the bit address in the XOR expression).
Precedence in an expression is evaluated according to the following list
(from highest to lowest priority):
1. !(bit inversion)
2. parentheses
3. exponentiation (** or XPY())
4. SQR(), TOD(), FRD(), NOT(), NEG(), LN(), LOG(), DEG(), RAD(),
SIN(), COS(), TAN(), ASN(), ACS(), ATN()
5. *, / , MOD
6. +,
7. logical AND (whole word value)
8. logical XOR (whole word value)
9. logical OR (whole word value)
10. =, <>, >, <, <=, >=
11. boolean AND (1 bit wide)
12. boolean XOR (1 bit wide)
13. boolean OR (1 bit wide)
14. ladder instructions
any valid ladder output instruction (excluding JMP, END, MCR, FOR,
BRK, NXT, MSG, SDS, DFA, AND, OR, XOR, and TND) or math
expression. If you need the MSG, SDS, or DFA instructions, put them in a
ladder file and use a JSR instruction to execute that file from a structured
text file. For example, MOV N7:46 N7:36
one or more tabs, spaces, returns, and/or blank lines. Use whitespace to
make your program more readable.
input expression
output instruction
whitespace
Writing Structured Text
Chapter 1
1-6
Structured Text User Manual
Follow these rules when writing structured text:
Important: Do not insert a single % character in a structured text file.
When you accept the edits, the software deletes the rest of the file that
follows the % character because the software assumes the remainder of the
file is a comment.
Keywords, operators, and operands MUST be separated by whitespace
For example:
The I character indicates where you should enter a space.
N7:0I:=I10;
N7:0I:=IN7:10;
N7:0I:=IR6:0.LEN;
F8:0I:=I((N7:1I*I3.14)I+I(N7:3I/IN7:4));
Each statement must end with a semicolon. See chapter 3.
String data types are not supported by the PowerTextt feature.
For example, entering (ST15:0 := ST15:1) is not supported. String
data values in length (but not position) are supported. Therefore,
(ST15:0.LEN := N7:0) is supported.
Structured text is not case sensitive (i.e. WHILE, While, and while are
all equivalent).
When writing or entering a program, you can use a semicolon anywhere
(see important note below) you would use a colon. For example, you
can enter N7:0 := N7:1; as N7;0 ;= N7;1 ;. But the converse is not true -
N7:1 := N7:1: is incorrect, because each statement must end with
a semicolon.
Important: The only exception to the above rule is in the case specifier.
For example:
CASE N7:0 Of
1:
(1; is invalid.)
Important: Due to the expansion of the display by the PowerText
feature, there is a 16 line (1 line = 80 characters) limit in Run mode for a
continuous line of structured text. Although these expressions can span
multiple lines, they must not exceed 16 lines in Run mode. Note that a
construct that takes 16 lines in Program mode may take more than 16
lines in Run mode. See the table describing field widths on page 4-5.
Rules for Writing
Structured Text
Writing Structured Text
Chapter 1
1-7
Structured Text User Manual
When writing or entering a program, the following are equivalent
and interchangeable:
This Is: Equivalent and Interchangeable With:
{ DO, THEN, OF
ELSIF ELSE_IF, ELSEIF
AND (boolean) &&, &
OR (boolean) ||
} (no semicolon
required)
END_FOR;, END_CASE;, ENDIF;,
ENDWHILE;, ENDREPEAT;,
END_WHILE;, END_REPEAT;,
ENDFOR;, ENDCASE;, END_IF;
Important: Although you can use braces ({}) when writing or entering
a program, the syntax of structured text is different than that used in the
standard C programming language. In the following comparison, the
original program version does not have matching pairs of braces. In
structured text, this is correct syntax.
Standard Format: Original Program:
IF (N7:0 = 1) THEN
Structured Text
ELSIF (N7:3 = 27) THEN
Structured Text
ELSE
Structured Text
ENDIF ;
(Code to do one of three things using
standard nomenclature.)
IF (N7:0 = 1) {
Structured Text
else_if (N7:3 = 27) {
Structured Text
ELSE
Structured Text
}
(Code to do one of three things using { }
nomenclature.)
The following words are reserved and you should not use them
as symbols:
- any ladder instruction mnemonic (i.e. LOG, DEG)
- any structured text keyword or equivalent (i.e. CASE, FOR)
- START, DATA, PROJECT, SFC, SFC2, LADDER, I/O, ASCII,
CAR, FORCE, PLC2, CONFIG, INC, ALL, YES, NO,
STRUCTURED TEXT
Writing Structured Text
Chapter 1
1-8
Structured Text User Manual
The structured text compiler handles spaces around constructs as
described in the example below.
Construct
Construct
End
Blank Line 1
Blank Line 2
XX := YY;
Blank Line 3
XX := YY;
Blank Line 4
no line
no line
The compiler inserts blank lines before and after the
first level of the following constructs (not nested
constructs): IF, ELSEIF, ELSE, CASE, FOR, WHILE,
REPEAT. See Blank Line 1 and Blank Line 2 and the
arrows indicating no lines between nested constructs.
The compiler removes the blank lines you insert in
places other than before and after the first level of the
above constructs, i.e. before or after a variable
assignment, before or after a ladder function. See
Blank Line 3 and Blank Line 4. If you insert these
lines, the compiler removes them.
End Construct
Chapter
2
2-1
Structured Text User Manual
Structured Text Constructs
After you prepare your design specification and, if applicable, enter your
sequential function chart (SFC), you are ready to enter the structured text
that runs your application. Use this chapter to learn about the structured
text constructs that you can use. The following table lists page references
for each construct.
If You Want to: Use this: See Page:
assign an integer or floating point value
to a data table location
variable assignment 2-2
make bit assignments (non-retentive) non-retentive bit
assignment
2-2
make bit assignments (retentive) retentive bit
assignment
2-3
conditionally execute a section of code IF-ELSIF-ELSE 2-4
conditionally execute a section of code
based on the value of a math expression
or operand
CASE 2-5
repeat a section of code a specified
number of times
FOR 2-6
repeat a section of code as long as an
input condition is true
WHILE 2-7
repeat a section of code until an input
condition becomes true
REPEAT 2-8
exit an iterative command (FOR, WHILE,
or REPEAT) before it reaches the normal
termination condition
EXIT 2-9
perform no function, treated as
whitespace
;; 2-10
call PLC-5 input instruction or output
instruction as functions
ladder functions 2-10
The last section in this chapter provides guidelines for the memory
requirements for the constructs.
ATTENTION: The examples throughout this publication are
meant to help you create your own structured text programs.
They may need modification to work correctly for
your application.
Chapter Objectives
Structured Text Constructs
Chapter 2
2-2
Structured Text User Manual
Use this construct to assign an integer or floating point value to a data
table location. See the following formats and examples.
Format: Examples:
operand := immediate ; N7:0 := 10;
operand := operand ; N7:0 := N7:10;
N7:0 := R6:0.LEN;
operand := math expression ;
N7:0 := R6:0.LEN;
F8:0 := ((N7:1 * 3.14) + (N7:3 / N7:4));
Variable assignments are synonymous with MOV instructions. The source
of the MOV instruction corresponds to the right side of the variable
assignment and the destination of the MOV instruction corresponds to the
left side of the assignment.
MOV
Source
Destination
N30:0
N30:1
N30:1 := N30:0
Use this construct to make binary assignments to a storage bit. These bit
addresses are non-retentive (they are cleared to 0 when the processor mode
changes from Program to Run or when an SFC step with the structured text
file as an action is postscanned). See the following formats and examples:
Format: Examples:
bit_operand := 0;
bit_operand := 1;
bit_operand := bit_operand;
bit_operand := compare_expr;
B3/0 := 0;
N7:0/0 := 1;
O:0/0 := N7:0/0;
B3:0/11 := N7:1 <
N7:2;
B3/0 is set to the value of 0.
N7:0/0 is set to the value of 1.
O:0/0 is set to the value of N7:0/0, 1 or 0.
If N7:1 is less than N7:2 then B3:0/11 is set
to the value of 1; if N7:1 is not less than
N7:2, then B3:0/11 is set to the value of 0.
See the table below.
If the Compare
Expression Is:
The Assignment
Value Is:
true 1
false 0
Variable Assignment (:=)
Non-Retentive Bit
Assignments (:=)
Structured Text Constructs
Chapter 2
2-3
Structured Text User Manual
Use this construct to make binary assignments to a storage bit. These bit
addresses are made retentive (they are not cleared to 0 when the processor
mode changes from Program to Run or when the SFC step is postscanned)
using the RETAIN function. See the following formats and examples.
Formats: Examples:
bit_operand := RETAIN (0);
bit_operand := RETAIN (1);
bit_operand := RETAIN (bit operand);
bit_operand := RETAIN (compare expression);
B3/0 := RETAIN (0);
N7:0/0 := RETAIN (1);
O:0/0 := RETAIN (N7:0/0);
N7:0/0 := RETAIN (N7:1 < N7:2);
B3:0 is set to 0.
N7:0/0 is set to 1.
If N7:0/0 is set to 1
then O:0/0 is set
to 1. If N7:0/0 is
set to 0, then O:0/0
is set to 0.
If N7:1 < N7:2 then
N7:0/0 is set to 1.
If N7:1 is not less
than N7:2, then N7:0/0
is set to 0. See the
table below.
If the Compare
Expression Is:
The Assignment
Value Is:
true 1
false 0
Retentive Bit Assignments
(RETAIN)
Structured Text Constructs
Chapter 2
2-4
Structured Text User Manual
Use this construct to conditionally execute a section of code. If the input
expression is true, the code is executed. If the input expression is false, the
code is skipped and execution continues at the next ELSE, ELSE_IF, or
END_IF statement. If there are false inputs, you can specify an alternate
conditional code section (ELSIF) or a default code section (ELSE).
You can only specify one ELSE for each IF, but you can specify any
number of ELSIFs. You can also use any structured construct, including
another IF, in the code section. An END_IF statement marks the end of
the construct. See the following formats and examples.
Format: Examples:
IF input expression THEN
Structured Text
END_IF;
IF input expression THEN
Structured Text
ELSE
Structured Text
END_IF;
IF input expression THEN
Structured Text
ELSIF input expression THEN
Structured Text
..........
ELSIF input expression THEN
Structured Text
ELSE
Structured Text
END_IF ;
IF I:000/0 THEN
N7:0 := N7:1 + N7:2;
END_IF ;
IF N7:0 < (N7:1 + N7:2) THEN
N7:0 := N7:0 +1;
ELSE
N7:1 := N7:1 + 1;
N7:2 := N7:2 1;
END_IF;
IF I:000/0 AND !I:001/5 THEN
N7:0 := 1;
ELSIF I:000/2 OR (N7:5 <> (N7:6 *
N7:2)) THEN
N7:0 := 2;
ELSIF !I:001/4 THEN
N7:0 := 3;
ELSE
N7:0 := 4;
END_IF;
IF I:000/0 THEN
IF I:005/1 THEN
N7:0 := 1;
ELSIF I:007/2 THEN
N7:0 := 2;
ELSE
N7:0 := 3;
END_IF;
ELSE
N7:0 := 4;
END_IF;
nested IF
end of nested IF
IF-ELSIF-ELSE
You can put multiple
structured statements within each
part of a single construct. If one of the
input expressions is true, the code
section following it executes and then
execution continues at the line after
the END_IF statement. No other
ELSIF or ELSE statements are
executed if a true input expression is
found earlier.
code section
Structured Text Constructs
Chapter 2
2-5
Structured Text User Manual
Use this construct to conditionally execute a section of code based on the
value of a math expression or operand. You can compare the operand or
expression to a single value, list of values, or range of values.
Enter a list of values by typing the values and separating each by a comma.
Enter a range of values by typing the lower number, two dots, and then the
higher number. You can also enter a single value. The value(s) must end
with a colon.
You can use integer, floating point, or mixed modes for the math
expression and case values. You can also use both immediate integers
and integer operand addresses for the case values. See the following
format and examples.
Important: Since floating point values are rarely absolutely equal, we
recommend that you use only ranges for floating point cases. Also, you
must specify operand addresses to a single integer or floating point value.
Important: The processor only executes one section of code. If the
expression result matches more than one value, the processor executes the
first one it finds. You can specify a default case (ELSE) that executes
if none of the values matches. An END_CASE marks the end of
the construct.
Format: Examples:
CASE math_expr or operand OF
value:
Structured Text
value,value:
Structured Text
value .. value:
Structured Text
value, value..value:
Structured Text
ELSE
Structured Text
END_CASE;
CASE N7:0 OF
0:
N7:1 := 1;
1,9:
N7:1 := 2;
2..4:
N7:1 := 3
10,5..8:
N7:1 := 4;
ELSE
N7:1 := 5;
END_CASE;
CASE F8:0 OF
5.001 .. 5.625:
N7:1 := 3;
N7:0 , N7:5 .. F8:5 :
N7:1 := 4;
ELSE
N7:1 := 5;
END_CASE;
IF N7:0 = 0
IF N7:0 = 1 or 9
IF 2 <= N7:0 <= 4
IF N7:0 = 10 OR 5 <= N7:0 <= 8
Default
Default
recommended range check
mixed mode
CASE
single value
list of values
range of values
mixed list and range
default case
Structured Text Constructs
Chapter 2
2-6
Structured Text User Manual
Use this construct to repeat a section of code a specified number of times.
To use the FOR construct, specify the following: a variable to use as the
loop counter, an initial value, a terminal value, and an increment. The first
time through the loop, the processor sets the loop counter to the initial
value. Each subsequent time through the loop, the processor adds the
increment value to the loop counter. When the loop counter exceeds the
the terminal value (or falls below the terminal value when counting down),
the program exits the loop.
Keep in mind the following considerations:
The initial value, terminal value, and increment value can be positive or
negative. All parameters, however, must be integers.
You can use both immediate integers and integer operand addresses for
the initial value, terminal value, and the increment value. For example:
FOR N7:0 := N7:1 TO N7:2 BY N7:3 DO
N7:4 := N7:4 + 1 ;
END_FOR ;
OR
FOR N10:0 := 100 to 0 BY 1 DO
CTU (C5:0, 100, ));
END_FOR ;
If you do not specify an increment value, the default is to add 1.
If the processor meets the conditions for termination at initialization, it
does not execute the loop. I.E., in the above example, if N7:0 already
equals N7:2, N7:4 is not incremented.
An END_FOR statement marks the end of the construct. See the following
formats and examples.
Format: Examples:
FOR operand := initial TO terminal BY increment DO
Structured Text
END_FOR;
FOR operand := initial TO terminal DO
x
Structured Text
END_FOR;
FOR N7:0 := 10 TO 0 BY -1 DO
N7:4 := N7:4 + 1;
END_FOR;
FOR N7:0 := 0 To 10 DO
N7:1 := N7:1 + 1;
END_FOR;
x
If no increment value, default = 1.
FOR
code inside the loop
default: increment by 1
Structured Text Constructs
Chapter 2
2-7
Structured Text User Manual
Important: Do not use I/O addresses in iterative constructs as test values
because they will not be updated by real I/O. The PLC-5 processor is
processing the loop and it cannot continue to the end of the program where
it performs housekeeping and updates remote I/O.
In a running processor, all structured text constructs complete before the
program scan continues. If the FOR loop takes longer to complete than the
watchdog setpoint, the watchdog timer times out. This is a major fault that
shuts down the processor.
Important: When the processor runs a FOR loop, all other processing is
put on hold, like checking for a change in the processor keyswitch or a
change in I/O status. The following examples show how to exit a FOR
loop. You can also use these methods with WHILE and
REPEAT constructs.
Method: Examples:
IIN instruction FOR N7:0 := 10 TO 0 BY -1 DO
N7:4 := N7:4 + 1;
IIN (000);
IF (I:000/00) THEN
EXIT;
END_IF;
END_FOR;
EXIT construct FOR N7:0 ;+ 0 TO 20 DO
N7:1 := N8:0 + N8:1;
IF (B3:0/0 = 1) THEN
EXIT;
END_IF;
END_FOR;
Use this construct to repeat a section of code as long as an input expression
is true. If the input expression is false, the processor skips the construct.
If the input expression is true, the processor executes the code in the loop.
When the processor completes the code, it rechecks the input expression.
If the expression is still true, the processor repeats the loop. This process
continues until the processor finds the expression false and exits the loop.
An END_WHILE statement marks the end of the construct. See the
following formats and examples.
Format: Examples:
WHILE input expression DO
Structured Text
END_WHILE;
WHILE N7:0/0 AND (N7:1/0 OR !N7:2/0) DO
N7:0 := N7:0 + 1;
END_WHILE;
N7:0 increments by 1
as long as the input conditions
are true
WHILE
code inside the loop
Structured Text Constructs
Chapter 2
2-8
Structured Text User Manual
Important: Do not use I/O addresses in iterative constructs as test values
because they will not be updated by real I/O. The PLC-5 processor is
processing the loop and it cannot continue to the end of the program where
it performs housekeeping and updates remote I/O.
In a running processor, all structured text constructs complete before the
program scan continues. If the WHILE loop takes longer to complete than
the watchdog setpoint, the watchdog timer times out. This is a major fault
that shuts down the processor.
Important: When the processor runs a WHILE loop, all other processing
is put on hold, like checking for a change in the processor keyswitch or a
change in I/O status. The following examples show how to exit a WHILE
loop. You can also use these methods with FOR and REPEAT constructs.
Method: Examples:
IIN instruction WHILE (I:000/000) DO
N7:0 := N7:0 + 1;
IIN (000);
END_WHILE;
EXIT construct WHILE (N7:0/0 = 1) DO
N7:3 := (N7:1 + N7:2);
IF (N7:19/2) THEN
EXIT;
END_IF;
END_WHILE;
Use this construct to repeat a section of code until an input expression
becomes true. After the processor executes the code inside the loop, it
checks the input expression. If the expression is false, the processor
repeats the loop. This process continues until the processor finds the
expression true and exits the loop. An END_REPEAT statement marks the
end of the loop. See the following formats and examples.
Format: Examples:
REPEAT
Structured Text
UNTIL input expression
END_REPEAT;
REPEAT
N7:0 := N7:0 + 1;
UNTIL N7:0 > (N7:10 / 10)
END_REPEAT;
N7:0 increments by 1
until N7:0 is greater than N7:10
divided by 10
Important: Do not use I/O addresses in iterative constructs as test values
because they will not be updated by real I/O. The PLC-5 processor is
processing the loop and it cannot continue to the end of the program where
it performs housekeeping and updates remote I/O.
REPEAT
code inside the loop
Structured Text Constructs
Chapter 2
2-9
Structured Text User Manual
In a running processor, all structured text constructs complete before the
program scan continues. If the REPEAT loop takes longer to complete
than the watchdog setpoint, the watchdog timer times out. This is a major
fault that shuts down the processor.
Important: When the processor runs a REPEAT loop, all other processing
is put on hold, like checking for a change in the processor keyswitch or a
change in I/O status. The following examples show how to exit a REPEAT
loop. You can also use these methods with FOR and WHILE constructs.
Method: Examples:
IIN instruction REPEAT
N7:0 := N7:0 +1;
IIN (000);
IF (I:000/07) THEN
EXIT;
END_IF;
UNTIL (N7:0 > 25)
END_REPEAT;
EXIT construct REPEAT
N7:0 := N7:0 +1;
IF (B3:0/0 = 1 ) THEN
EXIT;
END_IF;
UNTIL (N7:0 > (N7:10 /10)
END_REPEAT;
Use this construct to exit an iterative construct (FOR, WHILE, or
REPEAT) before the processor reaches the normal termination condition.
The processor continues execution of the program at the line following
the end of the current iterative construct. See the following formats
and examples.
Format: Examples:
EXIT; FOR N7:0 := 0 TO 10 DO
WHILE N7:1/0 DO
N7:10:=(N7:10 + 10) / (SIN(F8:0));
IF N7:5 < 4 THEN
EXIT;
END_IF;
END_WHILE;
N7:11 := N7:12 + 1;
END_FOR;
exit the WHILE loop early
execution continues here
EXIT
Structured Text Constructs
Chapter 2
2-10
Structured Text User Manual
This construct performs no function and is provided for IEC standard
1131-3 compatibility. The processor treats it in the same way as
whitespace to make programs more readable. See the following example.
Format: Examples:
;; IF N7:0/0 THEN
;;
ELSE
N7:2 := N7:5 +10;
END_IF;
no effect on program scan
time
Use this construct to call PLC-5 input or output instructions as functions.
Enter the instructions as you would in an exported processor memory file
(ASCII format) with the following exceptions:
enclose the operands within parentheses
separate the operands by commas
omit the SOR and EOR statements
For a complete list of supported instructions, operands, and valid data
types, see appendix B.
You can use any ladder instruction as a ladder function, with the following
exceptions. You cannot use: LBL, JMP, END, MCR, FOR, BRK, NXT,
MSG, SDS, DFA, AND, OR, XOR, and TND. See the following formats
and examples.
Format: Examples:
output instruction (operand a, operand b,...);
input expression output instruction (operand list);
FAL(R6:0,10,0,ALL,#N7:0,#N7:1+#N7:2);
DTR(N7:0, N7:1, N7:2) OTE O:0/3
FAL(R6:0,10,0,ALL,#N7:0,#N7:1+#N7:2);
N7:0 > N7:1 FAL(R6:0,10,0,ALL,#N7:0,#N7:1+#N7:2);
Some input instructions require output instructions for correct syntax (see
the DTR example above). Appendix B identifies which instructions
require output instructions.
In general, enter ladder functions exactly as they are displayed in the
ladder editor. You must specify all fields, even those that are display-only
fields in the ladder editor. Any field that accepts a word (i.e. Yes or
No in a block transfer) must be fully specified (Y or N is invalid.)
;;
Ladder Functions
Structured Text Constructs
Chapter 2
2-11
Structured Text User Manual
The JSR instruction is an exception, and must be entered as follows:
JSR (SBR_file_number, number_of_input_parameters, parameter_list);
For example, enter a JSR to execute subroutine file number 3, with no parameters as:
JSR (3,0);
Enter a JSR to execute subroutine file number 7, with 2 input parameters and 3 return parameters as:
JSR (7,2, N7:0, N7:1, N7:2, N7:3, N7:4);
Although you cannot use certain ladder instructions in a structured text
program (see above), you can, however, access sub-element data associated
with these instructions. For example, you could include the following in a
structured text program:
IF MG10:1.EN THEN
...MG10:1.DLEN := 4;
END_IF;
ATTENTION: Structured text does not prevent you from
assigning invalid values to sub-elements. Doing so could result
in improper machine operation, damage to equipment, and/or
injury to personnel. It is your responsibility to check the
validity of all assignments.
Structured text has equivalents to OTL, OTU, OTE, CPT, FOR, NXT,
BRK, AND, and OR instructions. See the following table for page
references for these functions. Structured text has no direct equivalent to
the JMP instruction. Use the CASE and WHILE constructs instead.
For an Equivalent to
these Constructs:
See Page and Section:
OTE 2-2 (Non-Retentive Bit Assignments)
OTL, OTU 2-3 (Retentive Bit Assignments)
CPT 2-2 (Variable Assignment)
FOR, NXT, BRK 2-6 (FOR)
AND, OR 2-2 (Variable Assignment)
Important: OTL, OTU, OTE, and CPT are valid output instructions in
structured text. However, they will be displayed as their structured text
counterparts after you accept the logic.
Important: In ladder programming, the SBR instruction is an input
instruction. This instruction must be the first instruction in a program file
and must be followed by an output instruction. In structured text
programming, however, no output instruction is required, but the SBR
instruction still must be the first instruction in the program file.
Structured Text Constructs
Chapter 2
2-12
Structured Text User Manual
Important: Be careful when using ladder functions inside of conditional
constructs. Some ladder functions are transitional and do not operate
properly if not scanned with a false rung status. For example, a false IF
skips over the code inside the IF, whereas a false logic rung executes the
output instruction for a false case. (An ASCII Write instruction, AWT,
needs a false scan after the instruction executes to correctly reset.)
Note that if you test control bits of timers, counters, or instructions that use
control file limits, those instructions must be scanned in the loop or they
will not be updated.
Each structured text file uses 7 words for overhead.
The ladder-function constructs take the same amount of memory as their
ladder counterparts. The complex constructs have the following memory
requirements (not including the code section):
Construct: Memory Requirement:
IF input expressions + 9 words
ELSIF input expressions + 9 words
ELSE 2 words
END_IF 2 words
END_FOR 2 words
END_WHILE 2 words
END_REPEAT 2 words
END_CASE 2 words
WHILE input expressions + 16 words
REPEAT input expressions + 15 words
EXIT 1 word
EMPTY 0 words
CASE expressions = 14 words
case item 10 to 12 words
discrete (3 to 6 words) * number of items
range 6 to 12 words
Memory Requirements
Chapter
3
3-1
Structured Text User Manual
Using the Structured Text Editor
This chapter explains how to use the structured text editor. Use the
following table to find specific topics.
For this Topic: See Page:
Creating a structured text file 3-1
Configuring the SFC editor for
structured text
3-2
Entering structured text 3-5
Editing structured text 3-7
Creating documentation reports 3-10
Important: If you create a structured text program file, you can only
monitor or restore that file with programming software that supports
structured text.
To create a structured text file, follow the steps on the left:
+= PROGRAM DIRECTORY FOR PROCESSOR: EXPSFC ======================[ OFFLINE ]===+
| File Name Type Size(words) |
||
| 0 system 10 |
| 1 function chart 69 |
| 2 undefined 6 |
| 3 ladder 7 |
| 4 ladder 7 |
| 5 ladder 7 |
| 6 ladder 7 |
| 7 ladder 7 |
| 8 ladder 7 |
| 9 ladder 7 |
| 10 ladder 7 |
| 11 ladder 7 |
| 12 ladder 7 |
| |
+==============================================================================+
Press a function key.
>
Rem Prog PLC5/40 Series C Revision C 5/40 File EXPSFC
Create Create Create
Lad Fl SFC Fl STxt Fl
F6 F7 F8
F1
Proc Functions
Program
Directory
Press 1
2
3
Enter the number of the file to create.
Press
Esc
to return to
Program
Directory
F8
Create STxt Fl
to create a structured text file.
F6
Create File
Chapter Objectives
Creating a Structured
Text File
Using the Structured Text Editor
Chapter 3
3-2
Structured Text User Manual
After you create the file, you can enter your structured text. Follow the
steps on the left:
Empty Structured Text File