You are on page 1of 75

PLC-5 Structured Text

Release 1.1

User Manual

Important User Information

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.

Structured Text User Manual

Summary of Changes

Whats New

This release of the publication contains updated information.


For this updated information:

See:

corrected the smallest and largest floating point values


rule about using a single % character in a structured text file
information about using and exiting iterative loops
memory requirements for constructs
how to access the database editor and the data monitor from
the structured text editor
information about accepting structured text edits
information about editing structured text files in multiple
Windows sessions
clarification about how the PowerText feature intensifies
addresses with NOT operands
how to toggle between displaying addresses and symbols
when monitoring structured text
correction to the programming example for creating a
configurable data monitor with a structured text file
additional programming example for a sort routine
information about debugging structured text programs
new appendix that lists the supported processor instructions,
syntax, valid operands, and whether an instruction requires a
false-to-true transition before executing

chapter 1
chapter 1
chapter 2
chapter 2
chapter 3

new appendix that shows an example of an ASCII structured


text file that you can import into 6200

appendix C

chapter 3
chapter 3
chapter 4
chapter 4
chapter 4
appendix A
appendix A
appendix B

To help you find new information in this publication, we included change


bars as shown to the right of this paragraph.

Preface
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.

How to Use Your


Documentation

Figure 1
Enhanced PLC-5 Programmable Controller Documentation

HARDWARE

SOFTWARE

Enhanced and Ethernet


PLC-5 Programmable
Controllers User Manual
Placing system hardware
Addressing I/O and
processor memory
Communicating with
devices on a DH+, serial,
and Ethernet link

Software Configuration
and Maintenance
Installing 6200
programming software
Defining data table files
Configuring processor
Processor/channel status
Clearing faults
Printing reports
6200-6.4.6

1785-6.5.12
Enhanced PLC-5
Programmable
Controllers
Installation Instructions

Ethernet PLC-5
Programmable
Controllers
Installation Instructions

Handling the Enhanced


PLC-5 processor
Connecting a remote,
extended local, and
DH+ link

Handling the Enhanced


PLC-5 processor
Connecting a remote,
extended local, and
DH+ link

1785-2.38

1785-2.30

I/O Configuration
Software
Configuring intelligent
I/O modules

6200-6.4.12

1785 PLC-5
Programmable Controllers
Quick Reference
Quick access to switches,
status bits, indicators,
instructions, software screens
1785-7.1

Structured Text
User Manual
Program considerations
Program examples
Mnemonic explanations
Using PowerTextt
Instruction parameters
and syntax
6200-6.4.18

Programming
Creating/managing files
Saving/restoring files
Importing/exporting
Creating/editing SFCs
Creating/editing/
documenting ladder
logic programs

You are here

6200-6.4.7

For more information about PLC-5 programmable


controllers or these publications, contact your
local sales office, distributor, or system integrator.

Instruction Set
Reference
Instruction execution,
parameters, status
bits and examples

6200-6.4.11

Structured Text User Manual

Preface
Structured Text User Manual

Where to Start

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.

Conventions

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.

ii

Structured Text User Manual

Preface
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

+= 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
|
|
|
+==============================================================================+

Proc Functions
F1

Create File
F6

Press a function key.


>
Rem Prog

PLC5/40 Series C Revision C


Create
Create
Lad Fl
SFC Fl
F6
F7

5/40 File EXPSFC


Create
STxt Fl
F8

Create STxt Fl
F8

Press

Enter the number of the file to create.

Press

Esc

to create a structured text file.

to return to

Program
Directory

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

iii

Structured Text User Manual

Table of Contents
Structured Text User Manual

Chapter 1
Chapter Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Structured Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Writing Structured Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Rules for Writing Structured Text . . . . . . . . . . . . . . . . . . . . . . . . . . .

1-1
1-1
1-1
1-3
1-6

Chapter 2
Chapter Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Variable Assignment (:=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Non-Retentive Bit Assignments (:=) . . . . . . . . . . . . . . . . . . . . . . . . .
Retentive Bit Assignments (RETAIN) . . . . . . . . . . . . . . . . . . . . . . .
IF-ELSIF-ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
WHILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REPEAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
EXIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ladder Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Memory Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2-1
2-2
2-2
2-3
2-4
2-5
2-6
2-7
2-8
2-9
2-10
2-10
2-12

Using the Structured


Text Editor

Chapter 3
Chapter Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Structured Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Configuring the Structured Text Editor . . . . . . . . . . . . . . . . . . . . . . .
Defining Addresses and Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . .
Entering Structured Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Editing Structured Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Documentation Reports . . . . . . . . . . . . . . . . . . . . . . . . . . .

3-1
3-1
3-2
3-3
3-5
3-7
3-10

Monitoring Structured Text

Chapter 4
Chapter Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using PowerText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Configurable Data Monitor . . . . . . . . . . . . . . . . . . . . . . .

4-1
4-1
4-4

Writing Structured Text

Structured Text Constructs

iv
Structured Text User Manual

Table of Contents
Structured Text User Manual

Application Example

Instruction Reference

ASCII Structured Text


Programming Example

Appendix A
Appendix Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Programming a Free Running Timer . . . . . . . . . . . . . . . . . . . . . . . . .
Programming a Sort Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A-1
A-1
A-2
A-2

Appendix B
Instruction Operands and Valid Data Types . . . . . . . . . . . . . . . . . . .

B-1

Appendix C
ASCII Structured Text Processor Memory File Example . . . . . . . . .
Structured Text Syntax for Above ASCII File . . . . . . . . . . . . . . . . .

C-1
C-9

v
Structured Text User Manual

Chapter

Writing Structured Text

Chapter Objectives

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).

Using Structured Text

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.

Installing the Software

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.

1.

Turn on the computer.

2.

When the DOS prompt appears, insert the structured text disk into the
disk drive. Type:
A:

a: is the drive where you insert the disk.

Return

INSTALL C:

Return

c: is any destination hard-disk for the


programming software.

1-1

Structured Text User Manual

Chapter 1
Writing Structured Text

You see:

Allen-Bradley Company, Inc., Copyright 1995, All rights reserved.

