You are on page 1of 75

PLC-5 Structured Text

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

programmable controller documentation is organized into


manuals according to the tasks you perform. This organization lets you easily
find the information you want without reading through information that is not
related to your current task.
Figure 1
Enhanced PLC-5 Programmable Controller Documentation
Programming
6200-6.4.7
Software Configuration
and Maintenance
6200-6.4.6
Configuring processor
Processor/channel status
Defining data table files
Printing reports
Clearing faults
Saving/restoring files
Creating/managing files
Creating/editing SFCs
Importing/exporting
I/O Configuration
6200-6.4.12
Software
Configuring intelligent
I/O modules
6200-6.4.11
Reference
Instruction Set
Instruction execution,
parameters, status
bits and examples
1785 PLC-5
Programmable Controllers
Quick Reference
Quick access to switches,
status bits, indicators,
1785-7.1
6200-6.4.18
Structured Text
User Manual
Program considerations
Mnemonic explanations
Program examples
Using PowerTextt
Instruction parameters
and syntax
Creating/editing/
documenting ladder
logic programs
instructions, software screens
Installing 6200
programming software
1785-6.5.12
Enhanced and Ethernet
PLC-5 Programmable
Controllers User Manual
Enhanced PLC-5
Programmable
Controllers
Ethernet PLC-5
1785-2.38 1785-2.30
Placing system hardware
Addressing I/O and
processor memory
Communicating with
devices on a DH+, serial,
and Ethernet link
Installation Instructions
Programmable
Controllers
Installation Instructions
Handling the Enhanced
Connecting a remote,
extended local, and
DH+ link
PLC-5 processor
Handling the Enhanced
Connecting a remote,
extended local, and
DH+ link
PLC-5 processor
For more information about PLC-5 programmable
controllers or these publications, contact your
local sales office, distributor, or system integrator.
HARDWARE SOFTWARE
You are here
How to Use Your
Documentation
Structured Text User Manual
Preface
ii
Structured Text User Manual
To use 6200 programming software:
If you are a new user of an enhanced PLC-5 processor, use the Enhanced
PLC-5 Programmable Controllers Installation Instructions, publication
1785-2.38, or the Ethernet PLC-5 Programmable Controllers Installation
Instructions, publication 1785-2.30, to make sure your PLC-5 system is
correctly installed. Then see the Enhanced and Ethernet PLC-5
Programmable Controllers User Manual, publication 1785-6.5.12, for
programming guidelines.
After your system is up and running, use the Quick Reference manual,
publication 1785-7.1, for help in maintaining your system.
If you are already familiar with 6200 programming software, you might only
need the Instruction Set Reference manual, publication 6200-6.4.11, or the
Structured Text User Manual, publication 6200-6.4.18.
This manual uses the following conventions to describe how to
enter information:
Unless otherwise stated:
References to: Include these Allen-Bradley Processors:
Classic PLC-5 processors PLC-5/10, -5/12, -5/15, -5/25, and -5/VME processors.
Enhanced PLC-5 processors PLC-5/11, -5/20, -5/30, -5/40, -5/40L, -5/60 , -5/60L,
and -5/80 processors.
Important: Unless otherwise specified, Enhanced PLC-5
processors include Ethernet PLC-5 and VME PLC-5 processors.
Ethernet PLC-5 processors PLC-5/20E, -5/40E, and -5/80E processors.
VME PLC-5 processors PLC-5/V30, -5/V40, -5/V40L, and -5/V80 processors. See the
PLC-5/VME VMEbus Programmable Controllers User Manual,
publication 1785-6.5.9, for more information.
Where to Start
Conventions
Structured Text User Manual
Preface
iii
Structured Text User Manual
Pictures of keys and/or screens represent actual keys that you press or screens
that you see. For example, in the procedure for creating a structured text file,
you see:
+= 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
What the procedure shows is that from the program directory, press [F1] and
then [F6] to display this screen. Then press [F8] to create a structured text
file and enter the file number. Press [Esc] to return to the program directory.
Words in square brackets represent actual keys that you press. For example:
[Enter] or [F1] Online Programming/Documentation
Words that describe information that you have to provide are shown in
italics. For example, if you have to type a file name, this is shown as:
filename
Messages and prompts that the terminal displays are shown as:
Press a function key
Structured Text User Manual
Table of Contents
iv
Structured Text User Manual
Chapter 1
Chapter Objectives 1-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Structured Text 1-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing the Software 1-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Writing Structured Text 1-3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Rules for Writing Structured Text 1-6 . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 2
Chapter Objectives 2-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Variable Assignment (:=) 2-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Non-Retentive Bit Assignments (:=) 2-2 . . . . . . . . . . . . . . . . . . . . . . . . .
Retentive Bit Assignments (RETAIN) 2-3 . . . . . . . . . . . . . . . . . . . . . . .
IF-ELSIF-ELSE 2-4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CASE 2-5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FOR 2-6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
WHILE 2-7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REPEAT 2-8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
EXIT 2-9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;; 2-10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ladder Functions 2-10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Memory Requirements 2-12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 3
Chapter Objectives 3-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Structured Text File 3-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Configuring the Structured Text Editor 3-2 . . . . . . . . . . . . . . . . . . . . . . .
Defining Addresses and Symbols 3-3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
Entering Structured Text 3-5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Editing Structured Text 3-7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Documentation Reports 3-10 . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 4
Chapter Objectives 4-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using PowerText 4-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Configurable Data Monitor 4-4 . . . . . . . . . . . . . . . . . . . . . . .
Writing Structured Text
Structured Text Constructs
Using the Structured
Text Editor
Monitoring Structured Text
Structured Text User Manual
Table of Contents
v
Structured Text User Manual
Appendix A
Appendix Objectives A-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Programming a Free Running Timer A-1 . . . . . . . . . . . . . . . . . . . . . . . . .
Programming a Sort Routine A-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging Programs A-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix B
Instruction Operands and Valid Data Types B-1 . . . . . . . . . . . . . . . . . . .
Appendix C
ASCII Structured Text Processor Memory File Example C-1 . . . . . . . . .
Structured Text Syntax for Above ASCII File C-9 . . . . . . . . . . . . . . . . .
Application Example
Instruction Reference
ASCII Structured Text
Programming Example
Important: Remove any previous versions of the
software before installing the new version. For
information about removing the software, see
the PLC-5 Configuration and Maintenance
manual, publication 6200-6.4.6.
a: is the drive where you insert the disk.
c: is any destination hard-disk for the
programming software.
Chapter
1
1-1
Structured Text User Manual
Writing Structured Text
Use this chapter to learn what structured text is and how you can use it as
an alternative to or in conjunction with ladder logic or Sequential Function
Charts (SFCs).
Structured text is an English-like set of instructions and mnemonics that
you can use to perform most of the same tasks that you already perform
with ladder logic. The structured text language resembles BASIC and is
based on the International Electrotechnical Commission (IEC) 1131-3
standard for programmable controller software.
Structured text supports complex expressions and both logical and
symbolic addressing. Use structured text or ladder logic to program
MCPs, subroutines, or actions and/or transitions in SFCs, depending on
which type of programming best suits your application and how much
memory you have available.
Structured text is only supported on enhanced 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

Press a function key, or use cursor keys to scroll structured text.


MONITOR 11 >
Rem Prog Forces: None Edits: None 5/40 File RUNBATCH
Change Exit Edit Data Edit
Mode DBASE Monitor
F1 F3 F5 F8 F10
cursor to
structured text file
Program
Directory
F8
Monitor File
You can configure the structured text editor to display addresses or
symbols. For structured text in MCPs and/or subroutines, this is the only
display characteristic that you can configure. If you are using structured
text in an SFC, you can also adjust the action and/or condition field size
and configure the editor to show either the first line of the structured text
file or the structured text file number in the Action Condition window. To
configure the structured text editor, follow the steps on the left:
SFC
Main Menu
F7
General
Utility
F2
Configure
Display
F8
Act/Cnd
Window
+= Action/Condition Window Configuration ======================================+
| 10 50 |
| Action/Condition Comment |
| .......... .................................................. |
| |
| F3 Address Display: Suppress Symbol F4 Act/Cnd Dsp: Show Structured Text |
+==============================================================================+

START
+++
+++
END







