Programming with statement list © Festo Didactic – Training & Consulting

advertisement
Programming with statement list
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 1 / 56
Operands
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 2 / 56
Operands
• System identifiers are referred to as operands.
• Operands are elements within the controller that can be interrogated or manipulated using program instructions and operators.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 3 / 56
Absolute and symbolic operand
The software allows programs to be written using both absolute and symbolic operand.
• Examples of absolute operands are :
• I0.1
• T1
• O0.4
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 4 / 56
Absolute and symbolic operand
Examples of symbolic operands are :
• S1
• Timer
• Solenoid
• Y1
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 5 / 56
Single bit vs multi-bit operand
• Single bit operands (SBO) can be evaluated as true/false in the conditional part of the program sentence and can be set/reset in the
execution part of the program sentence.
• Multi bit operands (MBO) can be tested for value or compared to other multi bit operands in the conditional part of the sentence.
• In the executive part of the program sentence, they can be loaded with a value, decremented or incremented, or manipulated via a rich
set of arithmetic and logic operators.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 6 / 56
Single bit operand
Operand
STL Form
Syntax
Typical example
Input
I
In.n
IF I 2.0
Output
O
On.n
IF I 2.0
SET O2.3
Flag
F
Fn.n
IF F 7.16
RESET F9.3
Counter
C
Cn
IF C3
SET C5
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 7 / 56
Multi-bit operand
Operand
STL Form
Syntax
Typical example
Input word
IW
Iwn
IF (IW3=V 255)
Output word
OW
Own
IF (OW2=V80)
LOAD V128 TO OW3
Flag word
FW
FWn
IF (FW3=V220)
LOAD V21000 TO FW1
Function Unit
FU
FUn
IF (FU32=V16)
LOAD FU34 to R60
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 8 / 56
Multi-bit operand
Operand
STL Form
Syntax
Typical example
Timer Word
TW
TWn
IF (TW2<V 2000)
LOAD V1345 TO TW6
Timer Preselect
TP
TPn
IF (TP0<V20)
THEN LOAD V500 TO TP4
Counter Word
CW
CWn
IF (CW3<>V50)
THEN INC CW5
Counter Preselect
CP
CPn
IF (CP3=V555)
LOAD V67 to CP5
Register
R
RN
IF (R60=V21113)
LOAD (R53 + R45)
TO R32
Error Word
EW
EW
IF (EW AND V15)
LOAD V0 TO EW
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 9 / 56
STL program structure
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 10 / 56
STL program structure
• The STL language allows the programmer to solve control tasks using simple english statements to describe the desired operation of
the controller.
• The modular nature of the language allows the programmer to solve complex tasks in an efficient and self-documenting manner.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 11 / 56
STL program structure – element hierarchy
Program
Step
Sentence
Conditional part
Executive part
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 12 / 56
STL program structure – step inspection
• Although the use of the keyword STEP is optional, most STL programs will use the STEP instruction.
• The step instruction is used to mark the beginning of a logical block of program code.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 13 / 56
STL program structure – step inspection
• Each STL program may contain up to 255 discrete STEPS.
• Each step may contain one or more sentences.
• Each step may be assigned an optional label or name.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 14 / 56
STL program structure – step inspection
• A step label is only required if the respective step will later be assigned
as the destination of a jump instruction.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 15 / 56
STL program structure – sentences
• The sentence forms the most basic level of program organisation.
• Each sentence consists of a conditional part and an executive part.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 16 / 56
STL program structure – conditional part
• The conditional part serves to list one or more conditions which are to be evaluated at run time as being either true or false.
• This part usually begins with the if keyword and continues with one or more statements that describe the conditions to be evaluated.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 17 / 56
STL program structure – conditional part
• If the program conditions are evaluated as true, then any instructions programmed in the executive part of the sentence will be
performed.
• Examples are:
• If I0.1
• If I0.2 and I1.3
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 18 / 56
STL program structure – executive part
• It is the section of the sentence where the output is activated if the conditional part is evaluated as true.
• Examples are :
• THEN SET Y1
• THEN RESET Y2
• THEN JMP TO 10
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 19 / 56
STL program structure – step instruction
• Programs that do not use the STEP instruction can be processed in a parallel (scanning) fashion.
• Although this type of program execution may be well suited for solving certain types of control tasks, the STL language provides the
step instruction which allows programs to be divided into discrete sections (steps) which will be executed independently.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 20 / 56
STL program structure – step instruction
In its simplest form, a STEP includes at least one sentence.
STEP
IF
THEN
(label)
I1.0
SET
© Festo Didactic – Training & Consulting
If Input 1.0 is active
O2.4
then turn on output 2.4
and proceed to the next step.
PLC programming
20.12.03
No. 21 / 56
STL program structure – step instruction
• It is important to understand that the program will WAIT at this STEP until the conditions are true at which time the actions will be
performed.
• Only then will the program proceed to the next step.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 22 / 56
STL program structure – programming
Single sentence within a step
STEP Start
IF
THEN
STEP Stop
IF
THEN
© Festo Didactic – Training & Consulting
SET
- Label for STEP can be up to 8 alphanumeric
I0.0 - Conditional part
O0.0 - Execution part
RESET
I0.1
O0.0
PLC programming
20.12.03
No. 23 / 56
STL program structure – programming
• Single sentence within a step
• The program will execute the first step, STEP start.
• If the condition i0.0 is true, then it will execute the execution part (set O0.0) and proceed to next step, STEP stop
• If the condition is false, it will WAIT at STEP start.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 24 / 56
STL program structure – programming
Multiple sentence within a step
STEP Start
IF
THEN
SET
I0.0 - First Sentence
O0.0
IF
THEN
SET
I0.1 - Second Sentence
O0.1
SET
I0.2 - Third Sentence
O0.2
RESET
RESET
RESET
I0.1
O0.0
O0.1
O0.2
IF
THEN
STEP Stop
IF
THEN
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 25 / 56
STL program structure – programming
• Multiple sentence within a step
• Sequence of execution
• If the conditional part of the first sentence is true, then it will execute the execution part and proceed to second sentence
WITHOUT any exception
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 26 / 56
STL program structure – programming
• If the conditional part of the second sentence is true, then it will execute the execution part and proceed to third sentence WITHOUT
any exception. No waiting at second sentence.
• If the conditional part of the third sentence is true, then it will execute the execution part and proceed to next step. If not true, it will
proceed to first sentence, second sentence and it will loop within the step.
• Generally, only when the last sentence within the step is true, it will proceed to next step.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 27 / 56
STL program structure – programming
• If the conditions of a sentence are met, then the programmed actions are executed.
• If the conditions of the last (or only) sentence within a step are met, then the programmed actions are executed and the program
proceeds to the next step.
• If the conditions of a sentence are not met, then the program will move to the next step in the current step.
• If the conditions of the last (or only) sentence within a step are not met, then the program will return to the first sentence of the current
step.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 28 / 56
STL program structure – influencing program flow
In addition to the control structures inherent within the step instruction, several additional STL instructions are available which can be
used to influence the execution criteria of program steps and sentences.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 29 / 56
STL program structure – NOP instruction
• The NOP instruction may be used in either the conditional or executive part of a sentence.
• When used in the conditional part, the NOP instruction is always evaluated as true.
• The NOP instruction can be used to cause unconditional execution of a sentence.
IF
THEN
SET
© Festo Didactic – Training & Consulting
NOP
O1.0
This is always True
so Output 1.0 will always be turned
on when the program reaches here
PLC programming
20.12.03
No. 30 / 56
STL program structure – NOP instruction
Example of an NOP instruction
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 31 / 56
STEP 50
IF
THEN
SET
I10.0
O2.2
If input 1.0 is active
then turn on output 2.2
N
AND
RESET
I3.5
I4.4
O1.2
If input 3.5 is not active
and input 4.4 is active
then turn off output 1.2
IF
THEN
SET
T3
F0.0
If timer 3 is running
then set flag 0.0
IF
NOP
THEN
SET
IF
THEN
© Festo Didactic – Training & Consulting
O3.6
In any case, we make sure that the
last sentence will always be true
Turn on output 3.6, exit and go to
next step
PLC programming
20.12.03
No. 32 / 56
STL program structure – NOP instruction
• In step 50, several conditions were to be checked.
• If they were true, the appropriate actions were executed.
• However, regardless of whether any or all of the conditions were true, after being checked exactly one time the program would turn on
output 3.6 and proceed to the next step.
• We have forced the last sentence to be true via the nop instruction.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 33 / 56
STL program structure – NOP instruction
• The NOP instruction may also be used in the executive part. Here the NOP is equivalent to “do nothing”.
• It is often used when the program is to wait for certain conditions and then proceed to the next step.
IF
THEN
I3.2
NOP
© Festo Didactic – Training & Consulting
If Input 3.2 is Active
Do nothing and go to the next step.
PLC programming
20.12.03
No. 34 / 56
STL program structure – jump instruction
• The JMP instruction adds the ability of program branching to the STL language.
• As an example, we will modify the previous example used for NOP instruction.
• It would now be possible to test the conditions of each sentence and if true perform the programmed action and then jump to a
designated program step.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 35 / 56
STEP 50
IF
THEN
SET
JMP TO
I10.0
O2.2
70
If input 1.0 is active
then turn on output 2.2
and jump to step label 70
N
AND
RESET
JMP To
I3.5
I4.4
O1.2
6
If input 3.5 is not active
and input 4.4 is active
then turn off output 1.2
and jump to step label 70
IF
THEN
SET
T3
F0.0
If timer 3 is running
then set flag 0.0
IF
THEN
NOP
SET
O3.6
Always true, so ...
Turn on output 3.6, exit and go to next step
IF
THEN
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 36 / 56
STL program structure – jump instruction
• It can be seen that not only have we altered the program flow, but in addition have established priorities between the sentences.
• Sentences 2,3 and 4 will only have the possibility to be processed if sentence 1 is false and therefore not executed.
• If sentence 1 is executed, the program will jump to step 70 without ever processing any subsequent sentences in step 50.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 37 / 56
STL program structure – OTHRW instruction
• The OTHRW instruction is executed when the last encountered IF clause is evaluated as not true.
IF
I2.0
If Input 2.0 is active
THEN
SET
O3.3
Turn on output 3.3
OTHRW
RESET
O4.5
Otherwise turn on output 4.5
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 38 / 56
STL program structure – OTHRW instruction
STEP execution with OTHRW (Otherwise) instruction
STEP Start
IF
THEN
SET
OTHRW
RESET
- Label for STEP can be up to 8 alphanumeric
I0.0 - Conditional part
O0.0 - Execution part
O0.0 - Execution part
STEP Stop
IF
THEN
RESET
I0.1
O0.0
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 39 / 56
STL program structure – OTHRW instruction
• The program will execute the first step, STEP start.
• If the condition i0.0 is true, then it will execute the execution part (set O0.0) and proceed to next step, STEP stop. Otherwise (if not
true), it will execute the RESET O0.0 and proceed to next step, STEP stop
• In this case, there is no waiting at STEP start, either it executes SET O0.0 or RESET O0.0 and proceed to next step
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 40 / 56
STL instruction summary
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 41 / 56
STL instruction summary
The STL language provides the following instructions which allow both simple and complex tasks to be solved quickly and easily.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 42 / 56
STL instruction summary
AND
Performs a logical AND operation on single or Multibit operands and constants.
BID
Converts the contents of the Multibit Accumulator from Binary to BCD format.
CFM n
Begin Execution of a Function Module.
CMP n
Begin Execution of a Program Module.
CPL
Produces the two’s compliment of the contents of the multibit accumulator.
DEC
Decrements a Multibit Operand / Accumulator.
DEB
Converts the contents of the Multibit Accumulator from BCD to Binary format.
EXOR
Performs a logical EXOR operation on single or multi operands and constants.
IF
Keyword marking the beginning of the Conditional part of a sentence.
INC
Increments a Multibit Operand / Accumulator.
INV
Produces the one’s compliment of the contents of the multibit accumulator.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 43 / 56
STL instruction summary
JMP TO
(Step Label)
Causes the program to continue execution at the specified Step.
LOAD
Allows loading specified operands (single or multibit) and constants to either the single or multibit accumulator.
NOP
A Special instruction which is Always True in the Conditional Part of a sentence. In the Executive Part it is equivalent
to “Do nothing”.
OR
Performs a logical OR operation on single or multibit operands and constants.
OTHRW
Provides the ability to continue program execution if the Conditional Part of a sentence is False.
RESET
The Reset instruction is used to change single bit operands to logical “0” status.
ROL
Rotates Left all bits contained in the Multibit Accumulator by one position. The most significant bit is moved to the
least significant bit.
ROR
Rotates Right all bits contained in the Multibit Accumulator by one position. The most significant bit is moved to the
most significant bit.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 44 / 56
STL instruction summary
SET
The Set instruction is used to change single bit operands to a logical “1” status.
SHIFT
Performs a Single Bit Swap between a Single Bit Operand and the Single Bit Accumulator.
SHL
Shifts Left all bits contained in the Multibit Accumulator by one position. The most significant bit is lost, and the least
significant bit is filled with a zero (0).
SHR
Shifts Right all bits contained in the Multibit Accumulator by one position. The most significant bit is lost, and the
least significant bit is filled with a zero (0).
SWAP
Exchanges the high and low order bytes of the Multibit Accumulator.
TO
Used with the LOAD instruction to specify a destination operand.
THEN
Keyword marking the beginning of the Executive Part of a sentence.
WITH
Used to pass parameters with some CFM/CMP instructions. Also used to specify timer clock rates for some PLC
models.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 45 / 56
Multitasking
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 46 / 56
Multitasking
• Multitasking is the term used for the “simultaneous” execution of a number of different tasks (problems, programs)
• Organising the program sections using modular programming techniques.
• The PLC program can consist of several parts each of which is a program in its own right. These programs have various functions.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 47 / 56
Multitasking
• The advantages of this method of working include clearer program structures and shorter cycle times.
• With multitasking it is easy to program several different operating modes and to be able to call them up at any time and to run parallel
with the main program.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 48 / 56
Multitasking
P0
Main control program
P0 is activated automatically
when power on
© Festo Didactic – Training & Consulting
P1
CMP 0
CFM 0
CMP 49
CFM 49
P63
CMP 99
CFM 99
Program
( Multi-Tasking )
Module Program
( Subroutine )
Function modules
( Predefined by Festo )
P2
PLC programming
20.12.03
No. 49 / 56
Multitasking
• Multitasking – modules can be activated by the main program / other programs to run concurrently.
• P1 to p63 can be activated to run parallel with P0. Hence, a multi-tasking of 64 programs can be achieved.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 50 / 56
Multitasking
STEP 10
Then Set O0.0
P0
STEP 20
If I0.0
Then SET P1
STEP 30
Then Reset O0.0
© Festo Didactic – Training & Consulting
STEP Start
If I0.1
Then Set O0.2
P1
STEP End
Then NOP
PLC programming
20.12.03
No. 51 / 56
Multitasking – call module program
• Sub routine – modules can only be activated by the main program to run as sub-routines. (CMP – call module program)
• Command – CMP X
THEN CMP x
module number x
With p1
1st parameter
With p2
2nd parameter
With p3
3rd parameter
With p4
4th parameter
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 52 / 56
Multitasking – call module program
STEP 10
Then Set O0.0
P0
STEP 20
If I0.0
Then CMP0
STEP 30
Then Reset O0.0
© Festo Didactic – Training & Consulting
STEP Start
If I0.1
Then Set O0.2
B0
STEP End
Then NOP
PLC programming
20.12.03
No. 53 / 56
Multitasking – call function module
• Sub routine – modules can only be activated by the main program to run as sub-routines. (CFM – call function module)
• Command – CFM X
THEN CFM x
module number x
With p1
1st parameter
With p2
2nd parameter
With p3
3rd parameter
With p4
4th parameter
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 54 / 56
Multitasking – call function module
STEP 10
Then Set O0.0
P0
STEP 20
If I0.0
Then CFM 8
With v2
With v6
Function Add
(Internal Module)
v2 + v6 = v8
F8
Load FU32
To R0
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 55 / 56
Multitasking - summary
When you are doing multitasking:
• The sub-program will be activated and will run together with the main program, which will still carry on running.
• The programs are running parallel.
• When using the CMP (call module program) or CFM (call function module) command, you are activating a sub-routine.
• In this case, the main program will stop and stay at that step and the sub-program will be activated.
• Only when the sub-program is completed it will jump back to the main program at the point where it left.
© Festo Didactic – Training & Consulting
PLC programming
20.12.03
No. 56 / 56
Download