Press any key

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.
* ****************************************************************** *
*
*
Press Any Key to Start Installation
*
*
*
*
Contents:
PLC-5 Prog Structured Text Programming Option
Catalog Number: 6203-ST5
Part Number:
XXXXXX-XX
Release Number: 1.1
Quantity 1 Disk
Company Name: Allen-Bradley
Address: 747 Alpha Drive
***********************************************************************
: Highland Hts OH 44143
Serial Number:: XXOXXOXX

Press

Return
Press ENTER to continue with the installation

3
Enter your company name and address.
You can find the serial number on the front
of the product box. Format is AA0AA0AA.

When you are finished, press

Contents:
PLC-5 Prog Structured Text Programming Option
Catalog Number: 6203-ST5
Product Registration Information
Part Number:
XXXXXX-XX
Release Number:
2.0 Name:
Quantity 1 Disk
Company
Address:
:
Serial Number:

F9
Instructions
Enter product registration info and press F9

1-2

Structured Text User Manual

Chapter 1
Writing Structured Text

After you enter the product registration, you see:

The percent completion bar


advances as the installation
progresses.

Contents:
Catalog Number:
Part Number:
Release Number:

PLC-5 Prog Structured Text Programming Option


6203-ST5
XXXXXXXXX
1.1
Quantity x Disks
Status

98% Complete

The file names display as they


are copied to your hard disk.

0%

25%

50%

75%

100%

Copy UPD.EXE to C:\IPDS\UPD.EXE

After structured text is installed,


press Enter

Instructions

The File Copy portion of Install is Complete: Press ENTER

Writing Structured Text

To write structured text, you need to understand the following definitions:

construct 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;
operand any standard PLC-5 operand address. An operand can also be a symbol.
For example, N7:0.
bit operand any standard PLC-5 bit operand address. For example, B3/0.
immediate 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.

1-3

Structured Text User Manual

Chapter 1
Writing Structured Text

math expression 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:

/
*
modulo (MOD)
SQR
FRD
TOD
NOT
NEG

add
subtract
divide
multiply
returns the remainder of an integer divide
square root
convert from BCD
convert to BCD
logical NOT
negate

LN
LOG
DEG
RAD
SIN
COS
TAN
ASN
ACS
ATN

natural log
log to the base 10
degree (convert radians to degrees)
radian (convert degrees to radians)
sine
cosine
tangent
arc sine
arc cosine
arc tangent

compare expression 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

input instruction 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).

1-4

Structured Text User Manual

Chapter 1
Writing Structured Text

input expression 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
output instruction 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
whitespace one or more tabs, spaces, returns, and/or blank lines. Use whitespace to
make your program more readable.

1-5

Structured Text User Manual

Chapter 1
Writing Structured Text

Rules for Writing


Structured Text

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 character indicates 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 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.

1-6

Structured Text User Manual

Chapter 1
Writing Structured Text

When writing or entering a program, the following are equivalent


and interchangeable:
This Is:

Equivalent and Interchangeable With:

{
ELSIF
AND (boolean)
OR (boolean)
} (no semicolon
required)

DO, THEN, OF
ELSE_IF, ELSEIF
&&, &
||
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 ;