Press a function key or user left/right arrow keys to configure window.
MONITOR 1:(0,0) >
Rem Prog SFCFrc:Disabled PLC5/40 Ser C Rev C 5/40 File LIMIT
Act/Cnd Comment Address Act/Cnd
Field Field Display Display
F1 F2 F3 F4
Configuring the Structured
Text Editor
Using the Structured Text Editor
Chapter 3
3-3
Structured Text User Manual
To: Press this Key:
Specify the action/condition field size for the
action/condition window (0-60 characters) by
entering it on the command line or using the
left/right arrow keys
[F1] - Act/Cond Fld
Adjusting the Action/Condition field automatically
adjusts the Comment field size.
Specify the comment field size for the
action/condition window (0-60 characters) by
entering it on the command line or using the
left/right arrow keys
[F2] - Comment Field
Adjusting the Comment field automatically adjusts
the Action/Condition field size.
Display address symbols [F3] - Address Display: Display/Suppress Symbol
s ke les e ee s la s ess
Suppress address symbols
This key toggles between displaying or suppressing
address symbols. The default is to display symbols.
Display the first line of structured text [F4] - Act/Cnd Display
This key toggles between displaying the first line of
Display the structured text file number
This key toggles between displaying the first line of
structured text and displaying the structured text file
number in the Action/Condition window.
Return to the Display Configuration window. [Esc]
Any addresses and symbols that you want to use in your structured text
files must be assigned before you edit the file. You cannot save a
structured text file that references any addresses or symbols that do not
exist in the database.
You can access the documentation database and the data table monitor
through the structured text editor. You must still define the symbols you
need prior to editing a structured text file. To access the documentation
database or the data table monitor, follow these steps:
Defining Addresses
and Symbols
Using the Structured Text Editor
Chapter 3
3-4
Structured Text User Manual
6200
Main Menu
F8
Cursor to a
structured text file or
enter file number
Monitor File
F5
Edit
DBASE
Program
Directory
F1
Online Prog
F3
Offline Prog
or
6200
Main Menu
F8
Cursor to a
structured text file or
enter file number
Monitor File
Program
Directory
F1
Online Prog
F3
Offline Prog
or
To access the documentation database: To access the data table monitor:
F8
Data
Monitor
For more information about using the documentation database, see the
PLC-5 Programming Manual, publication 6200-6.4.7. For more
information about using the data monitor, see the PLC-5 Configuration and
Maintenance Manual, publication 6200-6.4.6.
Using the Structured Text Editor
Chapter 3
3-5
Structured Text User Manual
You can enter structured text as an MCP, subroutine, fault routine, STI
routine, or as an action or transition in an SFC file. To enter structured text
as an MCP, subroutine, fault routine, or STI routine follow the steps on
the left:
Entering Structured Text
IF (!T4:0.DN) THEN
TON (T4:0, 0.01, 100, 0);
ELSIF (T4:0.DN) THEN
RES (T4:0);
END_IF;
WHILE (TIMER1) DO
FOR (N7:10 := 0 TO 10) DO
CASE (N7:20) OF
0:
N7:100 := TIMER8;
1:
N7:101 := TIMER9;
END_CASE;
END_FOR;
END_WHILE;

Press a function key or enter the structured text.


MONITOR 8 >
Rem Prog Mode:Insert WrapOff Left Col:1 Line:1 5/40 File LIMIT
Delete Undel Delete Undel Delete Undel Advancd Accept
ST File ST File Line Line Word Word Editing ST Edit
F1 F2 F3 F4 F5 F6 F7 F8
6200
Main Menu
F8
Cursor to a
structured text file or
enter file number
Monitor File
If you havent entered logic (structured text) into the program file yet,
this window is blank.
F10
Edit
Program
Directory
F1
Online Prog
F3
Offline Prog
or
Using the Structured Text Editor
Chapter 3
3-6
Structured Text User Manual
To enter structured text as a step action or transition condition in an SFC,
follow the steps on the left:
Rem Prog SFCFrc:Disabled PLC-5/40 Ser C Rev C 5/40 Addr 43 DRILL1
Select Edit Copy Remove
File Text Cond Cond
F1 F2 F3 F6
Rem Prog SFCFrc:Disabled PLC-5/40 Ser C Rev C 5/40 Addr 43 DRILL1
Select Edit Append Insert Remove
File Text Action Action Action
F1 F2 F3 F4 F6
Step Trans Step Step Trans
Actions * Timer Name Name
F1 F2 F4 F8 F9
START
+++
+=====+=====+
# MIXER #
+=====+=====+
+
|
|
+++

Press a function key.
EDIT 2:(0,0) >
Rem Prog SFCFrc:Disabled PLC5/40 Ser C Rev C 5/40 Addr 43 DRILL1
+= Action Display for Step: MIXER==============================================+
| ActionName QL Action Comment |
++
| ValveChk N 2 (ladder) |
| |
| |
| |
+==============================================================================+

SFC
Edit Selections
F10
Edit
SFC
Main Menu
F3
Append
Step/Trn
or
F4
Insert
Step/Trn
Choose or create a structured text file, then cursor to
the Condition Text field and then press
Press the appropriate function key to choose
to create an action or a transition. See below.
Choose or create a structured text file, then cursor to
the Action Text field and then press
If you press F1
Step Actions
a
b
If you press F2
Trans
F2
Edit Text
F2
Edit Text
Using the Structured Text Editor
Chapter 3
3-7
Structured Text User Manual
The editing keys for a structured text file used within an SFC (as an action
or transition) and a structured text file used as an MCP or subroutine are
identical, but the ways to get to the editor are different. To edit structured
text, either in an SFC or as an MCP or subroutine, follow the steps on
the left:
Important: You must be offline or in Program or Remote Program mode
to edit structured text. If you change the processor mode from Program or
Remote Program, all of your edits are lost. The system displays an error
message Processor has changed to Run or Test mode, edit
aborted. The system returns to the SFC main menu (if you are using an
SFC) or the Structured Text View screen (if you are entering structured text
as an MCP or subroutine).
IF (LIMIT_SW1 AND BOXPRESENT) THEN
GATE1 := OPEN;
GATE2 := CLOSE;
ELSIF ((LIMIT_SW2 OR (WEIGHT <> SETPOINT))) THEN
GATE1 := CLOSE;
GATE2 := CLOSE;
ELSIF (LIMIT_SW3 XOR LIMIT_SW4) THEN
GATE1 := CLOSE;
GATE2 := CLOSE;
ELSE
GATE1 := OPEN;
GATE2 := CLOSE;
END_IF;


Press a function key or enter the structured text.


MONITOR 2 >
Rem Prog Mode:Insert WrapOn Left Col:1 Line:1 5/40 File ST
Delete Undel Delete Undel Delete Undel Advancd Accept
ST File ST File Line Line Word Word Editing ST Edit
F1 F2 F3 F4 F5 F6 F7 F8
Use these editing keys to edit the structured text. For more
information on how the editor works, see chapter 17 in the
PLC-5 Programming manual, 6200-6.4.7.
SFC
Edit Selections
F10
Edit
SFC
Main Menu
F5
F1
Step Actions
F2
Edit Text
Ladder Editor
Main Menu
F8
Cursor to a
structured text file or
enter file number
Monitor File
F10
Edit
Within an SFC
or F2
Trans
Modify Stp/Trn
Cursor to the Action or
Condition Text field
SFC
Main Menu
F1
Online Prog
F3
Offline Prog
or
MCP or Subroutine
F4
Prog Dir
Editing Structured Text
Using the Structured Text Editor
Chapter 3
3-8
Structured Text User Manual
When you load a structured text program into a processor, the processor
converts the program to IEC standard 1131-3 format. Therefore, if you
monitor or save a program, it is converted to standard format, regardless of
the format in which you wrote it. (For example, if you used semicolons in
place of colons in your program, the semicolons are replaced by colons
when you load the program into the processor.) If you want to keep the
program as you originally entered it, save the original program as a paste
file using the Advanced Editing cut, copy, and paste features.
Accepting Edits
When you finishing entering or editing structured text, press F8 Accept
Edits to accept the edits. The software checks the edits to make sure the
syntax is correct before saving the file. If there is an error in the structured
text, the software displays an error message explaining the error. You must
correct the error before you can accept edits again.
If there are syntax errors and you want to temporarily save the incorrect
structured text file, use the advanced editing functions to copy the file to a
disk file. You can then later paste the file into an empty structured text file
and correct the syntax errors. Follow the steps below.
Move the cursor to the
beginning of the area
you want to save.
ST Editor
F7
Advanced Editing
F1
Select
Move the cursor to the
end of the area you
want to save.
To select the structured
text to save to disk file:
ST Editor
F2
Cut
F7
Copy to Disk
To copy the selected structured
text to disk file:
with selected text
highlighted
TIP
Using the Structured Text Editor
Chapter 3
3-9
Structured Text User Manual
Important: If you are editing online in Program or Remote Program
mode, do not type ahead after pressing F8 Accept Edits. Wait until the
software completes accepting the edits. The software takes awhile to
accept your edits because it checks all the syntax. If you type ahead, such
as the key sequence for changing to Run mode, the software uses these
keystrokes and deletes the current structured text file after accepting
the edits.
If you do type ahead and the software deletes your structured text file, you
can undelete the file. Do not return to the program directory. Instead,
return to the structured text editor and press F2 Undelete ST File.
Editing Structured Text In Windows
When using multiple sessions, if you edit a structured text file while
displaying the same file in another session, the edit does not appear in the
second session.
Editing Structured Text as an ASCII File
You can create a structured text paste file with most word processors. Save
the file as ASCII or text only in the \IPDS\ARCH\PLC5 directory, with a
.STX extension. You can then paste the file using the advanced editing
paste from disk function.
You can also create an entire processor memory file as an ASCII file and
import that file into 6200. Appendix C shows an example of a processor
memory file complete with data table values.
Using the Structured Text Editor
Chapter 3
3-10
Structured Text User Manual
PLC-5 programming software generates and prints reports about
your programs. One of these reports is the Structured Text Listing.
The Structured Text Listing lets you see a printed copy of your structured
text program. To generate a Structured Text Listing, follow the steps on
the left:
F3
F8
Reports
6200
Main Menu
select Structured Text
Listing as the report to
generate by cursoring to it and
pressing
F3
Create Offline
Select the range of files
to include in the report.
or F1
Create Online
current
processor
memory
file
Toggle Report
F5
Report Options
F1
Create Reports
+========================= PLC5 PROGRAMMING SOFTWARE =========================+
| += Offline ======= LIMIT=====+
| A 6200 Series Software Pr| SFC Listing |
| | SFC Cross Reference |
| Copyright 1986, 1995, AllenBradle *| Structured Text Listing |
| All Rights Reserved | Ladder Program Listing |
| | Program Cross Reference |
| Release 5.0 | Program Directory |
| += Structured Text Listing =========+ | Memory Map |
| This so| | | Processor Status |
| | Starting File 1 | | I/O Status |
| | Ending File 999 | | Data Tables |
| | | | Force Status |
| | Address Display SYMBOL | | Symbol Table |
| | | | Unused Addresses |
| | | | Memory Usage |
| | | | Privilege Classes |
+===========+===================================+=+============================+

