Upload
ralejaga5970
View
243
Download
2
Embed Size (px)
Citation preview
8/10/2019 PLC Structured Text
1/75
PLC-5 Structured TextRelease 1.1
User Manual
8/10/2019 PLC Structured Text
2/75
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
8/10/2019 PLC Structured Text
3/75
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 f loating 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 fromthe structured text editor
chapter 3
information about accepting structured text edits chapter 3
information about editing structured text files in multipleWindows sessions
chapter 3
clarification about how the PowerText feature intensifiesaddresses with NOT operands
chapter 4
how to toggle between displaying addresses and symbolswhen monitoring structured text
chapter 4
correction to the programming example for creating aconfigurable 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 afalse-to-true transition before executing
appendix B
new appendix that shows an example of an ASCII structuredtext 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
8/10/2019 PLC Structured Text
4/75
PrefaceStructured Text User Manual
i
StructuredText User Manual
6200 Programming SoftwareStructured Text
Your PLC-5programmable 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 1EnhancedPLC-5 Programmable Controller Documentation
Programming
6200-6.4.7
Software Configurationand Maintenance
6200-6.4.6
Configuring processorProcessor/channel status
Defining data table files
Printing reportsClearing faults
Saving/restoring filesCreating/managing files
Creating/editing SFCsImporting/exporting
I/O Configuration
6200-6.4.12
Software
Configuring intelligentI/O modules
6200-6.4.11
ReferenceInstruction Set
Instruction execution,parameters, statusbits and examples
1785 PLC-5Programmable Controllers
Quick Reference
Quick access to switches,status bits, indicators,
1785-7.1
6200-6.4.18
Structured TextUser Manual
Program considerations
Mnemonic explanationsProgram examples
Using PowerTextInstruction parametersand syntax
Creating/editing/documenting ladderlogic programs
instructions, software screens
Installing 6200programming software
1785-6.5.12
Enhanced and EthernetPLC-5 Programmable
Controllers User Manual
Enhanced PLC-5Programmable
Controllers
Ethernet PLC-5
1785-2.38 1785-2.30
Placing system hardwareAddressing I/O andprocessor memoryCommunicating withdevices on a DH+, serial,and Ethernet link
Installation Instructions
Programmable
ControllersInstallation Instructions
Handling the Enhanced
Connecting a remote,extended local, andDH+ link
PLC-5 processorHandling the Enhanced
Connecting a remote,extended local, andDH+ link
PLC-5 processor
For more information about PLC-5 programmablecontrollers or these publications, contact yourlocal sales office, distributor, or system integrator.
HARDWARE SOFTWARE
Youare here
How to Use YourDocumentation
8/10/2019 PLC Structured Text
5/75
Structured Text User ManualPreface
ii
StructuredText 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/VMEprocessors.
Enhanced PLC-5 processors PLC-5/11, -5/20, -5/30, -5/40, -5/40L, -5/60
,
-5/60L,and -5/80processors.
Important: Unless otherwise specified, Enhanced PLC-5processors include Ethernet PLC-5 and VME PLC-5 processors.
Ethernet PLC-5 processors PLC-5/20E, -5/40E, and -5/80Eprocessors.
VME PLC-5 processors PLC-5/V30, -5/V40, -5/V40L, and -5/V80 processors. See thePLC-5/VME VMEbus Programmable Controllers User Manual,publication 1785-6.5.9, for more information.
Where to Start
Conventions
8/10/2019 PLC Structured Text
6/75
Structured Text User ManualPreface
iii
StructuredText 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
ProgramDirectory
Press1
2
3
Enter the number of the file to create.
Press Esc to return to ProgramDirectory
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
8/10/2019 PLC Structured Text
7/75
Structured Text User ManualTable of Contents
iv
StructuredText User Manual
Chapter1Chapter 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. . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter2Chapter 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. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter3
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. . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter4Chapter 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
8/10/2019 PLC Structured Text
8/75
Structured Text User ManualTable of Contents
v
StructuredText User Manual
Appendix AAppendix Objectives A-1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Programming a Free Running Timer A-1. . . . . . . . . . . . . . . . . . . . . . . . .
Programming a Sort Routine A-2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging Programs A-2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix BInstruction Operands and Valid Data Types B-1. . . . . . . . . . . . . . . . . . .
Appendix CASCII Structured Text Processor Memory File Example C-1. . . . . . . . .
Structured Text Syntax for Above ASCII File C-9. . . . . . . . . . . . . . . . .
ApplicationExample
Instruction Reference
ASCII Structured TextProgramming Example
8/10/2019 PLC Structured Text
9/75
Important: Remove any previous versions of thesoftware before installing the new version. Forinformation about removing the software, seethe PLC-5 Configuration and Maintenancemanual, publication 6200-6.4.6.
a:is the drive where you insert the disk.
c:is any destination hard-disk for theprogramming software.
Chapter
1
1-1
StructuredText 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 isbased 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 number62xx-PLC5) and theninstall 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
ChapterObjectives
Using Structured Text
Installing the Software
8/10/2019 PLC Structured Text
10/75
Writing Structured TextChapter 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 installand use this software on a single processing unit. You are not licensed toinstall the software on more than one processing unit or to distribute it inany way. Support and updates will be provided to registered customersonly. To register your software, return the enclosed registration card assoon as possible.
WARNINGTHIS SOFTWARE IS PROTECTED UNDER THE COPYRIGHT LAWS OF THE UNITED STATES.UNAUTHORIZED REPRODUCTION OF COPYRIGHTED SOFTWARE VIOLATES U.S. COPYRIGHTLAWS. CRIMINAL PENALTIESMAY INCLUDE FINES OR IMPRISONMENT.
******************************************************************
******************************************************************
Contents: PLC-5 Prog Structured Text Programming OptionCatalog Number: 6203-ST5Part Number: XXXXXX-XXRelease Number: 1.1 Quantity 1 Disk
Press any key
Press
Contents: PLC-5 Prog Structured Text Programming OptionCatalog Number: 6203-ST5Part Number: XXXXXX-XXRelease 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 frontof 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 44143Serial Number:: XXOXXOXX
Press ENTER to continue with the installation
8/10/2019 PLC Structured Text
11/75
Writing Structured TextChapter 1
1-3
StructuredText User Manual
After you enter the product registration, you see:
Contents: PLC-5Prog Structured Text Programming OptionCatalog Number: 6203-ST5Part Number: XXXXXXXXXRelease Number: 1.1 Quantity x Disks
Instructions
The File Copy portion of Install is Complete: Press ENTER
Status98% Complete
0% 25% 50% 75% 100%
CopyUPD.EXE to C:\IPDS\UPD.EXE
Enter
After structured text is installed,press
The percent completion baradvances as the installationprogresses.
The file names display as theyare 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
8/10/2019 PLC Structured Text
12/75
Writing Structured TextChapter 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
= 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
8/10/2019 PLC Structured Text
13/75
Writing Structured TextChapter 1
1-5
StructuredText 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. =, , >,
8/10/2019 PLC Structured Text
14/75
Writing Structured TextChapter 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 MUSTbe separated by whitespace
For example:
The characterindicates where you should enter a space.
N7:0:=10;
N7:0:=N7:10;
N7:0:=R6:0.LEN;
F8:0:=((N7:1*3.14)+(N7:3/N7:4));
Each statement must end with a semicolon. See chapter 3.
String data types are not supported by the PowerTextfeature.
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 whileare
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 WritingStructured Text
8/10/2019 PLC Structured Text
15/75
Writing Structured TextChapter 1
1-7
StructuredText 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 semicolonrequired)
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 usingstandard 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
8/10/2019 PLC Structured Text
16/75
Writing Structured TextChapter 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 thefirst level of the following constructs (not nestedconstructs): IF, ELSEIF, ELSE, CASE, FOR, WHILE,REPEAT. See Blank Line 1 and Blank Line 2 and thearrows indicating no lines between nested constructs.
The compiler removes the blank lines you insert inplaces other than before and after the first level of theabove constructs, i.e. before or after a variableassignment, before or after a ladder function. SeeBlank Line 3 and Blank Line 4. If you insert theselines, the compiler removes them.
End Construct
8/10/2019 PLC Structured Text
17/75
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 constructsthat 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 valueto a data table location
variable assignment 2-2
make bit assignments (non-retentive) non-retentive bitassignment
2-2
make bit assignments (retentive) retentive bitassignment
2-3
conditionally execute a section of code IF-ELSIF-ELSE 2-4
conditionally execute a section of codebased on the value of a math expressionor operand
CASE 2-5
repeat a section of code a specifiednumber 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 inputcondition becomes true
REPEAT 2-8
exit an iterative command (FOR, WHILE,or REPEAT) before it reaches the normaltermination condition
EXIT 2-9
perform no function, treated aswhitespace
;; 2-10
call PLC-5 input instruction or outputinstruction 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.
ChapterObjectives
8/10/2019 PLC Structured Text
18/75
Structured Text ConstructsChapter 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 ;
: := : . ;
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:10 / 10)
END_REPEAT;
N7:0 increments by 1
until N7:0 is greater than N7:10divided 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
8/10/2019 PLC Structured Text
25/75
Structured Text ConstructsChapter 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, orREPEAT) 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; FORN7: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
8/10/2019 PLC Structured Text
26/75
Structured Text ConstructsChapter 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:
;; IFN7:0/0 THEN;;
ELSE
N7:2 := N7:5 +10;
END_IF;
no effect on program scantime
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 theladder 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
8/10/2019 PLC Structured Text
27/75
Structured Text ConstructsChapter 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 pagereferences for these functions. Structured text has no direct equivalent to
the JMP instruction. Use the CASE and WHILE constructs instead.
For an Equivalent tothese 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 instructured 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.
8/10/2019 PLC Structured Text
28/75
Structured Text ConstructsChapter 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 theirladder 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 wordsEND_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
8/10/2019 PLC Structured Text
29/75
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 forstructured 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
Press1
2
3
Enter the number of the file to create.
Press Esc to return to ProgramDirectory
F8
Create STxt Fl
to create a structured text file.
F6
Create File
ChapterObjectives
Creating a StructuredText File
8/10/2019 PLC Structured Text
30/75
Using the Structured Text EditorChapter 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 tostructured text file
ProgramDirectory
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:
SFCMain Menu
F7
GeneralUtility
F2
Configure Display
F8
Act/CndWindow
+= 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 StructuredText Editor
8/10/2019 PLC Structured Text
31/75
Using the Structured Text EditorChapter 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) byentering it on the command line or using theleft/right arrow keys
[F1] - Act/Cond Fld
Adjusting the Action/Condition field automaticallyadjusts the Comment field size.
Specify the comment field size for theaction/condition window (0-60 characters) byentering it on the command line or using theleft/right arrow keys
[F2] - Comment Field
Adjusting the Comment field automatically adjuststhe Action/Condition field size.
Display address symbols [F3] - Address Display: Display/Suppress Symbol
Suppress address symbolsThis key toggles between displaying or suppressingaddress symbols. The default is to display symbols.
Display the f irst line of structured text [F4] - Act/Cnd Display
This key toggles between displaying the first line ofDisplay the structured text file number
Thi y togg b tw n di p ying th fir t in ofstructured text and displaying the structured text filenumber 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:
DefiningAddressesand Symbols
8/10/2019 PLC Structured Text
32/75
Using the Structured Text EditorChapter 3
3-4
Structured Text User Manual
6200Main Menu
F8
Cursor to astructured text file orenter file number
Monitor File
F5
EditDBASE
ProgramDirectory
F1
Online Prog
F3
Offline Prog
or
6200Main Menu
F8
Cursor to astructured text file orenter file number
Monitor File
ProgramDirectory
F1
Online Prog
F3
Offline Prog
or
To access the documentation database: To access the data table monitor:
F8
DataMonitor
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.
8/10/2019 PLC Structured Text
33/75
8/10/2019 PLC Structured Text
34/75
Using the Structured Text EditorChapter 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) |
| |
| |
| |
+==============================================================================+
SFCEdit Selections
F10
Edit
SFCMain Menu
F3
Append
Step/Trn orF4
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 chooseto 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
StepActions
a
b If you press F2 Trans
F2
Edit Text
F2
Edit Text
8/10/2019 PLC Structured Text
35/75
Using the Structured Text EditorChapter 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 moreinformation on how the editor works, see chapter 17 in thePLC-5 Programming manual, 6200-6.4.7.
SFCEdit Selections
F10
Edit
SFCMain Menu
F5
F1
Step Actions
F2
Edit Text
Ladder EditorMain Menu
F8
Cursor to astructured text file orenter file number
Monitor File
F10
Edit
Within an SFC
or F2
Trans
Modify Stp/Trn
Cursor to the Action orCondition Text field
SFCMain Menu
F1
Online Prog
F3
Offline Prog
or
MCP or Subroutine
F4
Prog Dir
Editing Structured Text
8/10/2019 PLC Structured Text
36/75
Using the Structured Text EditorChapter 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 structuredtext, 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 thebeginning of the areayou want to save.
ST Editor
F7
Advanced Editing
F1
Select
Move the cursor to theend of the area youwant to save.
To select the structuredtext to save to disk file:
ST Editor
F2
Cut
F7
Copy to Disk
To copy the selected structuredtext to disk file:
with selected texthighlighted
TIP
8/10/2019 PLC Structured Text
37/75
Using the Structured Text EditorChapter 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 toaccept 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.
8/10/2019 PLC Structured Text
38/75
Using the Structured Text EditorChapter 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
6200Main Menu
selectStructured TextListingas the report togenerate by cursoring to it andpressing
F3
CreateOffline
Select the range of filesto include in the report.
or F1
Create Online
currentprocessormemoryfile
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 DocumentationReports
8/10/2019 PLC Structured Text
39/75
Using the Structured Text EditorChapter 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
AbortUtility
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 textlisting file has a .TXR extension and resides in the IPDS\TEXT\PLC5 directory.
F8
Reports
6200Main 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 processorname you want
8/10/2019 PLC Structured Text
40/75
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 alsodisplays 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 tostructured text file
ProgramDirectory
F8
Monitor File
When monitoring a structured text file, press F7Alt to toggle between
displaying or suppressing documentation.
ChapterObjectives
Using PowerText
TIP
8/10/2019 PLC Structured Text
41/75
Monitoring Structured TextChapter 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;
ProgramDirectory
F8
Cursor to astructured text file orenter file number
Monitor File
If you havent entered logic (structured text) into the program file yet,this window says only: Empty Structured Text File
6200Main 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.
SFCMain Menu
MCP or Subroutine Within an SFC:
If you have not configured the Action Window toappear on the screen, press
Cursor to the structured textfield and press Enter
Alt A
Alt A (a cursor appears in the action window)
PowerText values
8/10/2019 PLC Structured Text
42/75
Monitoring Structured TextChapter 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
SoftwareConfig
F3
Color
Selection
If you want to change the color mode, press this key
If you just installed yourprogramming software, the defaultcolor selection is monochrome.
If you have a monochromemonitor, use the default selection.If you use color choices on amonochrome monitor, someitems may be difficult orimpossible (invisible) to read. Forexample, if your monitor ismonochrome, and you set thebackground color for theinstruction cursor the same as thatfor main displays, the cursoris invisible.
This Selection: Applies to: Displays in:
True Logic display of bit values andother values
the foreground color you configure for True Logicand the background color you configure forOption Windows
False Logic the foreground and background color youconfigure for Option Windows
Forces whether forces are enabled when enabled, the foreground color you configurefor Forces and the background color you configurefor Option Windows
when disabled, the foreground and backgroundcolor you configure for Option Windows
Option Windows the structured text view window the foreground and background color you
configure for Option WindowsData Entry Windows the structured text edit window the foreground and background color you
configure for Option Windows
8/10/2019 PLC Structured Text
43/75
Monitoring Structured TextChapter 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 currentprogramming 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 speci fy 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 monitoringscreens 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 ConfigurableData Monitor
8/10/2019 PLC Structured Text
44/75
Monitoring Structured TextChapter 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/4OR (((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
8/10/2019 PLC Structured Text
45/75
Appendix
A
A-1
StructuredText 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.
AppendixObjectives
Programming a FreeRunning Timer
8/10/2019 PLC Structured Text
46/75
Application ExamplesAppendix A
A-2
StructuredText 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
FILEand STATEvalues to determine where the processor is executing.
Programming a Sort Routine
Debugging Programs
8/10/2019 PLC Structured Text
47/75
Appendix
B
B-1
StructuredText 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-38to+3.4028237e+38). Note that the 1784-T50 may round or truncate thenumber based on the number of significant digits and the size of thefloating 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.
AppendixObjectives
Instruction Operands andValid Data Types
8/10/2019 PLC Structured Text
48/75
Ladder Functions ReferenceAppendix B
B-2
StructuredText User Manual
Table B.AProgramming Instructions and Operands
Instruction Descriptionstructured-text syntax
Operand Valid Value RequireFalse-to-TrueTransition
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 inladder 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 inladder 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, index immediate, 0-82 integerdestination)
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
8/10/2019 PLC Structured Text
49/75
Ladder Functions ReferenceAppendix B
B-3
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-text syntax
ARD ASCII Read Characters channel immediate, 0-4 integer yes
ARD (channel, destination, control, destination stringstring_length, characters_read)
control control address
string length 0 82
characters read integer
(this is a display only field inladder logic)
ARL ASCII Read Line channel immediate, 0-4 integer yes
ARL (channel, destination, control, destination stringstring_length, characters_read)
control control address
string length 0 82
characters read integer
(this is a display only field inladder 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 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, source stringstring_length, characters_sent)
control control address
string length 0 82
characters sent integer
(this is a display only field inladder logic)
8/10/2019 PLC Structured Text
50/75
Ladder Functions ReferenceAppendix B
B-4
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-text syntax
AWT ASCII Write channel immediate, integer yes
AWT (channel, source, control, source stringstring_length, characters_sent)
control control address
length 0 82
characters sent integer
(this is a display only field inladder logic)
BSL Bit Shift Left file binary yes
BSL (file, control, bit_address, control control addresslength)
bit address bit
length 1 16000 (length in bits)
BSR Bit Shift Right file binary yes
BSR (file, control, bit_address, control control addresslength)
bit address bit
length 1 16000 (length in bits)
BTD Bit Distribute source immediate, integer no
BTD (source, source_bit, destination,
destination bit, len th)source bit immediate, (0 15) integer
es na on_ , eng
destination integer
destination bit immediate (0 15)
length immediate (1 16)
8/10/2019 PLC Structured Text
51/75
Ladder Functions ReferenceAppendix B
B-5
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-text syntax
BTR Block Transfer Read rack 00-277 octal yes
BTR (rack, group, module, group 0-7control_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
BTW Block Transfer Write rack 00-277 octal yes
BTW (rack, group, module, group 0-7control_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
this instruction must be followed by an output instructionto 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, floataddresses with evaluators
CTD Count Down counter counter yes
CTD (counter, preset, accumulated) PRE 32768 +32767
ACC 32768 +32767
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.
8/10/2019 PLC Structured Text
52/75
Ladder Functions ReferenceAppendix B
B-6
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-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, reference array binarycompare_control, length, position,
result_control, length, position) result array integer_
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 source immediate, integer no
DTR (source, mask, reference) output
instruction mask immediate, integer
this instruction must be followed by an output instructionto compile correctly
reference integer
EOT End of Transition
EOT
no
EQU Equal
EQU (source_A, source_B) output
source A immediate, integer, float no
nstruct on
this instruction must be followed by an output instructionto compile correctly
source B immediate, integer, float
FAL File Arithmetic/Logical control control address yes
FAL (control, length, position, mode, length 1 1000destination, expression)
position 0 999
mode (INC, 11000, ALL)
destination integer, float
expression indexed math instruction
8/10/2019 PLC Structured Text
53/75
Ladder Functions ReferenceAppendix B
B-7
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-text syntax
FBC File Bit Compare source array binary yes
FBC (source, reference, result, reference array binary compare_control, length, position,
result_control, length, position) result array integer
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 yesFFL (source, FIFO, control, length, FIFO array indexed, integerposition)
control control address
length 1 1000
position 0 999
FFU FIFO Unload FIFO array indexed, integer yes
FFU (FIFO, destination, control, destination indexed, integerlength, 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, length 1 1000expression) output instruction
s s s e ll e a sposition 0 999
thi in truction mu t b fo ow d by n output in tructionto 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
source A immediate, integer, float no
instruction
this instruction must be followed by an output instructionto compile correctly
source B immediate, integer, float
8/10/2019 PLC Structured Text
54/75
Ladder Functions ReferenceAppendix B
B-8
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-text syntax
GRT Greater Than
GRT (source_a, source_B) output
source A immediate, integer, float no
instruction
this instruction must be followed by an output instructionto compile correctly
source B immediate, integer, float
IIN Immediate Input
IIN input_word
I (input word) immediate, integerPLC-5/10, 11, 12 15, 20, 25,30: 000-077PLC-5/40, 40L: 000-157PLC-5/60, 60L, 80, :000-237
no
IOT Immediate Output
IOT output_word
O (output word) immediate, integerPLC-5/40, 40L: 000-157
PLC-5/60, 60L, 80: 000-237
no
JSR Jump to Subroutine ladder f ile number immediate (2 999), integer no
JSR (file_number,
number_of_input_parameters,number of inputparameters
immediate, integer
input_parameter_list,
return_parameter_list) input parameter list immediate, integer, float_ _
return parameter list integer, float
LEQ Less Than or Equal To
LEQ (source_a, source_B) output
source A immediate, integer, float no
instruction
this instruction must be followed by an output instructionto compile correctly
source B immediate, integer, float
LES Less ThanLES (source_a, source_B) output
source A immediate, integer, float no
instruction
this instruction must be followed by an output instructionto compile correctly
source B immediate, integer, float
LIM Limit low limit immediate, integer, float no
LIM (low_limit, test, high_limit)
output instruction test immediate, integer, float
this instruction must be followed by an output instructionto compile correctly
high limit immediate, integer, float
LFL LIFO Load source immediate, indexed, integer yes
LFL (source, LIFO, control, length, LIFO array indexed, integerposition)
control control address
length 1 1000
position 0 999
8/10/2019 PLC Structured Text
55/75
8/10/2019 PLC Structured Text
56/75
Ladder Functions ReferenceAppendix B
B-10
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-text syntax
OSF One Shot Falling storage bit bit yes
OSF (storage_bit, output_bit,
output_word) output instruction output bit immediate
this instruction must be followed by an output instructionto compile correctly
output word word
OSR One Shot Rising storage bit bit yes
OSR (storage_bit, output_bit,
output_word) output instruction output bit immediate
this instruction must be followed by an output instructionto 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, control integer address yestieback, 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, orcontrol address
no
RET Return
RET (return_parameter_list)
return parameter list immediate, integer, float no
RTO Retentive Timer On time base immediate (0.01, 1.0) yes
RTO (timer, time base, preset, PRE 0 32767accumulated)
ACC 0 32767
SBR SubroutineSBR (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
This instruction requires periodic scans to be updated.
8/10/2019 PLC Structured Text
57/75
Ladder Functions ReferenceAppendix B
B-11
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-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 instructionmask immediate, Hex indexed,
integer
this instruction must be followed by an output instructionle e l
source immediate, indexed, integerto compi corr ct y
control control address
length 1 1000
position 0 999
SQL Sequencer Load file integer, indexed yes
SQL (file, source, control, length, source immediate, indexed, integerposition)
control control address
length 1 1000
position 0 999
SQO Sequencer Output file integer, indexed yes
SQO (file, mask, destination, control, mask immediate, indexed, integerlength, 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, destination integer, floatlength, position)
control control addresslength 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
8/10/2019 PLC Structured Text
58/75
Ladder Functions ReferenceAppendix B
B-12
StructuredText User Manual
Instruction RequireFalse-to-TrueTransition
Valid ValueOperandDescriptionstructured-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
TOF TimerOff Delay timer timer yes: requires
TOF (timer, time base, preset, time base immediate (0.01, 1.0)atruetofalse
accumulated)PRE 0 32767
tru to ftransition to
ACC 0 32767execute
TON Timer On Delay timer timer yes
TON (timer, time base, preset, 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