IF (N7:0 = 1) {
Structured Text
else_if (N7:3 = 27) {
Structured Text
ELSE
Structured Text
}

(Code to do one of three things using


standard nomenclature.)

(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

1-7

Structured Text User Manual

Chapter 1
Writing Structured Text

The structured text compiler handles spaces around constructs as


described in the example below.
Blank Line 1
Construct
Construct

no line

End
End Construct

no line

Blank Line 2
XX := YY;
Blank Line 3
XX := YY;
Blank Line 4

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.

1-8

Structured Text User Manual

Chapter

Structured Text Constructs

Chapter Objectives

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
make bit assignments (non-retentive)

variable assignment

2-2

non-retentive bit
assignment
retentive bit
assignment
IF-ELSIF-ELSE
CASE

2-2

repeat a section of code a specified


number of times
repeat a section of code as long as an
input condition is true
repeat a section of code until an input
condition becomes true
exit an iterative command (FOR, WHILE,
or REPEAT) before it reaches the normal
termination condition

FOR

2-6

WHILE

2-7

REPEAT

2-8

EXIT

2-9

perform no function, treated as


whitespace
call PLC-5 input instruction or output
instruction as functions

;;

2-10

ladder functions

2-10

make bit assignments (retentive)


conditionally execute a section of code
conditionally execute a section of code
based on the value of a math expression
or operand

2-3
2-4
2-5

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.

2-1

Structured Text User Manual

Chapter 2
Structured Text Constructs

Variable Assignment (:=)

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

N30:0
N30:1 := N30:0

Destination

Non-Retentive Bit
Assignments (:=)

N30:1

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;

B3/0 := 0;

B3/0 is set to the value of 0.

bit_operand := 1;

N7:0/0 := 1;

N7:0/0 is set to the value of 1.

bit_operand := bit_operand;

O:0/0 := N7:0/0;

bit_operand := compare_expr;

B3:0/11 := N7:1 <


N7:2;

O:0/0 is set to the value of N7:0/0, 1 or 0.

If the Compare The Assignment


Expression Is: Value Is:
true
false

1
0

2-2

Structured Text User Manual

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.

Chapter 2
Structured Text Constructs

Retentive Bit Assignments


(RETAIN)

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);

B3/0 := RETAIN (0);

B3:0 is set to 0.

bit_operand := RETAIN (1);

N7:0/0 := RETAIN (1);

N7:0/0 is set to 1.

bit_operand := RETAIN (bit operand);

O:0/0 := RETAIN (N7:0/0);

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.

N7:0/0 := RETAIN (N7:1 < N7:2);

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.

bit_operand := RETAIN (compare expression);

If the Compare
Expression Is:

The Assignment
Value Is:

true
false

1
0

2-3

Structured Text User Manual

Chapter 2
Structured Text Constructs

IF-ELSIF-ELSE

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.

code section

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.

Format:

Examples:

IF input expression THEN


Structured Text
END_IF;

IF I:000/0 THEN
N7:0 := N7:1 + N7:2;
END_IF ;

IF input expression THEN


Structured Text
ELSE
Structured Text
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 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 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;

2-4

Structured Text User Manual

nested IF

end of nested IF

Chapter 2
Structured Text Constructs

CASE

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.

single value
list of values
range of values
mixed list and range
default case

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,9:
N7:1 :=
2..4:
N7:1 :=
10,5..8:
N7:1 :=
ELSE
N7:1 :=
END_CASE;

IF N7:0 = 0
1;
2;

IF N7:0 = 1 or 9
IF 2 <= N7:0 <= 4

3
IF N7:0 = 10 OR 5 <= N7:0 <= 8
4;
5;

Default

CASE F8:0 OF
recommended range check
5.001 .. 5.625:
N7:1 := 3;
N7:0 , N7:5 .. F8:5 :
mixed mode
N7:1 := 4;
ELSE
N7:1 := 5;
Default
END_CASE;

2-5

Structured Text User Manual

Chapter 2
Structured Text Constructs

FOR

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.

code inside the loop

default: increment by 1

Format:

Examples:

FOR operand := initial TO terminal BY increment DO


Structured Text
END_FOR;

FOR N7:0 := 10 TO 0 BY -1 DO
N7:4 := N7:4 + 1;
END_FOR;

FOR operand := initial TO terminal DO


Structured Text
END_FOR;

FOR N7:0 := 0 To 10 DO
N7:1 := N7:1 + 1;
END_FOR;

If no increment value, default

= 1.

2-6

Structured Text User Manual

Chapter 2
Structured Text Constructs

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.

WHILE

code inside the loop

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;
N7:0 increments by 1
END_WHILE;
as long as the input conditions
are true

2-7

Structured Text User Manual

Chapter 2
Structured Text Constructs

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;
WHILE (N7:0/0 = 1) DO
N7:3 := (N7:1 + N7:2);
IF (N7:19/2) THEN
EXIT;
END_IF;
END_WHILE;

EXIT construct

REPEAT

code inside the loop

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.

2-8

Structured Text User Manual

Chapter 2
Structured Text Constructs

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;
REPEAT
N7:0 := N7:0 +1;
IF (B3:0/0 = 1 ) THEN
EXIT;
END_IF;
UNTIL (N7:0 > (N7:10 /10)
END_REPEAT;

EXIT construct

EXIT

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 the WHILE loop early
EXIT;
END_IF;
END_WHILE;
execution continues here
N7:11 := N7:12 + 1;
END_FOR;

2-9

Structured Text User Manual

Chapter 2
Structured Text Constructs

;;

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.

Ladder Functions

Format:

Examples:

;;

IF N7:0/0 THEN
;;
no effect on program scan
ELSE
time
N7:2 := N7:5 +10;
END_IF;

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,...);

FAL(R6:0,10,0,ALL,#N7:0,#N7:1+#N7:2);

input expression output instruction (operand list);

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.)

2-10

Structured Text User Manual

Chapter 2
Structured Text Constructs

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
OTL, OTU
CPT
FOR, NXT, BRK
AND, OR

2-2 (Non-Retentive Bit Assignments)


2-3 (Retentive Bit Assignments)
2-2 (Variable Assignment)
2-6 (FOR)
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.
2-11

Structured Text User Manual

Chapter 2
Structured Text Constructs

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.

Memory Requirements

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
ELSIF
ELSE

input expressions + 9 words


input expressions + 9 words
2 words

END_IF
END_FOR
END_WHILE
END_REPEAT
END_CASE

2 words
2 words
2 words
2 words
2 words

WHILE
REPEAT
EXIT
EMPTY

input expressions + 16 words


input expressions + 15 words
1 word
0 words

CASE
case item
discrete
range

expressions = 14 words
10 to 12 words
(3 to 6 words) * number of items
6 to 12 words

2-12

Structured Text User Manual

Chapter

Using the Structured Text Editor

Chapter Objectives

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


Configuring the SFC editor for
structured text
Entering structured text
Editing structured text
Creating documentation reports

3-1
3-2
3-5
3-7
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.

Creating a Structured
Text File

To create a structured text file, follow the steps on the left:

Program
Directory

+= 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
|
|
|
+==============================================================================+

Proc Functions
F1

Create File
F6

Press a function key.


>
Rem Prog

PLC5/40 Series C Revision C


Create
Create
Lad Fl
SFC Fl
F6
F7

5/40 File EXPSFC


Create
STxt Fl
F8

Create STxt Fl
F8

Press

to create a structured text file.

Enter the number of the file to create.

Press

Esc

to return to

Program
Directory

3-1

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

After you create the file, you can enter your structured text. Follow the
steps on the left:
Program
Directory

Empty Structured Text File

cursor to
structured text file

Monitor File
F8

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

Configuring the Structured


Text Editor

SFC
Main Menu

General
Utility
F7

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:
+= Action/Condition Window Configuration ======================================+
| 10
50
|
| Action/Condition
Comment
|
| ..........
..................................................
|
|
|
| F3 Address Display: Suppress Symbol
F4 Act/Cnd Dsp: Show Structured Text |
+==============================================================================+
START
+++
+++
END

Configure
Display
F2

Act/Cnd
Window
F8

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

3-2

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

Defining Addresses
and Symbols

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
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
Display address symbols

[F1] - Act/Cond Fld


Adjusting the Action/Condition field automatically
adjusts the Comment field size.
[F2] - Comment Field
Adjusting the Comment field automatically adjusts
the Action/Condition field size.
[F3] - Address Display: Display/Suppress Symbol

Suppress address symbols

ke toggles
les between
e ee displaying
s la
ess
Thiss key
or ssuppressing
address symbols. The default is to display symbols.

Display the first line of structured text

[F4] - Act/Cnd Display

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:

3-3

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

To access the documentation database:

To access the data table monitor:

6200
Main Menu
Online Prog
F1

6200
Main Menu

Offline Prog
or

F3

Program
Directory

Cursor to a
structured text file or
enter file number

Online Prog
F1

Offline Prog
or

F3

Program
Directory

Cursor to a
structured text file or
enter file number

Monitor File

Monitor File

F8

F8

Edit
DBASE

Data
Monitor

F5

F8

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.

3-4

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

Entering Structured Text

6200
Main Menu
Online Prog
F1

Offline Prog
or

Cursor to a
structured text file or
enter file number

F8

Edit

IF (!T4:0.DN) THEN
TON (T4:0, 0.01, 100, 0);
ELSIF (T4:0.DN) THEN
RES (T4:0);
END_IF;

F3

Program
Directory

Monitor File

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:

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

If you havent entered logic (structured text) into the program file yet,
this window is blank.

F10

3-5

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

To enter structured text as a step action or transition condition in an SFC,


follow the steps on the left:
SFC
Main Menu

+= Action Display for Step: MIXER==============================================+


| ActionName QL Action
Comment
|
++
| ValveChk
N 2 (ladder)
|
|
|
|
|
|
|
+==============================================================================+

Edit
F10

START
+++
+=====+=====+
# MIXER
#
+=====+=====+
+
|
|
+++

SFC
Edit Selections

Append
Step/Trn

Insert
Step/Trn
or

F3

Press a function key.


EDIT 2:(0,0) >
Rem Prog
SFCFrc:Disabled

F4

Press the appropriate function key to choose


to create an action or a transition. See below.

Step
Trans
Actions
*
F1
F2

PLC5/40 Ser C
Step
Timer
F4

Rev C
Step
Name
F8

5/40 Addr 43 DRILL1


Trans
Name
F9

Step Actions

a If you press

F1

Rem Prog

Choose or create a structured text file, then cursor to


the Action Text field and then press Edit Text

SFCFrc:Disabled

PLC-5/40 Ser C Rev C

Select

Edit

Append

Insert

Remove

File

Text

Action

Action

Action

F1

F2

F3

F4

5/40 Addr 43 DRILL1

F6

F2

Trans

b If you press

F2

Rem Prog

Choose or create a structured text file, then cursor to


the Condition Text field and then press Edit Text

SFCFrc:Disabled

PLC-5/40 Ser C Rev C

Select Edit

Copy

Remove

File

Cond

Cond

F1

Text
F2

F3

F2

3-6

Structured Text User Manual

F6

5/40 Addr 43 DRILL1

Chapter 3
Using the Structured Text Editor

Editing Structured Text

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).