Press a function key.


Create Select Toggle Reset Report General Define Title Save
Reports All Report Reports Options Options Dir Config
F1 F2 F3 F4 F5 F6 F7 F8 F9
Creating Documentation
Reports
Using the Structured Text Editor
Chapter 3
3-11
Structured Text User Manual
The status screen (shown below) advises you of the progress of
the report.
+========================================+
| ALLENBRADLEY COMPANY |
| 6200 SERIES SOFTWARE |
| PLC5 DOCUMENTATION SOFTWARE |
+========================================+
Proc File: LIMIT Report: Structured Text Listing
Output: LIMIT.TXR Config: Files 1 999
Phase: GENERATE ST. TXT. LISTING Status: File: 2

+==============================================================================+
|** OPEN PROCESSOR MEMORY FILE ** |
|** GENERATE STRUCTURED TEXT LISTING REPORT ** |
|** GENERATE LISTING FOR FILE 2 ** |
| |
| |
| |
| |
| |
| |
+==============================================================================+

Press F3 to abort
Abort
Utility
F3
You can abort this utility with
F3
Abort Utility
For more information about reports, including how to print a report, see the
PLC-5 Configuration and Maintenance Manual, publication 6200-6.4.6.
Tue Jan 3, 1995 Page 1
Structured Text Listing Report PLC5/40 Addr 68 File 2
R6:6.DN AND ONS (B3/4) MOV (ST15:3.LEN, N17:85);
A structured text listing looks similar to the above screen. The structured text
listing file has a .TXR extension and resides in the IPDS\TEXT\PLC5 directory.
F8
Reports
6200
Main Menu
To View the Report:
F8
Print/View
F3
Select
F10
View File
IF (!T4:0.DN) THEN
TON (T4:0, 0.01, 100, 0);
ELSEIF (T4:0.DN) THEN
RES (T4:0);
END_IF;
WHILE (TIMER1) DO
FOR (N7:10 := 0 TO 10) DO
CASE (N7:20) OF
0:
N7:100 := TIMER8;
1:
N7:101 := TIMER9;
END_CASE;
END_FOR;
END_WHILE;
Cursor to the processor
name you want
Chapter
4
4-1
Structured Text User Manual
Monitoring Structured Text
Use this chapter to learn how to use the Structured Text View window and
the PowerText

feature as monitoring tools for structured text.


The PowerText feature is an online enhancement to structured text that
integrates actual real-time data table values with the structured text source
program. While the processor is in Run mode, the view window displays
variable values in { } braces and intensifies bit operands when true. It also
displays I/O forcing information, indicating the force value (ON or OFF)
and whether forces are enabled or disabled by changing color. The
PowerText feature is especially useful for maintenance purposes.
Important: The PowerText features intensification does not take the
context of an address into account. If you use a NOT operator (!) before
an address in a structured text file, the address is intensified by the
PowerText feature when the address is true and is not intensified when the
address is false.
To get to the monitor/view screen to monitor program files and to display
PowerText information, follow the steps on the next page.
Empty Structured Text File

Press a function key, or use cursor keys to scroll structured text.


MONITOR 11 >
Rem Prog Forces: None Edits: None 5/40 File RUNBATCH
Change Exit Edit Data Edit
Mode DBASE Monitor
F1 F3 F5 F8 F10
cursor to
structured text file
Program
Directory
F8
Monitor File
When monitoring a structured text file, press F7 Alt to toggle between
displaying or suppressing documentation.
Chapter Objectives
Using PowerText
TIP
Monitoring Structured Text
Chapter 4
4-2
Structured Text User Manual
If the processor is not in Run mode, the view window displays the
structured text that you entered.


Press a function key, or use cursor keys to scroll structured text.
MONITOR 11 >
Rem Run Forces: Enabled Edits: None 5/40 Addr 16 ST
Change Exit Edit Data
Mode DBASE Monitor
F1 F3 F5 F8
IF (LIMIT_SW1 {F ON} AND BOXPRESENT) THEN
GATE1 := OPEN;
GATE2 := CLOSE;
ELSIF ((LIMIT_SW2 OR (WEIGHT { 287} <> SETPOINT { 289}))) THEN
GATE1 := CLOSE;
GATE2 := CLOSE;
ELSIF (LIMIT_SW3 XOR LIMIT_SW4) THEN
GATE1 := CLOSE;
GATE2 := CLOSE;
ELSE
GATE1 := OPEN;
GATE2 := CLOSE;
END_IF;
Program
Directory
F8
Cursor to a
structured text file or
enter file number
Monitor File
If you havent entered logic (structured text) into the program file yet,
this window says only: Empty Structured Text File
6200
Main Menu
F1
Online Prog
F3
Offline Prog
or
If you have not created a structured text file,
you need to do so. See page 3-1.
SFC
Main Menu
MCP or Subroutine Within an SFC:
If you have not configured the Action Window to
appear on the screen, press
Cursor to the structured text
field and press
Enter
Alt A
Alt A (a cursor appears in the action window)
PowerText values
Monitoring Structured Text
Chapter 4
4-3
Structured Text User Manual
Configuring Display Colors
You can change the colors that the PowerText feature uses to display
information. To do this, follow the steps on the left:
+========================= PLC-5 PROGRAMMING SOFTWARE =======================+
| |
| A 6200 Series Software Product |
| += COLOR SELECTION MONOCHROME =========================================+ |
| | + Main Displays + Informational Messages | |
| | | True Logic | Errors | |
| | | Forces | User Prompts | |
| | | Rung/Step Comments | User Input | |
| | | Address Comments | Processor Status | |
| | | Instruction Comments | Program Modes | |
| | | Symbols | Test Modes | |
| | | Instruction Cursor | Run Modes | |
| | ++ Faults | |
| | Logo/Processor Directory Function Keys | |
| | Processor Dir. Cursor Data Entry Windows | |
| | Selection Windows Option Windows | |
| | Selection Cursor Who | |
+==+= ESC exits/ALTU aborts changes =======================================+==+

Press a function key