Within an SFC

MCP or Subroutine

SFC
Main Menu

Ladder Editor
Main Menu
Online Prog
F1

Edit

Offline Prog
or

F3

F10

SFC
Main Menu

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;

SFC
Edit Selections
Prog Dir
F4

Modify Stp/Trn
F5

Cursor to a
structured text file or
enter file number
Step Actions
F1

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

Trans

or

F2

Monitor File
F8

Cursor to the Action or


Condition Text field
Edit
Edit Text
F2

F10

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.

3-7

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

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.

TIP

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.
To select the structured
text to save to disk file:

To copy the selected structured


text to disk file:

ST Editor

ST Editor

Advanced Editing

Cut

F7

F2

Move the cursor to the


beginning of the area
you want to save.

Copy to Disk

Select
F1

Move the cursor to the


end of the area you
want to save.

3-8

Structured Text User Manual

F7

with selected text


highlighted

Chapter 3
Using the Structured Text Editor

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.

3-9

Structured Text User Manual

Chapter 3
Using the Structured Text Editor

Creating Documentation
Reports

6200
Main Menu

Reports
F8

Create Offline
F3

Create Online
or

F1

select Structured Text


Listing as the report to
generate by cursoring to it and
pressing Toggle Report
F3

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:
+========================= 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
Reports
All
F1
F2

Toggle
Report
F3

Reset Report General Define


Reports Options Options
Dir
F4
F5
F6
F7

Report Options
F5

Select the range of files


to include in the report.

Create Reports
F1

3-10

Structured Text User Manual

Title
F8

Save
Config
F9

current
processor
memory
file

Chapter 3
Using the Structured Text Editor

The status screen (shown below) advises you of the progress of


the report.

Proc File:
Output:
Phase:

Abort Utility

You can abort this utility with

F3

+========================================+
|
ALLENBRADLEY COMPANY
|
|
6200 SERIES SOFTWARE
|
|
PLC5 DOCUMENTATION SOFTWARE
|
+========================================+
LIMIT
Report:
Structured Text Listing
LIMIT.TXR
Config:
Files 1 999
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

For more information about reports, including how to print a report, see the
PLC-5 Configuration and Maintenance Manual, publication 6200-6.4.6.
To View the Report:
6200
Main Menu

Reports
F8

Print/View
F8

Cursor to the processor


name you want

Tue Jan 3, 1995


Structured Text Listing Report

PLC5/40

Addr 68

Page 1
File 2

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;
R6:6.DN AND

ONS (B3/4) MOV (ST15:3.LEN, N17:85);

Select
F3

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.

View File
F10

3-11

Structured Text User Manual

Chapter

Monitoring Structured Text

Chapter Objectives

Use this chapter to learn how to use the Structured Text View window and
the PowerText feature as monitoring tools for structured text.

Using PowerText

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.

Program
Directory

Empty Structured Text File

cursor to
structured text file

Monitor File
F8

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

TIP

When monitoring a structured text file, press


displaying or suppressing documentation.

Alt

F7

to toggle between
4-1

Structured Text User Manual

Chapter 4
Monitoring Structured Text

MCP or Subroutine

Within an SFC:
SFC
Main Menu

6200
Main Menu

Online Prog
F1

If you have not configured the Action Window to


appear on the screen, press Alt
A

Offline Prog
or

F3

Alt

Program
Directory

Cursor to a
structured text file or
enter file number
If you have not created a structured text file,
you need to do so. See page 3-1.

(a cursor appears in the action window)

Cursor to the structured text


field and press Enter

Monitor File
F8

PowerText values

IF (LIMIT_SW1 {F ON} AND BOXPRESENT) THEN


GATE1 := OPEN;
GATE2 := CLOSE;
ELSIF ((LIMIT_SW2 OR (WEIGHT {
287} <> SETPOINT {
GATE1 := CLOSE;
GATE2 := CLOSE;
ELSIF (LIMIT_SW3 XOR LIMIT_SW4) THEN
GATE1 := CLOSE;
GATE2 := CLOSE;
ELSE
GATE1 := OPEN;
GATE2 := CLOSE;
END_IF;

289}))) THEN

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 you havent entered logic (structured text) into the program file yet,
this window says only: Empty Structured Text File

If the processor is not in Run mode, the view window displays the
structured text that you entered.

4-2

Structured Text User Manual

Chapter 4
Monitoring Structured Text

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:
6200
Main Menu

Software
Config

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.

F6

Color
Selection
F3

+========================= 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
DfltClr LastClr
F1
F2

Bakgrnd Forgrnd
Color
Color
F5
F6

Save
Config
F9

If you want to change the color mode, press this key

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

4-3

Structured Text User Manual

Chapter 4
Monitoring Structured Text

If You Want to:

Press this Key:

Toggle between a black and white display or a display that uses the
default colors.
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.

[F1] Monochrome/Default Color

Toggle through the eight available color choices for backgrounds.


Toggle through the 16 available color choices for foregrounds.
Save the color options to disk.
Use the color selections you specify for this editing session only.

[F5] Background Color


[F6] Foreground Color
[F9] Save Configuration
[Enter]
[Esc]
[Alt-U]

Cancel any changes you made on this screen for the current editing session.

Creating a Configurable
Data Monitor

[F2] Recall Last Color

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));

4-4

Structured Text User Manual

Chapter 4
Monitoring Structured Text

3.

Accept the edits and change the processor mode to Run. The
PowerText values update. For example:

IF (0 = 1) THEN
FLOW_RATE1{
N10:0{

326.07} := FLOW_RATE2{

4095} := N10:1{

119.923};

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
decimal
float
ASCII
Binary (word)

6
4
14
6
19

4-5

Structured Text User Manual

Appendix

Application Examples

Appendix Objectives

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.

Programming a Free
Running Timer

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
T4:0

TIMER ON DELAY

LADDER:
DN

STRUCTURED TEXT:

TON
EN

Timer

T4:0

Time base

0.01

Preset

100

Accum

DN

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.
A-1

Structured Text User Manual

Appendix A
Application Examples

Programming a Sort Routine 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;

Debugging Programs

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.
A-2

Structured Text User Manual

Appendix

Ladder Functions Reference

Appendix Objectives

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:
immediate
(program constant)
integer
float

block transfer
PID
string
SFC status

Instruction Operands and


Valid Data Types

Accepts:
any value between -32768 and 32767
any integer data type: integer, timer, counter, status, bit, input, output,
ASCII, BCD, control (e.g. N7:0, C4:0, etc.)
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.
any block transfer data type (e.g. BT14:0) or integer data type (e.g. N7:0)
any PID data type (e.g. PD16:0) or integer data type (e.g. N7:0)
any string data type (e.g. ST12:0)
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.

B-1

Structured Text User Manual

Appendix B
Ladder Functions Reference

Table B.A
Programming Instructions and Operands
Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

ASCII Test Buffer for Line

channel

immediate, 04 integer

yes

ABL (channel, control, characters)

control

control address

characters

integer

structured-text syntax

ABL

(this is a display only field in


ladder logic)
ACB

ASCII Number of Characters in Buffer

channel

immediate, integer

ACB (channel, control, characters)

control

control address

characters

integer

yes

yes

(this is a display only field in


ladder logic)
ACI

ACN

ACS

ASCII String to Integer

source

string

ACI (source, destination)

destination

integer

ASCII String Concatenate

source A

string

ACN (source_A, source_B, destination)

source B

string

Arc Cosine

source

immediate, float (in radians),


integer

destination

float (in radians), integer

ADD

source A

immediate, integer, float

ADD (source_A, source_B, destination)

source B

immediate, integer, float

destination

integer, float

String Extract

source

string

AEX (source, index, number,


d ti ti )
destination)

index

immediate, 0-82 integer

number

immediate, 0-82 integer

destination

string

ACS (source, destination)

ADD

AEX

AFI

Always False

no

no

no

no

no

no

AFI

AHL

AIC

ASCII Set/Reset Handshake Lines

channel

immediate, 0-4 integer

handshake AND mask

immediate, Hex integer

handshake OR mask

immediate, Hex integer

control

control

ASCII Integer to String

source

immediate, integer

AIC (source, destination)

destination

string

B-2

Structured Text User Manual

yes

no

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

ASCII Read Characters

channel

immediate, 0-4 integer

yes

ARD (channel, destination, control,


string_length,
t i
l
th characters_read)
h
t
d)

destination

string

control

control address

string length

0 82

characters read

integer

structured-text syntax

ARD

(this is a display only field in


ladder logic)
ARL

ASCII Read Line

channel

immediate, 0-4 integer

ARL (channel, destination, control,


string_length,
t i
l
th characters_read)
h
t
d)

destination

string

control

control address

string length

0 82

characters read

integer

yes

(this is a display only field in


ladder logic)
ASC

ASN

ASR

ATN

AVE

AWA

ASCII String Search

source

string

ASC (source, index, search, result)

index

immediate, 0-4 integer

search

string

result

integer

Arc Sine

source

immediate, float (in radians)

ASN (source, destination)

destination

float (in radians)

ASCII String Compare

source A

string

ASR (source_A, source_B)

source B

string

Arc Tangent

source

immediate, float (in radians)

ATN (source, destination)

destination

float (in radians)

Average File

file

integer, float

AVE (fil
(file, d
destination,
i
i
control,
l
length, position)

destination

integer, float

control

control address

length

1 1000

position

0 999

ASCII Write with Append

channel

immediate, 0-4 integer

AWA (channel, source, control,


string_length,
t i
l
th characters_sent)
h
t
t)

source

string

control

control address

string length

0 82

characters sent

integer

no

no

no

no

yes

yes

(this is a display only field in


ladder logic)

B-3

Structured Text User Manual

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

ASCII Write