Mono/ Recall Bakgrnd Forgrnd Save
DfltClr LastClr Color Color Config
F1 F2 F5 F6 F9
F6
6200
Main Menu
Software
Config
F3
Color
Selection
If you want to change the color mode, press this key
If you just installed your
programming software, the default
color selection is monochrome.
If you have a monochrome
monitor, use the default selection.
If you use color choices on a
monochrome monitor, some
items may be difficult or
impossible (invisible) to read. For
example, if your monitor is
monochrome, and you set the
background color for the
instruction cursor the same as that
for main displays, the cursor
is invisible.
This Selection: Applies to: Displays in:
True Logic display of bit values and
other values
the foreground color you configure for True Logic
and the background color you configure for
Option Windows
False Logic the foreground and background color you
configure for Option Windows
Forces whether forces are enabled when enabled, the foreground color you configure
for Forces and the background color you configure
for Option Windows
when disabled, the foreground and background
color you configure for Option Windows
Option Windows the structured text view window the foreground and background color you
configure for Option Windows
Data Entry Windows the structured text edit window the foreground and background color you
configure for Option Windows
Monitoring Structured Text
Chapter 4
4-4
Structured Text User Manual
If You Want to: Press this Key:
Toggle between a black and white display or a display that uses the
default colors.
[F1] Monochrome/Default Color
Restore the last color selections that were saved before the current
programming session. This restores color for all display options.
Configurations saved during the current session are not recalled.
[F2] Recall Last Color
Toggle through the eight available color choices for backgrounds. [F5] Background Color
Toggle through the 16 available color choices for foregrounds. [F6] Foreground Color
Save the color options to disk. [F9] Save Configuration
Use the color selections you specify for this editing session only. [Enter]
[Esc]
Cancel any changes you made on this screen for the current editing session. [Alt-U]
With the PowerText feature, you can create custom data table monitoring
screens using structured text assignments. This is a convenient way to
monitor non-adjacent data table values.
The processor updates PowertText values on the screen when the processor
is in Run mode. To see these values, create a structured text file that is not
executing as an MCP, subroutine, or an action or transition within an SFC
file. Because the structured text file is not executing, the logic in the file is
not executed. Data table values for these variables, however, are
accurately updated.
To create a monitoring screen, follow these steps:
1. Create a new structured text file.
Important: Be sure that this file is not executed as an MCP, subroutine, or
as an SFC action or transition.
2. Edit the file, and create variable and/or bit assignments.
For example:
IF (0 = 1) THEN
FLOW_RATE1 := FLOW_RATE2;
N10:0 := N10:1;
B3:0 := B19:7;
D9:0 := D20:1;
N10:10 := F8:10;
END_IF;
If you want, you can perform math or logic expressions to increase
the number of values that can display on one screen. For example:
N10:0 := N10:1 + N31:231 + N26:34;
B3/3 := (B3/4 OR (((B3/5 OR B3/6) OR B3/7) OR B3/8));
Creating a Configurable
Data Monitor
Monitoring Structured Text
Chapter 4
4-5
Structured Text User Manual
3. Accept the edits and change the processor mode to Run. The
PowerText values update. For example:
IF (0 = 1) THEN
FLOW_RATE1{ 326.07} := FLOW_RATE2{ 119.923};
N10:0{ 4095} := N10:1{ 4095};
B3:0{0000 0000 0000 0001} := B19:7{0000 0000 0000 0000};
D9:0{FFFF} := D20:1{FC3A};
N10:0{ 4095} := N10:1{ 4095} + N31:231 { 1413} + N26:34{ 57};
B3/3 := (B3/4 OR (((B3/5 OR B3/6) OR B3/7) OR B3/8));
N10:10 { 2000} := F8:10 { 2000.00};
END_IF;
Important: Do not use parentheses around the variables when creating a
data monitor screen or a syntax error results. For example, do not type
(B3:0 := B3:1); Using parentheses in a situation like this results in a
syntax error.
In Run mode, structured texts PowerText feature displays instructions
sub-elements data differently than ladder does. In structured text,
sub-elements are always displayed as integers even if ladder displays the
sub-element as ASCII.
Field Widths
The width of each data type field displayed by the PowerText feature
varies. For the width of a particular data type field, see the following table.
Data Type: Field Width:
integer 6
decimal 4
float 14
ASCII 6
Binary (word) 19
Appendix
A
A-1
Structured Text User Manual
Application Examples
This appendix provides programing examples and tips on debugging structured
text programs.
ATTENTION: These examples are meant to help you create your
own structured text programs. They may need modification to work
correctly on your processor system.
You can program the logic in this example in several ways using structured text.
Method A uses 3 words of memory, the same as the ladder example. Method B
uses 24 words, and method C uses 34 words.
Example: Free Running Timer
EN
TON
TIMER ON DELAY
Timer
Time base
Preset
Accum
T4:0
0.01
100
0
DN
T4:0
DN
LADDER:
STRUCTURED TEXT:
METHOD A:
!T4:0.DN TON (T4:0, 0.01, 100, 0);
METHOD B:
IF (!T4:0.DN) THEN
TON (T4:0, 0.01, 100, 0);
ELSE
RES (T4:0);
END_IF;
METHOD C:
IF (!T4:0.DN) THEN
TON (T4:0, 0.01, 100, 0);
ELSIF (T4:0.DN) THEN
RES (T4:0);
END_IF;
All of the programming examples execute the timer until the preset equals the
accumulated value. The timer is then reset and begins timing again.
Appendix Objectives
Programming a Free
Running Timer
Application Examples
Appendix A
A-2
Structured Text User Manual
The following program sorts numbers in ascending order.
MAX_INDEX := MIN_INDEX + MAX_LOTS;
UNSORTED := 0;
START_I := MIN_INDEX + 1;
FOR (UNSORTED := START_I TO MAX_INDEX) DO
NEW_LOT := N7:[N7:301];
LOCATION := UNSORTED;
PREVIOUS_LOCATION := LOCATION 1;
WHILE (LOCATION > MIN_INDEX) AND (N7:[N7:[N7:309] > NEW_LOT) DO
N7:[N7:303] := N7:[N7:309];
LOCATION := LOCATION 1;
PREVIOUS_LOCATION := LOCATION 1;
END_WHILE;
N7:[N7:303] := NEW_LOT;
END_FOR;
To help locate and trace the execution of a structured text program, set a
variable at the beginning of each program file and store the file number. Then
in various locations throughout the structured text program, update a state
variable. For example:
FILE := 3;
STATE := 0;
structured text code
.
.
.
STATE := 1;
structured text code
.
.
.
STATE := 2;
structured text code
.
.
.
STATE := 3;
Use PowerText to monitor the structured text file to determine where the
processor is executing. You can also use your operator interface to monitor the
FILE and STATE values to determine where the processor is executing.
Programming a Sort Routine
Debugging Programs
Appendix
B
B-1
Structured Text User Manual
Ladder Functions Reference
This appendix lists the available ladder instructions for structured text and their
operands and the data types/values that are valid for each operand.
The following table explains each valid data type/value:
This Data Type/Value: Accepts:
immediate
(program constant)
any value between -32768 and 32767
integer any integer data type: integer, timer, counter, status, bit, input, output,
ASCII, BCD, control (e.g. N7:0, C4:0, etc.)
float any floating point data type (valid range is + 1.1754944e
-38
to
+3.4028237e
+38
). Note that the 1784-T50 may round or truncate the
number based on the number of significant digits and the size of the
floating point number.
block transfer any block transfer data type (e.g. BT14:0) or integer data type (e.g. N7:0)
PID any PID data type (e.g. PD16:0) or integer data type (e.g. N7:0)
string any string data type (e.g. ST12:0)
SFC status any SFC status data type (e.g. SC17:0)
Table B.A shows the PLC-5 instructions you can program in structured text, the
syntax, and the operands for those instructions. Some ladder functions are
transitional and do not operate properly if not scanned with a false rung status.
Table B.A also lists whether a false-to-true transition is required for execution.
Structured text is only supported on enhanced PLC-5

series C, revision C and


later processors.
Important: This appendix lists the instructions you can use in structured text
programs. There are additional instructions that you can use in ladder logic
programs. For a complete list of instructions, see the PLC-5 Instruction Set
Reference, publication 6200-6.4.11.
Appendix Objectives
Instruction Operands and
Valid Data Types
Ladder Functions Reference
Appendix B
B-2
Structured Text User Manual
Table B.A
Programming Instructions and Operands
Instruction Description
structured-text syntax
Operand Valid Value Require
False-to-True
Transition
ABL ASCII Test Buffer for Line channel immediate, 04 integer yes
ABL (channel, control, characters) control control address
characters integer
(this is a display only field in
ladder logic)
ACB ASCII Number of Characters in Buffer channel immediate, integer yes
ACB (channel, control, characters) control control address
characters integer
(this is a display only field in
ladder logic)
yes
ACI ASCII String to Integer source string no
ACI (source, destination) destination integer
ACN ASCII String Concatenate source A string no
ACN (source_A, source_B, destination) source B string
ACS Arc Cosine
ACS (source, destination)
source immediate, float (in radians),
integer
no
destination float (in radians), integer
ADD ADD source A immediate, integer, float no
ADD (source_A, source_B, destination) source B immediate, integer, float
destination integer, float
AEX String Extract source string no
AEX (source, index, number,
d ti ti )
index immediate, 0-82 integer
destination)
number immediate, 0-82 integer
destination string
AFI Always False
AFI
no
AHL ASCII Set/Reset Handshake Lines channel immediate, 0-4 integer yes
handshake AND mask immediate, Hex integer
handshake OR mask immediate, Hex integer
control control
AIC ASCII Integer to String source immediate, integer no
AIC (source, destination) destination string
Ladder Functions Reference
Appendix B
B-3
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
ARD ASCII Read Characters channel immediate, 0-4 integer yes
ARD (channel, destination, control,
t i l th h t d)
destination string
string_length, characters_read)
control control address
string length 0 82
characters read integer
(this is a display only field in
ladder logic)
ARL ASCII Read Line channel immediate, 0-4 integer yes
ARL (channel, destination, control,
t i l th h t d)
destination string
string_length, characters_read)
control control address
string length 0 82
characters read integer
(this is a display only field in
ladder logic)
ASC ASCII String Search source string no
ASC (source, index, search, result) index immediate, 0-4 integer
search string
result integer
ASN Arc Sine source immediate, float (in radians) no
ASN (source, destination)
destination float (in radians)
ASR ASCII String Compare source A string no
ASR (source_A, source_B) source B string
ATN Arc Tangent source immediate, float (in radians) no
ATN (source, destination)
destination float (in radians)
AVE Average File
(fil d i i l
file integer, float yes
AVE (file, destination, control,
length, position)
destination integer, float
control control address
length 1 1000
position 0 999
AWA ASCII Write with Append channel immediate, 0-4 integer yes
AWA (channel, source, control,
t i l th h t t)
source string
string_length, characters_sent)
control control address
string length 0 82
characters sent integer
(this is a display only field in
ladder logic)
Ladder Functions Reference
Appendix B
B-4
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
AWT ASCII Write channel immediate, integer yes
AWT (channel, source, control,
t i l th h t t)
source string
string_length, characters_sent)
control control address
length 0 82
characters sent integer
(this is a display only field in
ladder logic)
BSL Bit Shift Left file binary yes
BSL (file, control, bit_address,
length)
control control address
length)
bit address bit
length 1 16000 (length in bits)
BSR Bit Shift Right file binary yes
BSR (file, control, bit_address,
length)
control control address
length)
bit address bit
length 1 16000 (length in bits)
BTD Bit Distribute source immediate, integer no
BTD (source, source_bit, destination,
destination bit, length)
source bit immediate, (0 15) integer
destination_bit, length)
destination integer
destination bit immediate (0 15)
length immediate (1 16)
Ladder Functions Reference
Appendix B
B-5
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
BTRx Block Transfer Read rack 00-277 octal yes
BTR (rack, group, module,
control block data file BT length
group 0-7
control_block, data_file, BT_length,
continuous, BT_timeout)
module 0-1
, _ )
control block BT address
integer address
data file integer
length 0, 1-64
continuous YES, NO
BTWx Block Transfer Write rack 00-277 octal yes
BTW (rack, group, module,
control block data file BT length
group 0-7
control_block, data_file, BT_length,
continuous, BT_timeout)
module 0-1
, _ )
control block BT address
integer address
data file integer
length 0, 1-64
continuous YES, NO
CLR Clear
CLR destination
destination integer, float no
CMP Compare
CMP (expression) output instruction
expression, relative
expression, expression
expression using values or
addresses with evaluators
no
CMP (expression) output instruction
this instruction must be followed by an output instruction
to compile correctly
COP File Copy source array no
COP (source, destination, length)
destination array
length immediate (1 1000)
COS Cosine source immediate, float (in radians) no
COS (source, destination)
destination float (in radians)
CPT Compute destination integer, float no
CPT (destination, expression)
math expression expression using values or
immediate integer, float
addresses with evaluators
CTD Count Down counter counter yes
CTD (counter, preset, accumulated)
PRE 32768 +32767
ACC 32768 +32767
x In non-continuous mode, BTR and BTW ladder functions requires a false-to-true transition to execute. In continuous mode, once the rung goes true, BTR and BTW functions continue to
execute regardless of rung condition.
Ladder Functions Reference
Appendix B
B-6
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
CTU Count Up counter counter yes
CTU (counter, preset, accumulated)
PRE 32768 +32767
ACC 32768 +32767
DDT Diagnostic Detect source array binary yes
DDT (source, reference, result,
compare control length position
reference array binary
compare_control, length, position,
result_control, length, position)
result array integer
_ , g , p )
compare control control address
length 1 16000 (length in bits)
position 0 15999
result control control address
length 1 1000
position 0 999
DEG Degree (convert radians to degrees) source immediate, float (in radians) no
DEG (source, destination)
destination immediate, float (in degrees)
DIV Divide source A immediate, integer, float no
DIV (source_A, source_B, destination)
source B immediate, integer, float
destination integer, float
DTR Data Transitional
DTR (source mask reference) output
source immediate, integer no
DTR (source, mask, reference) output
instruction
s s s e ll e a s
mask immediate, integer
this instruction must be followed by an output instruction
to compile correctly
reference integer
EOT End of Transition
EOT
no
EQU Equal
EQU (source_A, source_B) output
instruction
source A immediate, integer, float no
instruction
this instruction must be followed by an output instruction
to compile correctly
source B immediate, integer, float
FAL File Arithmetic/Logical control control address yes
FAL (control, length, position, mode,
destination expression)
length 1 1000
destination, expression)
position 0 999
mode (INC, 11000, ALL)
destination integer, float
expression indexed math instruction
Ladder Functions Reference
Appendix B
B-7
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
FBC File Bit Compare source array binary yes
FBC (source, reference, result,
compare control length position
reference array binary

compare_control, length, position,
result_control, length, position)
result array integer
_ , g , p )
compare control control address
length 1 16000 (length in bits)
position 0 15999
result control control address
length 1 1000
position 0 999
FFL FIFO Load source immediate, indexed, integer yes
FFL (source, FIFO, control, length,
position)
FIFO array indexed, integer
position)
control control address
length 1 1000
position 0 999
FFU FIFO Unload FIFO array indexed, integer yes
FFU (FIFO, destination, control,
length position)
destination indexed, integer
length, position)
control control address
length 1 1000
position 0 999
FLL Fill File source immediate, integer, float no
FLL (source, destination, length)
destination array array
length immediate (1 1000)
FRD From BCD source immediate, integer no
FRD (source, destination)
destination integer
FSC File Search and Compare control control structure address yes
FSC (control, length, position, mode,
expression) output instruction
length 1 1000
expression) output instruction
s s s e ll e a s
position 0 999
this instruction must be followed by an output instruction
to compile correctly mode immediate, integer (0, INC,
11000, ALL)
expression indexed math instruction
GEQ Greater Than or Equal To
GEQ (source_a, source_B) output
instruction
source A immediate, integer, float no
instruction
this instruction must be followed by an output instruction
to compile correctly
source B immediate, integer, float
Ladder Functions Reference
Appendix B
B-8
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
GRT Greater Than
GRT (source_a, source_B) output
instruction
source A immediate, integer, float no
instruction
this instruction must be followed by an output instruction
to compile correctly
source B immediate, integer, float
IIN Immediate Input
IIN input_word
I (input word) immediate, integer
PLC-5/10, 11, 12 15, 20, 25,
30: 000-077
PLC-5/40, 40L: 000-157
PLC-5/60, 60L, 80, :000-237
no
IOT Immediate Output
IOT output_word
O (output word) immediate, integer
PLC-5/40, 40L: 000-157
PLC-5/60, 60L, 80: 000-237
no
JSR Jump to Subroutine ladder file number immediate (2 999), integer no
JSR (file_number,
number_of_input_parameters,
input parameter list
number of input
parameters
immediate, integer
input_parameter_list,
return_parameter_list)
input parameter list immediate, integer, float
_p _ )
return parameter list integer, float
LEQ Less Than or Equal To
LEQ (source_a, source_B) output
instruction
source A immediate, integer, float no
instruction
this instruction must be followed by an output instruction
to compile correctly
source B immediate, integer, float
LES Less Than
LES (source_a, source_B) output
instruction
source A immediate, integer, float no
instruction
this instruction must be followed by an output instruction
to compile correctly
source B immediate, integer, float
LIM Limit
LIM (low limit test high limit)
low limit immediate, integer, float no
LIM (low_limit, test, high_limit)
output instruction
s s s e ll e a s
test immediate, integer, float
this instruction must be followed by an output instruction
to compile correctly
high limit immediate, integer, float
LFL LIFO Load source immediate, indexed, integer yes
LFL (source, LIFO, control, length,
position)
LIFO array indexed, integer
position)
control control address
length 1 1000
position 0 999
Ladder Functions Reference
Appendix B
B-9
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
LFU LIFO Unload LIFO array indexed, integer yes
LFU (LIFO, destination, control,
length position)
destination indexed, integer
length, position)
control control address
length 1 1000
position 0 999
LN Natural Log source immediate, integer, float no
LN (source, destination)
destination float
LOG Log to the Base 10 source immediate, integer, float no
LOG (source, destination)
destination float
MEQ Mask Compare Equal To
MEQ (source mask compare) output
source operand immediate, integer no
MEQ (source, mask, compare) output
instruction
s s s e ll e a s
source mask immediate, integer
this instruction must be followed by an output instruction
to compile correctly
compare operand immediate, integer
MOV Move source immediate, integer, float no
MOV (source, destination)
destination integer, float
MUL Multiply source A immediate, integer, float no
MUL (source_A, source_B, destination)
source B immediate, integer, float
destination integer, float
MVM Masked Move source operand immediate, integer no
MVM (source, mask, destination)
source mask immediate, Hex integer
destination integer
NEG Negate source immediate, integer, float no
NEG (source, destination)
destination integer, float
NEQ Not Equal To
NEQ (source_A, source_B) output
instruction
source A immediate, integer, float no
instruction
this instruction must be followed by an output instruction
to compile correctly
source B immediate, integer, float
NOT Logical NOT source immediate, integer no
NOT (source, destination)
destination integer
ONS One Shot
ONS bit output instruction
this instruction must be followed by an output instruction
to compile correctly
source bit bit yes
Ladder Functions Reference
Appendix B
B-10
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
OSF One Shot Falling
OSF (storage bit output bit
storage bit bit yes
OSF (storage_bit, output_bit,
output_word) output instruction
s s s e ll e a s
output bit immediate
this instruction must be followed by an output instruction
to compile correctly
output word word
OSR One Shot Rising
OSR (storage bit output bit
storage bit bit yes
OSR (storage_bit, output_bit,
output_word) output instruction
s s s e ll e a s
output bit immediate
this instruction must be followed by an output instruction
to compile correctly
output word word
OTE Output Energize
OTE bit
destination bit bit no
OTL Output Latch
OTL bit
destination bit bit no
OTU Output Unlatch
OTU bit
destination bit bit no
PID PID control PD address no
PID (control, process_variable,
tieback control variable)
control integer address yes
tieback, control_variable)
process variable integer
tieback immediate, integer
control variable integer
RAD Radian (convert degrees to radians) source immediate, float (in degrees) no
RAD (source, destination)
destination float (in radians)
RES Timer/Counter Reset
RES address
address timer, counter, or
control address
no
RET Return
RET (return_parameter_list)
return parameter list immediate, integer, float no
RTOy Retentive Timer On time base immediate (0.01, 1.0) yes
RTO (timer, time base, preset,
accumulated)
PRE 0 32767
accumulated)
ACC 0 32767
SBR Subroutine
SBR (input_parameter_list)
input parameter list integer, float no
SFR SFC reset SFC file number immediate (1 999) no
SFR (file_number, restart_at_step)
restart at step immediate, integer
y This instruction requires periodic scans to be updated.
Ladder Functions Reference
Appendix B
B-11
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
SIN Sine source immediate, float (in radians) no
SIN (source, destination)
destination float (in radians)
SQI Sequencer Input file integer, indexed no
SQI (file, mask, source, control,
length, position) output instruction
s s s e ll e a s
mask immediate, Hex indexed,
integer
this instruction must be followed by an output instruction
le e l
source immediate, indexed, integer
to compile correctly
control control address
length 1 1000
position 0 999
SQL Sequencer Load file integer, indexed yes
SQL (file, source, control, length,
position)
source immediate, indexed, integer
position)
control control address
length 1 1000
position 0 999
SQO Sequencer Output file integer, indexed yes
SQO (file, mask, destination, control,
length position)
mask immediate, indexed, integer
length, position)
destination indexed, integer
control control address
length 1 1000
position 0 999
SQR Square Root source immediate, integer, float no
SQR (source, destination)
destination integer, float
SRT Sort sort file integer, float yes
SRT (file, control, length, position)
control control address
length 1 1000
position 0 999
STD Standard Deviation standard deviation file integer, float yes
STD (file, destination, control,
length position)
destination integer, float
length, position)
control control address
length 1 1000
position 0 999
SUB Subtract source A immediate, integer, float no
SUB (source_A, source_B, destination)
source B immediate, integer, float
destination integer, float
Ladder Functions Reference
Appendix B
B-12
Structured Text User Manual
Instruction Require
False-to-True
Transition
Valid Value Operand Description
structured-text syntax
TAN Tangent source immediate, float (in radians) no
TAN (source, destination)
destination float (in radians)
TOD To BCD source immediate, integer no
TOD (source, destination)
destination integer
TOFy Timer Off Delay timer timer yes: requires
a
TOF (timer, time base, preset,
accumulated)
time base immediate (0.01, 1.0)
a
truetofalse
a s
accumulated)
PRE 0 32767
truetofalse
transition to
e e e
ACC 0 32767
execute
TONy Timer On Delay timer timer yes
TON (timer, time base, preset,
accumulated)
time base immediate (0.01, 1.0)
accumulated)
PRE 0 32767
ACC 0 32767
UID User Interrupt Disable
UID
no
UIE User Interrupt Enable
UIE
no
XIC Examine On
XIC bit output instruction
this instruction must be followed by an output instruction
to compile correctly
source bit bit no
XIO Examine Off
XIO bit output instruction
this instruction must be followed by an output instruction
to compile correctly
source bit bit no
XPY X to the Power of Y source A immediate, integer no
XPY (source_A, source_B, destination)
source B immediate, integer
destination integer
y This instruction requires periodic scans to be updated.
Appendix
C
C-1
Structured Text User Manual
ASCII Structured Text Programming Example
This programming example is an ASCII structured text file that you can import
into 6200 using the import/export functions. For more information about
importing ASCII files, see the PLC-5 Programming Manual,
publication 6200-6.4.7.
START PLC5_80 SERIES_C REV_E COMPLETE
DATA O:277
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
DATA I:277
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000 0X0000
DATA S:127
% STATUS FILE COMMENT
DH+ station: 33 Mode: ADAPTER Local hardware addressing: 1SLOT
Ram backup: DISABLEDMemory: UNPROTECTED EEPROM: TRANSFER DISABLED
Arithmetic flags S:0 Z:0 V:0 C:0 CHECKSUM: 12912
User control bits 00000000 00000000 RESTART FIRST STEP
Processor status 00100000 10001000 MODE SWITCH IN REMOTE
Minor fault 00000000 00000010 DH+ TABLE CHANGE
Minor fault2 00000000 00000000
Major fault 00000000 00000000
Fault code 23 FILE NUMBER OUT OF RANGE
Where faulted prog file: 2 rung: 0
Fault routine prog file: 0 watchdog: 500
Select. timed inter.prog file: 0 setpoint: 0
Select. scan [msec] last: 0 max: 0
Program input inter.prog file: 0 input word: 00
ASCII Structured Text
Processor Memory
File Example
ASCII Structured Text Programming Example
Appendix C
C-2
Structured Text User Manual
PII scan [msec] last: 0 max: 0
PII input mask: 0000000000000000 preset: 0 accum: 0
PII in polarity: 0000000000000000 return mask: 0000000000000000
Program scan [msec] last: 7 max: 284
Date/time 00000406 23:53:17Indexed addressing offset 0
Adapter Image file: 0 I/O Status File: 0 VME status file: 0
Active node list
0 10 20 30 40 50 60 70
00000000 00000000 00000000 00010000 00001000 00000000 00000000 00000000
0 7 I/O STATUS btx full 00000000 rack fault 00000000
I/O CONTROL reset: 00000000 inhibit: 00000000
10 17 I/O STATUS btx full 00000000 rack fault 00000000
I/O CONTROL reset: 00000000 inhibit: 00000000
20 27 I/O STATUS btx full 00000000 rack fault 00000000
I/O CONTROL reset: 00000000 inhibit: 00000000
MCP inhibit: 0000000000000000
MCP prog file: 2 last: 3 max: 9
MCP prog file: 3 last: 4 max: 281
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
MCP prog file: 0 last: 0 max: 0
%
0 8328 13797 0 2048 16 0 0 7 284
2 0 23 2 0 0 0 0 0 4
6 23 53 17 0 0 0 0 500 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 12912 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
2 3 9 3 4 281 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
DATA B3:1
0 0
ASCII Structured Text Programming Example
Appendix C
C-3
Structured Text User Manual
DATA T4:3
0X026f 2 0
0X020a 2 0
0X02a5 34 0
0X02fa 2 0
DATA C5:2
0X0000 1 0
0X2000 100 188
0X0000 100 41
DATA R6:0
0X0000 0 0
DATA N7:50
0 1 1 0 0 0 601 0 0 0
0 0 0 0 0 0 0 0 0 0
20 0 0 0 0 0 0 0 0 0
2 500 1 0 0 7 31 0 0 0
0 0 0 0 0 0 0 0 0 0
17
DATA F8:25
1 3 1.7320508 5 5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
2 5 3 1 1.5
1
PROJECT P80NEW
3 text1
LADDER 2
SOR XIC I:001/004 CTU C5:2 100 41 EOR
SOR MOV N7:46 N7:36 EOR
ST_TEXT 3
IF (I:001/007) THEN
F8:23 := ((1.0 * F8:21)+( SQR ((F8:21 * F8:21)((4.0 * F8:20)* F8:22))))/(2.0 * F8:20);
F8:24 := ((1.0 * F8:21)(SQR((F8:21 * F8:21)((4.0 * F8:20)* F8:22))))/ (2.0 * F8:20);
END_IF;
F8:25 := ((1.0 * F8:21)+( SQR ((F8:21 * F8:21)((4.0 * F8:20)* F8:22))))/ (2.0 * F8:20);
IF (I:001/007) THEN
SQR (F8:1, F8:2);
NEG (F8:3, F8:4);
END_IF;
AFI () CTU (C5:1, 100, 188);
IF (I:001/004) THEN
CTU (C5:1, 100, 188);
END_IF;
N7:35 := 7;
N7:36 := 31;
IF (I:001/000) THEN
TON (T4:0, 1.0, 2, 0);
END_IF;
ASCII Structured Text Programming Example
Appendix C
C-4
Structured Text User Manual
IF (T4:0.DN) THEN
O:001/000 := 1;
O:001/001 := 1;
O:001/002 := 1;
O:001/003 := 1;
O:001/004 := 1;
O:001/005 := 1;
O:001/006 := 1;
O:001/007 := 1;
END_IF;
IF (T4:0.DN) THEN
TON (T4:1, 1.0, 2, 0);
END_IF;
IF (T4:1.DN) THEN
O:001/000 := 0;
O:001/001 := 0;
O:001/002 := 0;
O:001/003 := 0;
O:001/004 := 0;
O:001/005 := 0;
O:001/006 := 0;
O:001/007 := 0;
RES (T4:0);
RES (T4:1);
END_IF;
IF (I:001/001 AND !I:001/000) THEN
TON (T4:2, 1.0, 34, 0);
END_IF;
IF ((T4:2.ACC > 2) AND I:001/001) THEN
O:001/000 := 1;
END_IF;
IF ((T4:2.ACC > 4) AND I:001/001) THEN
O:001/001 := 1;
END_IF;
IF ((T4:2.ACC > 6) AND I:001/001) THEN
O:001/002 := 1;
END_IF;
IF ((T4:2.ACC > 8) AND I:001/001) THEN
O:001/003 := 1;
END_IF;
IF ((T4:2.ACC > 10) AND I:001/001) THEN
O:001/004 := 1;
END_IF;
IF ((T4:2.ACC > 12) AND I:001/001) THEN
O:001/005 := 1;
END_IF;
IF ((T4:2.ACC > 14) AND I:001/001) THEN
O:001/006 := 1;
END_IF;
ASCII Structured Text Programming Example
Appendix C
C-5
Structured Text User Manual
IF ((T4:2.ACC > 16) AND I:001/001) THEN
O:001/007 := 1;
END_IF;
IF ((T4:2.ACC > 18) AND I:001/001) THEN
O:001/007 := 0;
END_IF;
IF ((T4:2.ACC > 20) AND I:001/001) THEN
O:001/006 := 0;
END_IF;
IF ((T4:2.ACC > 22) AND I:001/001) THEN
O:001/005 := 0;
END_IF;
IF ((T4:2.ACC > 24) AND I:001/001) THEN
O:001/004 := 0;
END_IF;
IF ((T4:2.ACC > 26) AND I:001/001) THEN
O:001/003 := 0;
END_IF;
IF ((T4:2.ACC > 28) AND I:001/001) THEN
O:001/002 := 0;
END_IF;
IF ((T4:2.ACC > 30) AND I:001/001) THEN
O:001/001 := 0;
END_IF;
IF ((T4:2.ACC > 32) AND I:001/001) THEN
O:001/000 := 0;
END_IF;
IF (T4:2.DN) THEN
RES (T4:2);
END_IF;
CASE (N7:50) OF
1 :
O:001/000 := 1;
2 :
O:001/001 := 1;
3 :
O:001/002 := 1;
4 :
O:001/003 := 1;
5 :
O:001/004 := 1;
6 :
O:001/005 := 1;
7 :
O:001/006 := 1;
8 :
O:001/007 := 1;
9 :
O:001/000 := 0;

ASCII Structured Text Programming Example
Appendix C
C-6
Structured Text User Manual
10 :
O:001/001 := 0;
11 :
O:001/002 := 0;
12 :
O:001/003 := 0;
13 :
O:001/004 := 0;
14 :
O:001/005 := 0;
15 :
O:001/006 := 0;
16 :
O:001/007 := 0;
END_CASE;
IF (I:001/003) THEN
TON (T4:3, 1.0, 2, 0);
END_IF;
IF (T4:3.DN) THEN
N7:50 := N7:50 + 1;
END_IF;
IF (N7:50 > 17) THEN
N7:50 := 0;
END_IF;
IF (T4:3.DN) THEN
RES (T4:3);
END_IF;
IF (I:001/004) THEN
N7:31 := 500;
N7:32 := 0;
N7:35 := 7;
N7:36 := 31;
N7:6 := 0;
N7:7 := 0;
N7:8 := 0;
FOR (N7:30 := 2 TO N7:35 BY 2) DO
N7:32 := N7:32 + 1;
REPEAT
N7:6 := N7:6 + 1;
UNTIL (N7:6 > 600) END_REPEAT;
IF (N7:6 > 550) THEN
EXIT;
END_IF;
END_FOR;
END_IF;
SFC2 4
FORCE FO:277
0X0000 0X0000
0X0000 0X0000
0X0000 0X0000 . . .
ASCII Structured Text Programming Example
Appendix C
C-7
Structured Text User Manual
FORCE FI:277
0X0000 0X0000
0X0000 0X0000
0X0000 0X0000
0X0000 0X0000 . . .
PLC2 $3:0:47
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
PLC2 $3:1:47
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
PLC2 $3:2:47
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
PLC2 $3:3:47
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
PLC2 $3:4:47
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
PLC2 $3:5:47
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
ASCII Structured Text Programming Example
Appendix C
C-8
Structured Text User Manual
CONFIG $4:0
CONFIG $4:1:411
1 1 32574 3335 18954 7717 1 4097 8224 8224
8224 8224 1 4097 8224 8224 8224 8224 1 5121
28207 7175 18954 7717 257 260 257 0 0 0
0 0 0 0 0 0 0 0 0 0 . . .
CONFIG $4:2:17
8192 6995 21826 1024 0 0 28672 50 771 768
1536 0 0 781 243 2560 0 1000
CONFIG $4:3:17
8192 6995 21826 1024 0 0 28672 50 771 768
1536 0 0 781 243 2560 0 1000
CONFIG $4:4:71
130 0 8 27 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
CONFIG $4:5:71
129 0 8 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
CONFIG $4:6:71
127 0 8 3264 0 24 1 24 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
CONFIG $4:7:71
127 0 8 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
ASCII Structured Text Programming Example
Appendix C
C-9
Structured Text User Manual
The actual structured text for the preceding ASCII processor memory file is
shown below.
IF (I:001/007) THEN
F8:23 := ((1.0 * F8:21) + ( SQR ((F8:21 * F8:21) ((4.0 * F8:20) * F8:22)))) / (2.0 * F8:20);
F8:24 := ((1.0 * F8:21) ( SQR ((F8:21 * F8:21) ((4.0 * F8:20) * F8:22)))) / (2.0 * F8:20);
END_IF;
F8:25 := ((1.0 * F8:21) + ( SQR ((F8:21 * F8:21) ((4.0 * F8:20) * F8:22)))) / (2.0 * F8:20);
IF (I:001/007) THEN
SQR (F8:1, F8:2);
NEG (F8:3, F8:4);
END_IF;
AFI () CTU (C5:1, 100, 188);
IF (I:001/004) THEN
CTU (C5:1, 100, 188);
END_IF;
N7:35 := 7;
N7:36 := 31;
IF (I:001/000) THEN
TON (T4:0, 1.0, 2, 0);
END_IF;
IF (T4:0.DN) THEN
O:001/000 := 1;
O:001/001 := 1;
O:001/002 := 1;
O:001/003 := 1;
O:001/004 := 1;
O:001/005 := 1;
O:001/006 := 1;
O:001/007 := 1;
END_IF;
IF (T4:0.DN) THEN
TON (T4:1, 1.0, 2, 0);
END_IF;
IF (T4:1.DN) THEN
O:001/000 := 0;
O:001/001 := 0;
O:001/002 := 0;
O:001/003 := 0;
O:001/004 := 0;
O:001/005 := 0;
O:001/006 := 0;
O:001/007 := 0;
RES (T4:0);
RES (T4:1);
END_IF;
Structured Text Syntax for
Above ASCII File
ASCII Structured Text Programming Example
Appendix C
C-10
Structured Text User Manual
IF (I:001/001 AND !I:001/000) THEN
TON (T4:2, 1.0, 34, 0);
END_IF;
IF ((T4:2.ACC > 2) AND I:001/001) THEN
O:001/000 := 1;
END_IF;
IF ((T4:2.ACC > 4) AND I:001/001) THEN
O:001/001 := 1;
END_IF;
IF ((T4:2.ACC > 6) AND I:001/001) THEN
O:001/002 := 1;
END_IF;
IF ((T4:2.ACC > 8) AND I:001/001) THEN
O:001/003 := 1;
END_IF;
IF ((T4:2.ACC > 10) AND I:001/001) THEN
O:001/004 := 1;
END_IF;
IF ((T4:2.ACC > 12) AND I:001/001) THEN
O:001/005 := 1;
END_IF;
IF ((T4:2.ACC > 14) AND I:001/001) THEN
O:001/006 := 1;
END_IF;
IF ((T4:2.ACC > 16) AND I:001/001) THEN
O:001/007 := 1;
END_IF;
IF ((T4:2.ACC > 18) AND I:001/001) THEN
O:001/007 := 0;
END_IF;
IF ((T4:2.ACC > 20) AND I:001/001) THEN
O:001/006 := 0;
END_IF;
IF ((T4:2.ACC > 22) AND I:001/001) THEN
O:001/005 := 0;
END_IF;
IF ((T4:2.ACC > 24) AND I:001/001) THEN
O:001/004 := 0;
END_IF;
IF ((T4:2.ACC > 26) AND I:001/001) THEN
O:001/003 := 0;
END_IF;
IF ((T4:2.ACC > 28) AND I:001/001) THEN
O:001/002 := 0;
END_IF;
IF ((T4:2.ACC > 30) AND I:001/001) THEN
O:001/001 := 0;
END_IF;
ASCII Structured Text Programming Example
Appendix C
C-11
Structured Text User Manual
IF ((T4:2.ACC > 32) AND I:001/001) THEN
O:001/000 := 0;
END_IF;
IF (T4:2.DN) THEN
RES (T4:2);
END_IF;
CASE (N7:50) OF
1 :
O:001/000 := 1;
2 :
O:001/001 := 1;
3 :
O:001/002 := 1;
4 :
O:001/003 := 1;
5 :
O:001/004 := 1;
6 :
O:001/005 := 1;
7 :
O:001/006 := 1;
8 :
O:001/007 := 1;
9 :
O:001/000 := 0;