channel

immediate, integer

yes

AWT (channel, source, control,


string_length,
t i
l
th characters_sent)
h
t
t)

source

string

control

control address

length

0 82

characters sent

integer

structured-text syntax

AWT

(this is a display only field in


ladder logic)
BSL

BSR

BTD

Bit Shift Left

file

binary

BSL (file, control, bit_address,


length)

control

control address

bit address

bit

length

1 16000 (length in bits)

Bit Shift Right

file

binary

BSR (file, control, bit_address,


length)

control

control address

bit address

bit

length

1 16000 (length in bits)

Bit Distribute

source

immediate, integer

BTD (source, source_bit, destination,


destination bit, length)
destination_bit,

source bit

immediate, (0 15) integer

destination

integer

destination bit

immediate (0 15)

length

immediate (1 16)

B-4

Structured Text User Manual

yes

yes

no

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

Block Transfer Read

rack

00-277 octal

yes

BTR (rack, group, module,


control block data
control_block,
data_file,
file BT
BT_length,
length
continuous,
, BT_timeout)
_
)

group

0-7

module

0-1

control block

BT address

structured-text syntax

BTR

integer address

BTW

data file

integer

length

0, 1-64

continuous

YES, NO

Block Transfer Write

rack

00-277 octal

BTW (rack, group, module,


control block data
control_block,
data_file,
file BT
BT_length,
length
continuous,
, BT_timeout)
_
)

group

0-7

module

0-1

control block

BT address

yes

integer address

CLR

Clear

data file

integer

length

0, 1-64

continuous

YES, NO

destination

integer, float

no

CLR destination

CMP

Compare

expression, relative
expression using values or
expression, expression addresses with evaluators

no

File Copy

source

array

no

COP (source, destination, length)

destination

array

length

immediate (1 1000)

Cosine

source

immediate, float (in radians)

COS (source, destination)

destination

float (in radians)

Compute

destination

integer, float

CPT (destination, expression)

math expression

expression using values or


immediate integer, float
addresses with evaluators

Count Down

counter

counter

CTD (counter, preset, accumulated)

PRE

32768 +32767

ACC

32768 +32767

CMP (expression) output instruction

this instruction must be followed by an output instruction


to compile correctly
COP

COS

CPT

CTD

no

no

yes

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.

B-5

Structured Text User Manual

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

Count Up

counter

counter

yes

CTU (counter, preset, accumulated)

PRE

32768 +32767

ACC

32768 +32767

Diagnostic Detect

source array

binary

DDT (source, reference, result,


compare control length,
compare_control,
length position,
position
result_control,
position)
_
, length,
g , p
)

reference array

binary

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

Degree (convert radians to degrees)

source

immediate, float (in radians)

DEG (source, destination)

destination

immediate, float (in degrees)

Divide

source A

immediate, integer, float

DIV (source_A, source_B, destination)

source B

immediate, integer, float

destination

integer, float

Data Transitional

source

immediate, integer

(source mask,
mask reference) output
DTR (source,
instruction

mask

immediate, integer

structured-text syntax

CTU

DDT

DEG

DIV

DTR

thiss instruction
must
s
s bee followed
ll e by an
a output instruction
s
reference
to compile correctly
EOT

yes

no

no

no

integer

End of Transition

no

EOT

EQU

source A

immediate, integer, float

source B

immediate, integer, float

File Arithmetic/Logical

control

control address

FAL (control, length, position, mode,


destination expression)
destination,

length

1 1000

position

0 999

mode

(INC, 11000, ALL)

destination

integer, float

expression

indexed math instruction

Equal

no

EQU (source_A, source_B) output


instruction

this instruction must be followed by an output instruction


to compile correctly
FAL

B-6

Structured Text User Manual

yes

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

File Bit Compare

source array

binary

yes

FBC (source, reference, result,


compare control length,
compare_control,
length position,
position
result_control,
position)
_
, length,
g , p
)

reference array

binary

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

FIFO Load

source

immediate, indexed, integer

FFL (source, FIFO, control, length,


position)

FIFO array

indexed, integer

control

control address

length

1 1000

position

0 999

FIFO Unload

FIFO array

indexed, integer

FFU (FIFO, destination, control,


length position)
length,

destination

indexed, integer

control

control address

length

1 1000

position

0 999

Fill File

source

immediate, integer, float

FLL (source, destination, length)

destination array

array

length

immediate (1 1000)

From BCD

source

immediate, integer

FRD (source, destination)

destination

integer

File Search and Compare

control

control structure address

FSC (control, length, position, mode,


expression) output instruction

length

1 1000

structured-text syntax

FBC

FFL

FFU

FLL

FRD

FSC

position
thiss instruction
s
must
s bee followed
ll e by aan output instruction
s
to compile correctly
mode

GEQ

Greater Than or Equal To

yes

yes

no

no

yes

0 999
immediate, integer (0, INC,
11000, ALL)

expression

indexed math instruction

source A

immediate, integer, float

source B

immediate, integer, float

no

GEQ (source_a, source_B) output


instruction

this instruction must be followed by an output instruction


to compile correctly

B-7

Structured Text User Manual

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

source A

immediate, integer, float

no

source B

immediate, integer, float

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

O (output word)

immediate, integer
PLC-5/40, 40L: 000-157
PLC-5/60, 60L, 80: 000-237

no

Jump to Subroutine

ladder file number

immediate (2 999), integer

no

JSR (file_number,
number_of_input_parameters,
input parameter list
input_parameter_list,
_p
_
)
return_parameter_list)

number of input
parameters

immediate, integer

input parameter list

immediate, integer, float

return parameter list

integer, float

source A

immediate, integer, float

source B

immediate, integer, float

source A

immediate, integer, float

source B

immediate, integer, float

Limit

low limit

immediate, integer, float