10 :
O:001/001 := 0;
11 :
O:001/002 := 0;
12 :
O:001/003 := 0;
13 :
O:001/004 := 0;
14 :
O:001/005 := 0;
15 :
O:001/006 := 0;
16 :
O:001/007 := 0;
END_CASE;
IF (I:001/003) THEN
TON (T4:3, 1.0, 2, 0);
END_IF;
IF (T4:3.DN) THEN
N7:50 := N7:50 + 1;
END_IF;
IF (N7:50 > 17) THEN
N7:50 := 0;
END_IF;
ASCII Structured Text Programming Example
Appendix C
C-12
Structured Text User Manual
IF (T4:3.DN) THEN
RES (T4:3);
END_IF;
IF (I:001/004) THEN
N7:31 := 500;
N7:32 := 0;
N7:35 := 7;
N7:36 := 31;
N7:6 := 0;
N7:7 := 0;
N7:8 := 0;
FOR (N7:30 := 2 TO N7:35 BY 2) DO
N7:32 := N7:32 + 1;
REPEAT
N7:6 := N7:6 + 1;
UNTIL (N7:6 > 600) END_REPEAT;
IF (N7:6 > 550) THEN
EXIT;
END_IF;
END_FOR;
END_IF;
Index
Structured Text User Manual
A
accepting edits, 3-8
addresses, 3-3
application example, sort routine, A-2
application examples
debugging programs, A-2
free running timer, A-1
ASCII files, 3-9, C-1
Attention
modifying programming examples, 2-1, A-1
sub-element values, 2-11
B
bit operands, 1-3
C
CASE, 2-5
compare expressions, 1-4
conditional iterative loops
EXIT, 2-9
REPEAT, 2-8
WHILE, 2-7
conditional loops
CASE, 2-5
IF-ELSIF-ELSE, 2-4
configuring
PowerText display colors, 4-3
structured text, 3-2
constructs, 1-3, 1-7, 2-1
creating
configurable data monitor, 4-4
structured text files, 3-1
D
data monitor, configurable, 4-4
data types, B-1
debugging programs, A-2
defining
addresses, 3-3
symbols, 3-3
display characteristics, configuring, 3-2
documentation reports, 3-10
E
editing
accepting edits, 3-8
ASCII files, 3-9
in Windows, 3-9
online, 3-9
structured text, 3-1, 3-7
EMPTY (;;), 2-10
entering
accepting edits, 3-8
structured text, 3-1, 3-5
equivalents to ladder functions, 2-11
EXIT, 2-9
F
false-to-true transitions, B-1
field widths, 4-5
FOR, 2-6
I
IF-ELSIF-ELSE, 2-4
immediates, 1-3
Important
creating a monitoring screen, 4-4
editing online in Program or Remote
Program mode, 3-9
exiting FOR loops, 2-7
exiting REPEAT loops, 2-9
exiting WHILE loops, 2-8
floating point values, 2-5
I/O addresses in iterative constructs, 2-7, 2-8
installing structured text, 1-1
line length, 1-6
multiple CASE values, 2-5
PowerText intensification, 4-1
processor modes, 3-7
removing previous versions of software, 1-1
software products, 3-1
supported ladder instructions, B-1
using % characters, 1-6
using braces ({ }), 1-7
Index
Structured Text User Manual
using ladder instructions inside conditional
constructs, 2-12
using parentheses, 4-5
using SBR instructions, 2-11
using semi colons, 1-6
valid output instructions, 2-11
input expressions, 1-5
input instructions, 1-4
installing, structured text, 1-1
instructions
constructs, 2-10
input, 1-4
output, 1-5
reference, B-1
structured text equivalents, 2-11
iterative loops
EXIT, 2-9
FOR, 2-6
L
ladder functions, 2-10
line length, 1-6, 4-5
M
math expressions, 1-4
memory requirements, 2-12
monitoring, structured text, 4-1
N
non-retentive bit assignments, 2-2
O
operands, 1-3, B-1
order of precedence, 1-5
output instructions, 1-5
P
PowerText
configurable data monitor, 4-4
configuring display colors, 4-3
field widths, 4-5
line length, 1-6
monitoring structured text, 4-1
programming examples
ASCII structured text, C-1
debugging, A-2
free running timer, A-1
sort routine, A-2
R
reference, instructions, B-1
REPEAT, 2-8
reports, generating, 3-10
reserved words, 1-7
retentive bit assignments, 2-3
rules, 1-6
S
sort routine, A-2
string data types, 1-6
structured text
accepting edits, 3-8
application examples, A-1
ASCII files, 3-9
bit operands, 1-3
CASE, 2-5
compare expressions, 1-4
comparison to C, 1-7
configurable data monitor, 4-4
constructs, 1-3, 1-7, 2-1
definition, 1-1
editing, 3-1, 3-7
Index
Structured Text User Manual
EMPTY (;;), 2-10
entering, 3-5
equivalents to ladder functions, 2-11
EXIT, 2-9
FOR, 2-6
IF-ELSIF-ELSE, 2-4
immediates, 1-3
input expressions, 1-5
input instructions, 1-4
installing, 1-1
ladder functions, 2-10
line length, 1-6, 4-5
math expressions, 1-4
memory for constructs, 2-12
monitoring, 4-1
non-retentive bit assignments, 2-2
operands, 1-3
order of precedence, 1-5
output instructions, 1-5
overview, 1-1
PowerText, 4-1
programming examples, C-1
REPEAT, 2-8
reports, 3-10
reserved words, 1-7
retentive bit assignments, 2-3
rules, 1-6
support, 1-1
variable assignments, 2-2
WHILE, 2-7
whitespace, 1-5, 1-8
writing, 1-1
symbols, 3-3
T
Tip
[AltF7] key toggles documentation display,
4-1
saving files with syntax errors, 3-8
V
variable assignments, 2-2
W
WHILE, 2-7
whitespace, 1-5, 1-8
writing, structured text, 1-1
PLC-5, PLC-5/11, PLC-5/20, PLC-5/30, PLC-5/40, PLC-5/60 and PLC-5/80 are
registered trademarks of Allen-Bradley Company, Inc.
PowerText is a trademark of Allen-Bradley Company, Inc.
If you need additional assistance in using your software, Allen-Bradley offers
telephone and on-site product support at Customer Support Centers worldwide.
For technical assistance on the telephone, first contact your local sales office,
distributor, or system integrator. If additional assistance is needed, then contact
your local Customer Support Center or contact System Support Services.
In the United States and Canada
If you have a SupportPlus agreement or your software is under warranty, you
can contact System Support Services at: 1-800-289-2279. Have your support
contract or software registration number available.
For assistance that requires on-site support, contact your local sales office,
distributor, or system integrator.
Outside of the United States
Contact your local Customer Support Center at:
Region or Area Customer Support Center
Telephone Number
Canada (Cambridge, Ontario) 519-623-1810
Latin America (Milwaukee) 414-382-2000
United Kingdom (Milton Keynes) 44-908 838800
Europe (Amsterdam) 31-2975 43500
France (Paris) (33-1) 4778 1402
Germany (Gruiten) (49) 2104 6900
Italy (Milan) (39-2) 4830 0381
Asia Pacific (Hong Kong) (852) 873-1342
Customer Support
Worldwide representation.
Algeria Argentina Australia Austria Bahrain Belgium Brazil Bulgaria Canada Chile China, PRC Colombia Costa Rica Croatia Cyprus Czech Republic
Denmark Ecuador Egypt El Salvador Finland France Germany Greece Guatemala Honduras Hong Kong Hungary Iceland India Indonesia Israel Italy
Jamaica Japan Jordan Korea Kuwait Lebanon Malaysia Mexico New Zealand Norway Oman Pakistan Peru Philippines Poland Portugal Puerto Rico
Qatar Romania RussiaCIS Saudi Arabia Singapore Slovakia Slovenia South Africa, Republic Spain Switzerland Taiwan Thailand The Netherlands Turkey
United Arab Emirates United Kingdom United States Uruguay Venezuela Yugoslavia
Allen-Bradley Headquarters, 1201 South Second Street, Milwaukee, WI 53204 USA, Tel: (1) 414 382-2000 Fax: (1) 414 382-4444
Allen-Bradley, a Rockwell Automation Business, has been helping its customers improve
productivity and quality for 90 years. We design, manufacture, and support a broad range of
control and automation products worldwide. They include logic processors, power and motion
control devices, man-machine interfaces, sensors, and a variety of software. Rockwell is one
of the worlds leading technology companies.
Publication 6200-6.4.18 February 1995
Supersedes 6200-6.4.18 July 1993
PN 955116-95
Copyright 1995 Allen-Bradley Company, Inc. Printed in USA

You might also like