(low limit test,


test high_limit)
high limit)
LIM (low_limit,
output instruction

test

immediate, integer, float

structured-text syntax

GRT

Greater Than
GRT (source_a, source_B) output
instruction

this instruction must be followed by an output instruction


to compile correctly
IIN

Immediate Input
IIN input_word

IOT

Immediate Output
IOT output_word

JSR

LEQ

Less Than or Equal To

no

LEQ (source_a, source_B) output


instruction

this instruction must be followed by an output instruction


to compile correctly
LES

Less Than

no

LES (source_a, source_B) output


instruction

this instruction must be followed by an output instruction


to compile correctly
LIM

thiss instruction
must
s
s bee followed
ll e by an
a output instruction
s
high limit
to compile correctly
LFL

immediate, integer, float

LIFO Load

source

immediate, indexed, integer

LFL (source, LIFO, control, length,


position)

LIFO array

indexed, integer

control

control address

length

1 1000

position

0 999

B-8

Structured Text User Manual

no

yes

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

LIFO Unload

LIFO array

indexed, integer

yes

LFU (LIFO, destination, control,


length position)
length,

destination

indexed, integer

control

control address

length

1 1000

position

0 999

Natural Log

source

immediate, integer, float

LN (source, destination)

destination

float

Log to the Base 10

source

immediate, integer, float

LOG (source, destination)

destination

float

Mask Compare Equal To

source operand

immediate, integer

MEQ (source,
(source mask,
mask compare) output
instruction

source mask

immediate, integer

structured-text syntax

LFU

LN

LOG

MEQ

thiss instruction
s
must
s bee followed
ll e by an
a output instruction
s
compare operand
to compile correctly
MOV

MUL

MVM

NEG

NEQ

no

no

no

immediate, integer

Move

source

immediate, integer, float

MOV (source, destination)

destination

integer, float

Multiply

source A

immediate, integer, float

MUL (source_A, source_B, destination)

source B

immediate, integer, float

destination

integer, float

Masked Move

source operand

immediate, integer

MVM (source, mask, destination)

source mask

immediate, Hex integer

destination

integer

Negate

source

immediate, integer, float

NEG (source, destination)

destination

integer, float

Not Equal To

source A

immediate, integer, float

source B

immediate, integer, float

Logical NOT

source

immediate, integer

NOT (source, destination)

destination

integer

One Shot

source bit

bit

no

no

no

no

no

NEQ (source_A, source_B) output


instruction

this instruction must be followed by an output instruction


to compile correctly
NOT

ONS

no

yes

ONS bit output instruction

this instruction must be followed by an output instruction


to compile correctly

B-9

Structured Text User Manual

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

One Shot Falling

storage bit

bit

yes

OSF (storage
bit output
bit
(storage_bit,
output_bit,
output_word) output instruction

output bit

immediate

structured-text syntax

OSF

thiss instruction
s
must
s bee followed
ll e by an
a output instruction
s
output word
to compile correctly
OSR

OTE

word

One Shot Rising

storage bit

bit

OSR (storage
(storage_bit,
bit output
output_bit,
bit
output_word) output instruction

output bit

immediate

yes

thiss instruction
s
must
s bee followed
ll e by an
a output instruction
s
output word
to compile correctly

word

Output Energize

destination bit

bit

no

destination bit

bit

no

destination bit

bit

no

PID

control

PD address

no

PID (control, process_variable,


tieback control_variable)
tieback,
control variable)

control

integer address

yes

process variable

integer

tieback

immediate, integer

control variable

integer

Radian (convert degrees to radians)

source

immediate, float (in degrees)

RAD (source, destination)

destination

float (in radians)

Timer/Counter Reset

address

timer, counter, or
control address

no

return parameter list

immediate, integer, float

no

Retentive Timer On

time base

immediate (0.01, 1.0)

yes

RTO (timer, time base, preset,


accumulated)

PRE

0 32767

ACC

0 32767

input parameter list

integer, float

no

SFC reset

SFC file number

immediate (1 999)

no

SFR (file_number, restart_at_step)

restart at step

immediate, integer

OTE bit

OTL

Output Latch
OTL bit

OTU

Output Unlatch
OTU bit

PID

RAD

RES

RES address

RET

Return

no

RET (return_parameter_list)

RTO

SBR

Subroutine
SBR (input_parameter_list)

SFR

This instruction requires periodic scans to be updated.

B-10

Structured Text User Manual

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

Sine

source

immediate, float (in radians)

no

SIN (source, destination)

destination

float (in radians)

Sequencer Input

file

integer, indexed

SQI (file, mask, source, control,


length, position) output instruction

mask

immediate, Hex indexed,


integer

structured-text syntax

SIN

SQI

thiss instruction
s
must
s bee followed
ll e by an
a output instruction
s
source
to compile
le correctly
e l
control

SQL

SQO

SQR

SRT

STD

SUB

no

immediate, indexed, integer


control address

length

1 1000

position

0 999

Sequencer Load

file

integer, indexed

SQL (file, source, control, length,


position)

source

immediate, indexed, integer

control

control address

length

1 1000

position

0 999

Sequencer Output

file

integer, indexed

SQO (file, mask, destination, control,


length position)
length,

mask

immediate, indexed, integer

destination

indexed, integer

control

control address

length

1 1000

position

0 999

Square Root

source

immediate, integer, float

SQR (source, destination)

destination

integer, float

Sort

sort file

integer, float

SRT (file, control, length, position)

control

control address

length

1 1000

position

0 999

Standard Deviation

standard deviation file

integer, float

STD (file, destination, control,


length position)
length,

destination

integer, float

control

control address

length

1 1000

position

0 999

Subtract

source A

immediate, integer, float

SUB (source_A, source_B, destination)

source B

immediate, integer, float

destination

integer, float

yes

yes

no

yes

yes

no

B-11

Structured Text User Manual

Appendix B
Ladder Functions Reference

Instruction Description

Operand

Valid Value

Require
False-to-True
Transition

Tangent

source

immediate, float (in radians)

no

TAN (source, destination)

destination

float (in radians)

To BCD

source

immediate, integer

TOD (source, destination)

destination

integer

Timer Off Delay

timer

timer

TOF (timer, time base, preset,


accumulated)

time base

immediate (0.01, 1.0)

PRE

0 32767

ACC

0 32767

Timer On Delay

timer

timer

TON (timer, time base, preset,


accumulated)

time base

immediate (0.01, 1.0)

PRE

0 32767

ACC

0 32767

structured-text syntax

TAN

TOD

TOF

TON

UID

User Interrupt Disable

no

yes: requires
a
truetofalse
transition
a s
to
e e e
execute
yes

no

UID

UIE

User Interrupt Enable

no

UIE

XIC

Examine On

source bit

bit

no

source bit

bit

no

X to the Power of Y

source A

immediate, integer

no

XPY (source_A, source_B, destination)

source B

immediate, integer

destination

integer

XIC bit output instruction

this instruction must be followed by an output instruction


to compile correctly
XIO

Examine Off
XIO bit output instruction

this instruction must be followed by an output instruction


to compile correctly
XPY

This instruction requires periodic scans to be updated.

B-12

Structured Text User Manual

Appendix

ASCII Structured Text Programming Example

ASCII Structured Text


Processor Memory
File 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
C-1

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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:
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


I/O CONTROL
10 17 I/O STATUS btx full
I/O CONTROL
20 27 I/O STATUS btx full
I/O CONTROL

00000000
reset:
00000000
reset:
00000000
reset:

rack fault
00000000
rack fault
00000000
rack fault
00000000

MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP
MCP

last:
last:
last:
last:
last:
last:
last:
last:
last:
last:
last:
last:
last:
last:
last:
last:

3
4
0
0
0
0
0
0
0
0
0
0
0
0
0
0

inhibit: 0000000000000000
prog file:
2
prog file:
3
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0
prog file:
0

max:
max:
max:
max:
max:
max:
max:
max:
max:
max:
max:
max:
max:
max:
max:
max:

00000000
inhibit: 00000000
00000000
inhibit: 00000000
00000000
inhibit: 00000000

9
281
0
0
0
0
0
0
0
0
0
0
0
0
0
0

%
0
2
6
0
0
0
0
0
2
0
0
0
0

8328 13797
0
23
23
53
0
0
0
0
0
0
0
0
0
0
3
9
0
0
0
0
0
0
0
0

DATA B3:1
0

0
2
17
0
0
0
0
0
3
0
0
0
0

2048
0
0
0
0
0
0
0
4
0
0
0
0

16
0
0
0
0
0
0
0
281
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

C-2

Structured Text User Manual

7
0
500
0
0
0
0
0
0
0
0
0

284
4
0
0
0
0
0
0
0
0
0
0

Appendix C
ASCII Structured Text Programming Example

DATA T4:3
0X026f
0X020a
0X02a5
0X02fa

2
2
34
2

0
0
0
0

DATA C5:2
0X0000
1
0X2000
100
0X0000
100

0
188
41

DATA R6:0
0X0000

DATA N7:50
0
1
0
0
20
0
2
500
0
0
17

1
0
0
1
0

DATA F8:25
1
0
0
0
2
1

0
0
0
0
0

3 1.7320508
0
0
0
0
0
0
5
3

0
0
0
0
0

0
0
0
7
0

601
0
0
31
0

5
0
0
0
1

5
0
0
0
1.5

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

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;
C-3

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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;

C-4

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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 :=
2 :
O:001/001 :=
3 :
O:001/002 :=
4 :
O:001/003 :=
5 :
O:001/004 :=
6 :
O:001/005 :=
7 :
O:001/006 :=
8 :
O:001/007 :=
9 :
O:001/000 :=

1;
1;
1;
1;
1;
1;
1;
1;
0;

C-5

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

10 :
O:001/001
11 :
O:001/002
12 :
O:001/003
13 :
O:001/004
14 :
O:001/005
15 :
O:001/006
16 :
O:001/007

:= 0;
:= 0;
:= 0;
:= 0;
:= 0;
:= 0;
:= 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 . . .
C-6

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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

C-7

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

CONFIG $4:0
CONFIG $4:1:411
1
1 32574
8224
8224
1
28207
7175 18954
0
0
0

3335
4097
7717
0

18954
8224
257
0

CONFIG $4:2:17
8192
6995 21826
1536
0
0

1024
781

CONFIG $4:3:17
8192
6995 21826
1536
0
0

7717
8224
260
0

1
8224
257
0

4097
8224
0
0

8224
1
0
0

8224
5121
0
0 . . .

0
243

0 28672
2560
0

50
1000

771

768

1024
781

0
243

0 28672
2560
0

50
1000

771

768

CONFIG $4:4:71
130
0
0
0
0
0

8
0
0

27
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
0
0
0
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

CONFIG $4:6:71
127
0
0
0
0
0

8
0
0

3264
0
0

0
0
0

24
0
0

1
0
0

24
0
0

0
0
0

0
0
0

CONFIG $4:7:71
127
0
0
0

8
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

C-8

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

Structured Text Syntax for


Above ASCII File

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;

C-9

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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;

C-10

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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 :=
2 :
O:001/001 :=
3 :
O:001/002 :=
4 :
O:001/003 :=
5 :
O:001/004 :=
6 :
O:001/005 :=
7 :
O:001/006 :=
8 :
O:001/007 :=
9 :
O:001/000 :=
10 :
O:001/001
11 :
O:001/002
12 :
O:001/003
13 :
O:001/004
14 :
O:001/005
15 :
O:001/006
16 :
O:001/007

1;
1;
1;
1;
1;
1;
1;
1;
0;

:= 0;
:= 0;
:= 0;
:= 0;
:= 0;
:= 0;
:= 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;

C-11

Structured Text User Manual

Appendix C
ASCII Structured Text Programming Example

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;

C-12

Structured Text User Manual

Index

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

Structured Text User Manual

Index

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

Structured Text User Manual

Index

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.

Structured Text User Manual

Customer Support

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)


Latin America (Milwaukee)
United Kingdom (Milton Keynes)
Europe (Amsterdam)
France (Paris)
Germany (Gruiten)
Italy (Milan)
Asia Pacific (Hong Kong)

519-623-1810
414-382-2000
44-908 838800
31-2975 43500
(33-1) 4778 1402
(49) 2104 6900
(39-2) 4830 0381
(852) 873-1342

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.

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

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