0% found this document useful (0 votes)
16 views14 pages

10 - API Course CHAPTER 5 PROGRAMMING

This document describes the different programming languages used for programmable logic controllers according to the IEC 1131-3 standard. It presents the cyclic operation of a controller and defines the concepts of addressing and assignment of inputs/outputs. The contact language is described in more detail.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

10 - API Course CHAPTER 5 PROGRAMMING

This document describes the different programming languages used for programmable logic controllers according to the IEC 1131-3 standard. It presents the cyclic operation of a controller and defines the concepts of addressing and assignment of inputs/outputs. The contact language is described in more detail.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Chapter V.

API Programming

API Programming

V.1. Introduction
The realization of all or part of a command section in programmed logic requires the
translation of the concerned model (grafcet, equations, ...) into an executable program by the API.
The development of such a program aims to write the output activation equations of the API and
the associated conditions in a language respond to theindustrial standards of thecommission
international electrotechnicsIEC 1131-3. This standard for programming languages of
programmable automation allows defining five usable programming languages, which
are:
Contact diagram (LD: Ladder Diagram)
Block Diagram (FBD: Function Block Diagram)
SFC (Sequential Function Chart) Language
Instruction List (IL)
Structured Text (ST).
The LD, FBD, and IL languages are available for all ranges of controllers, while the ST
and the SFC are only available for the S7-300/400, WINAC, and S7-1500 models.
To program the automation system, the automation engineer can use a programming console (portable)
or a computer equipped with programming software (for example: Step 7 for Siemens APIs or PL7 for
Schneider).
To send the program created to the memory of the automation, a serial connection is used between
the automated system and the computer or a specific cable when using a console.
In this chapter, we present the execution cycle of a paragrame by the programmable automation.
industrial, in the first place. Secondly, we define the notion of training and assignment. Then, we
describe the different programming languages of APIs. Then we will focus on the
programming of different operations in contact language. Programming in languages by
Blocks and a list of instructions are provided briefly at the end of the chapter.

V.2. Processing of the automation program

A machine executes its program cyclically as follows:


Internal processing: The automated system performs control operations and updates certain
system settings (detection of transitions between RUN / STOP, updates of values of
the timestamp, ...).
Reading inputs: The automaton receives data through its inputs and copies them into the
memory image of the inputs.
Program processing: The automaton processes incoming data through a defined program.
in its memory and writes the outputs in the output image memory.
Output writing: The automaton switches the various outputs to the defined positions in the
memory image of the outputs to control the actuators and communicate with the operator and the
other automated systems.

46
Chapter V. API Programming

INTERVENING TREATMENT

READING INPUTS

TRAITEMENTDU PROGRAMME

WRITING OF OUTPUTS

Figure V.1. Operating cycle of an API.

The term scrutiny refers to the set of four operations carried out by the automaton and the time of
Scrutation is the time taken by the automaton to process the same part of the program. This time varies.
depending on the size of the program and the power of the controller, and it is on the order of ten
milliseconds for standard applications.
Scanning time

T-I The E T-P E- S T- I L- E T- P E- S

Taking into account the Tipping of the


Triggering a detector
Change of entry exit

Response time
Figure V.2. Total scanning and response time.

The total response time is the time that elapses between a change of state of an input and the
Change of state of the corresponding output: The total response time is at most equal to two.
the time of scrutiny (without special treatment). This time is on the order of about twenty
milliseconds and is controlled by a timing called watchdog.

V.3. Allocation and Addressing


Before starting to program, it is very important to carry out the assignment of inputs and
outputs of the automated system, and know its addressing.
The assignment of inputs depends on the sensors and control buttons used. The outputs
are affected with pre-actuators, indicators, etc. The assignment also involves identifying
these variables are intended to store the states and intermediate values during execution of the
program.
Addressing involves identifying I/O variables and internal variables by addresses.
The addressing notion of an automaton allows us to know the type of object, the format of the data that
we will be able to form and its location (or number). Table I.1 shows the meaning of the
different symbols that can be found in an address.

47
Chapter V. API Programming

Prefix Meaning
I (or E) Reading the state of an input.
Q (or A) Read/Write the state of an output.
M and V Lecture/Writing the state of an internal variable (memo)
SM Lecture/Writing a bit System
S Lecture/Writing a Sequential Relay Bit
C or (Z) Meters
SC Fast counters
T Timers
A or (P) Analog
% IEC 1131-3 standards
B Size of a byte or octet
W Word size: 16-bit word
D Size of a double word: double word of 32 bits
Table V.1. Meaning of the different symbols of an address.
Examples:
Input bit 4 module 0.
IW125: entry word 125.
Output bit 4 module 1.
QB17: Output octet 17.
M12.15: internal memory bit 12.15.
MD48: dual internal memory 48.
AIW 288: Analog Input 288.
AQW304: Analog Output 304.
Note 1: addressing can be absolute or symbolic. Absolute addressing involves using the
physical addresses of the automate. To bring clarity to the program, addressing is used.
symbolic. This amounts to substituting each physical address with a symbolic address that
best represents the function. The mnemonic assignment table is "the tool" used to
create a symbolic addressing.
I0.4: Q0.4:
I0.4 Q0.4 Marche Pompe Market Pump

Absolute addressing. Symbolic addressing. Absolute and symbolic addressing.


Note 2: the addressing mode depends on the API manufacturer. Therefore, you should consult the manual.
of this automaton.

V.4. Programming languages for API

The programming languages of APIs are of various natures given the diversity,
users who can use them. They can be classified into two families:
V.4.1. Graphic languages
They allow for as direct a graphic transcription of the patterns as possible in order to
facilitate programming tasks and reduce sources of uncertainties. We distinguish three
the following languages: Contact diagram, Block diagram, and Functional sequence diagram.
Contact diagram: LeLDest is the most used, very easy to handle, and ideal for
visualize and diagnose programs during maintenance operations. It is suitable
in combinatorial processing.

48
Chapter V. API Programming

Block diagram: TheFBDis presented in the form of a diagram to create variables,


operations or functions, simple or very sophisticated. The blocks are programmed
(library) or programmable.
Functional sequence diagram: The SFC allows for graphical representation and
structured way the operation of a sequential automation. It is derivedthe grafcet.

V.4.2. Textual languages


It is about describing how the process works through a program in the form of a text.
Two languages exist: Instruction list and structured literal.
Instruction list: LeILest is a 'machine' language that allows writing processes.
logical and numerical. It can be compared to assembly language. Very rarely used by the
automators.
Structured literal: LeST is a 'computer' type language allowing for structured writing.
(algorithms) for logical and numerical processing. It is of the same nature as Pascal. Little used
by the automation engineers.

V.5. Programming in contact language


The relay language is based on a symbolism very similar to that used for the
electrical diagrams. It is composed of several networks. Each network contains
horizontal lines containing contacts, functional blocks, and coils between two bars
of power supply. The contacts allow reading the value of a boolean variable. The blocks
Functional blocks are pre-programmed blocks that allow for advanced functions to be performed:
timing, counting, communication, ...etc. The coils allow writing the value of a
boolean variable. The evaluation of each network is done from left to right. The evaluation
The entire network operates from top to bottom. Each network is identified by a label.
(LABEL).
In this suite, we present the most commonly used operation games, SIMATIC (Siemens standard),
for Siemens S200 PLCs. Programming is done using Step7 software.
Micro/Win version 4.
Note 3: The representation of operation games depends on the automaton, the standard, and the
version of the software used in programming.
V. 5.1. Combinatorial operations on bits
The table below shows the main combinatorial operations on bits.

Operation Graph Comment


The contact is closed if the value of the queried bit stored in
< operand > <operand> equals 1. However, if the bit <operand> is 0, the
Contact at The contact is open. Current flows through the contact and the operation.
closure provides a logical result (LRG) equal to 1 if and only if
contact is closed and the RLG at its entrance equals 1.

< opérande > The contact is closed if the value of the queried bit saved in
Contact at
<operand> is 0. On the other hand, if the signal state in
opening
<operand> is 1, the contact is open. The current flows through the
contact and the operation yields a logical result (LRG) equal to 1
if and only if the contact is closed and the RLG at its input
equal 1.

49
Chapter V. API Programming

RLG Inverter NOT This operation inverts the logical result bit (LRB).

< operand > This operation works like a coil in a diagram.


Bobbin of at the relay. If the energy reaches the coil (RLG = 1), the bit in
exit
<operand> is set to 1. If the energy does not reach the coil
(RLG = 0), the bit in <operand> is set to 0.

This operation only executes if the RLG of operations


< operand >
previous to the value 1. If the energy reaches the coil (RLG
Reset R
equals 1), the operation sets the internal N bits to 0, starting
N from the address of the indicated operand.

< operand > This operation is performed only if the RLG of the operations
S previous to the value 1. In this case, the N bits are set to 1,
Set to 1
N starting from the specified operand address.

This operation is executed as follows:


< opérande >
Bascule RS S OUT
S R Operand (out)
(put to 1, put 0 0 The unchanged operand
to 0) RS 0 1 resetting the operand bit
1 0 Setting the operand bit to 1
1 1 Set to 1 then set to 0. The operand therefore remains at 0

This operation is executed as follows:


< operand >
Bascule SR S OUT
S R Operand (out)
(reset, reset 0 0 The unchanged operand
to 1) SR 0 1 resetting the operand bit
1 0 Setting the operand bit to 1
1 1 Reset to 0 then set to 1. The operand therefore remains at 1.

This operation detects the transition from 1 to 0 of the signal state.


Detect from N RLG before the operation and shows this transition with an RLG
front equal to 1 in the form of a pulse. After the pulse, the
descendant the logical outcome is 0.
This operation detects the transition from 0 to 1 of the signal state.
Detect front P from RLG, before the operation, and shows this transition with a
amount RLG equal to 1 in the form of a pulse. After the pulse, the
The logical result is 0.
Tableau V.2. Combinatorial operations on bits.
Examples
S
I0.4 I0.4 Q4.0
E S E S E NOT
E E E
t t t
I0.4 I0.4 S
t t t
S S Q4.0
t t t

50
Chapter V. API Programming

Q1.0 M2.0 Q4.0


S OUT S OUT N
Q4.0 Q5.1 SR RS
E R S E Q4.2
1 1 R R S

S E
E
t t
t
R Q4.0
Q4.0
t t
t
Q1.0 Q4.2
Q5.1
t t
t
M2.0
t

V.5.2. Association of contacts and coils


Series contacts: The association of series contacts allows for the creation of logical 'AND' operations.
Parallel contacts: The association of parallel contacts allows for the realization of "OR".
logics.
Series coils: The association of coils in series is not possible.
Coils in parallel: The association of coils in parallel allows for controlling multiple
coils by the same logical equation.
Example: Implement the following logical function:O1I1 I2+ I3 , and put the outputO2to 0 if the
functionO1is null.
I1 I2 O1
NOT
The exitO1is equal to 1 and the outputO2is
I3 O2 reset to zero,
R
1
V.5.3. Comparison Operations
Comparison operations compare the inputs IN1 and IN2 according to the types of
following comparison:
== IN1 equals IN2. IN1 IN1 IN1 IN1
<> IN1 different from IN2. ==B >I <= D
> IN1 greater than IN2. IN2 IN2 IN2 IN2
< IN1 less than IN2. IN1 IN1 IN1 IN1
>= IN1 greater than or equal to IN2. D <R
<= IN1 less than or equal to IN2. IN2 IN2 IN2 IN2

The symbols B, I, D, R, and S mean that the data format of inputs IN1 and IN2 is
octet, integer, double integer, real and ASCII, respectively.
-The byte comparison operations are unsigned. The others are signed.
These operations are only executed if the RLG of the previous operations has a value of 1.
-If the comparison is true, the logical output result (LOR) is 1 (the contact is closed).

51
Chapter V. API Programming

Example

I0.0 I0.1 MD0 I0.2 Q0.1 The output Q0.1 is set to 1 if the signal state is
>=R S 1 at inputs I0.0 AND I0.1, AND if MD0 >=
MD4 1 MD4 AND if the signal state I0.2 is 1 at the input.
V.5.4. Conversion operations
The conversion operations read the content of the input parameter IN and then convert it.
The result is stored in the output parameter OUT. These operations only execute if the input
The EN value is 1. The ENO output takes the value 1 if the operation is performed.
Among these operations, you have the following:
B_I: Convert byte to 16-bit integer, B-I ROUND
Convert 16-bit integer to byte, EN ENO EN ENO
BCD_I: Convert DCB number to 16-bit integer. IN OUT IN OUT
I_BCD: Convert 16-bit integer to DCB number,
I_DI: Convert 16-bit integer to 32-bit integer
ROUND: Rounding: converts a real value IN into a 32-bit integer
TRUNC: Truncate: converts a real number IN into a 32-bit integer and places the part
entire result in the variable indicated by OUT.
Example
If the signal state is 1 at input I0.0, the content
I0.0 BCD-I Q4.0 the word of memento MW10 is read as number
IN INO NOT DCB in three digits and converted to an integer
of 16 bits. The result is stored in the word of
MW10IN OUT MW12
MW12 memo. The output Q4.0 is set to 1 if the
conversion is not executed (ENO = 0).
V 5.5. Transfer operations
This operation is activated by the validation input EN. The value indicated in the input IN is
copied to the address specified in the OUT output. The signal state of ENO is identical to that of EN.
You have the following transfer operations:
MOV-B: Transfer of a byte,
MOV_B MOV_W MOV_DW
MOV-W: Transfer of a word,
IN NO EN ENO IN NO
MOV-D: Transfer of a double word,
MOV-R: Transfer of a real. IN OUT IN OUT IN OUT

Example
The operation is executed if I0.0 is at 1. The content of
I0.0 MOV_W Q4.0 MW10 is then copied into data word 12 of the
EN ENO Data block in progress. Output A 4.0 is set to 1 if
MW10 IN OUT MW12 the operation is executed.

V 5.6. Shift and rotation operations


The shift operations allow for bit-by-bit shifting of the contents of input IN towards the
left or to the right. The number of shift bits is given by the input N.
You have the following shift operations:
SHR_B: Shift right by one byte.
SHR_W: Right shift of a word.

52
Chapter V. API Programming

SHR_DW: Right shift of a double word. SHR_W SHL_DW


SHL_B: Shift left by one byte. IN INO EN ENO
SHL_W: Shift a word to the left. IN OUT IN OUT
SHL_DW : Left shift of a double word. N N
Example
The SHL_DW operation is executed if the state of
I0.0 SHL_DW Q4.0 signal is 1 at input I0.0. The double word of
IN INO memento MD0 is loaded and shifted towards the
MD0IN OUT MD4 left of the number of bits specified in MW4.
MW4 N The result (double word) is stored in MD4.
La sortie Q4.0 est mise à 1.
Rotation operations allow for bit-by-bit rotation to the right or to the left.
left of the content of the IN entry. The number of rotation bits is specified in the parameter
entrance N.
You have the following rotation operations:
ROR_B: Right rotation of a byte.
ROR_B ROL_W
ROR_W: Right rotation shift of a word.
EN ENO EN ENO
ROR_DW : Right rotation of a double word
ROL_B: Rotation to the left of a byte. IN OUT IN OUT
ROL_W: Rotation to the left of a word. N N
ROL_DW: Rotation to the left of a double word.
Example

I0.0 ROL_DW Q4.0 The ROL_DW operation is executed if the state of


IN NO signal is 1 at input I0.0. The double word of
MD0 IN OUT MD4 memento MD0 is loaded and is the subject of a
MW4 N
left rotation of the number of bits
specified in MW4. The result (double word) is
arranged in MD4. The output Q4.0 is set to 1.

V. 5.7. Logical operations


Logical operations on numbers allow the execution of logical functions.
following on number and two numbers:
INV_B: Invert byte, i.e., form the one's complement.
INV_W : Invert word.
INV_D : Reverse double word. INV_B INV_W
AND_B: ET octet EN ENO EN ENO
AND_W : AND word IN OUT IN OUT
AND_DW : ET double mot
OR_B: OR byte
OR_W: OU word OR_DW AND_B XOR_B
OR_D : OR double word EN ENO IN ENO EN ENO
XOR_B : Exclusive OR byte IN OUT IN OUT IN OUT
XOR_W : Exclusive or word N N N
XOR_D : Double word exclusive OR

53
Chapter V. API Programming

V. 5.8. Arithmetic operations


Arithmetic operations on numbers allow the execution of arithmetic functions.
following on two numbers:
Operations Add, Subtract, Multiply and Divide
ADD_I Add 16-bit integers ADD_I SUB_I
SUB_I Subtract 16-bit integers IN ENO IN IN
MUL_I 16-bit integer multiplier IN OUT IN OUT
DIV_I Divide 16-bit integers N
N
ADD_DI Add 32-bit integers
SUB_DI Subtract 32-bit integers
MUL_DI 32-bit integer multiplier
MUL_I DIV_I
DIV_DI Divide 32-bit integers.
EN ENO EN ENO
ADD_R Add 32-bit real numbers.
SUB_R Subtract 32-bit reals. IN OUT IN OUT
MUL_R 32-bit real multipliers. N N
DIV_R 32-bit real divisor.
Digital operations
LN SIN
SQRTRoot of a real number.
IN IN EN ENO
LN Natural logarithm of a real number.
EXP Exponential value based on a real number. IN OUT IN OUT
Sine
PID
INCB DECB
Increment (+1) and decrement (-1) operations
EN ENO IN HASTE
INC_B and DEC_B: Increment byte and Decrement byte. IN OUT IN OUT
INC_W and DEC_W: Increment word and Decrement word.
INC_DW and DEC_DW: Increment byte and Decrement double word.
Example
The ADD_DI operation is executed if the state of
I0.0 ADD_DI Q4.0 signal is 1 at input I0.0. The result of
IN THE NOT the addition MD0 + MD4 is stored in the double
MD0IN1 OUT MD10 reminder word MD10. If the result is out of
MD4 IN2 the range allowed for an integer of 32
bits or if the signal state is 0 at input I0.0, the
sortie Q4.0 est mise à 1.
V. 5.9. Counting operations
Incremental counter (CTU) CXX

The Incremental Counter operation increments starting from the current value. CU CTU
at each rising edge of the CU increment input. When the current value
R
"Cxx" is greater than or equal to the predefined value PV, the counter bit Cxx is
activated. The counter is reset to zero when the reset input R is activated. PV
The incremental counter stops counting when it reaches the maximum value.
32,767. The current value of CXX is of type 16-bit integer. CXX
Decremental counter (CTD) CD CTD
The Decremental Counter operation decrements starting from the current value.
at each rising edge of the CD decrement input. When the value in LD
If Cxx is equal to zero, the Cxx counter bit is activated. The counter resets the PV

54
Chapter V. API Programming

Set the Cxx counter bit to 0 and load the preset value PV into the current value when the input
LD loading is activated. The counter stops when it reaches zero and the counter bit Cxx
is then set to 1. The current value of CXX is of integer type.
CXX
Up-Counter/Down-Counter (CTUD)
CU CTUD
The incremental/decremental counter operation increments starting from the
values in progress at each front rising from the increment input CU and CD
decreases on each rising edge of the decrement input CD. The value
The Cxx counter contains the current count. The preset value R
PV is compared to the current value at each execution of the operation. PV
counting.
When it reaches the maximum value of 32,767, the next rising edge at the increment input
set the current value to the minimum value of -32,768. When the minimum value -32,768
Attained, the next rising front at the entry of decrementation causes the current value to take on the
maximum value of 32,767.
When the current value Cxx is greater than or equal to the predefined value PV, the counter bit
Cxx is activated. Otherwise, the counter bit is disabled. The counter is reset to zero when the input
Reset R is activated or the 'Zero Out' operation is executed. The current value of
CXX is of integer type.
Examples

Network 1
I0.0 C1
CD CTD
I0.1
LD

+3 PV

Network 2
C1 Q0.0

Réseau 1
I0.0 C48
See youCTUD
I0.1
CD
I0.2
R
+4 PV
Network 2
C48 Q0.0

55
Chapter V. API Programming

V. 5.10. Timing operations


Start timer in the form of a rising delay (TON) TXX
This operation is used to delay the activation of an output (the bit of theIN TON
timer) for a given time interval after the input (IN) has been
PT
activated.
The timer starts on a rising edge at the start input IN.
The timer initializes if the signal state at the input IN changes from 1 to 0 while the
Timing is executed.
The TON timing continues the counting, once the preset value is reached, Up to the
maximum value (32,767).
The signal state at the output equals 1 when the current value ≥ the predefined value.
In other cases, the output takes the value 0.
The time interval is determined by the product of the timing resolution by the
value of the input PT (integer type).
The timer number (Txx) determines the timer resolution: 1ms
(T32, T96), 10ms (T33 to T36, T97 to T100) and 100ms (T37 to T63, T101 to T255).
Example
Réseau 1
I0.0 T37
IN TON

+10 PT 100ms

Network 2
T37 Q0.0

TXX
Start delay timing in the form of falling edge (TOF)
IN TOF
The Start delay operation in the form of a drop-off delay serves
to delay the deactivation of an output (the timer bit) for a PT
given time interval after the input (IN) has been deactivated.
The timer starts when a falling edge is detected at the start input IN.
The timer initializes if the signal state at input IN goes from 0 to 1 while the
Timing is being executed.
The timer continues to run until the elapsed time reaches the time.
predefined.
If current value = predefined value, the counting is stopped.
The signal state at the output is equal to 0 when the current value equals the predefined value or if the value
in progress = 0 provided that the input IN remains equal to 0. In other cases, the signal state at the
exit is 1.
Example
Network 1
I0.0 T33
IN TOF

+100 PT 10ms

Network 2
T33 Q0.0

56
Chapter V. API Programming

V.5.11. Program management operations


FOR/NEXT loop operation FOR
The FOR and NEXT operations allow you to define a loop that is
executed the specified number of times. EN ENO
You can nest up to eight FOR/NEXT loops within each other.
others. INDEX
The FOR operation executes the instructions between the keywords
INIT
FOR and NEXT.
You specify the number of loops currently INDX, the initial value
Final
INIT and the final value FINAL.
The NEXT operation signals the end of the loop triggered by FOR. NEXT
Example
Réseau 1
I2.0 FOR When I2.0 is activated, the instructions between
EN ENO the FOR operation and the NEXT operation are executed
VW100 INDEX
INIT 100 times, the INDX value being incremented:
+1
+100 Final 1, 2, 3, ...100. When the loop is reactivated, it
copy the initial value into the number of loops
Réseau 5
course (INDX).
NEXT
NEXT
N
N
Jump operations JMP/LBL JMP LBL
The Jump to Label (JMP) operation performs a jump within the program to the specified label N.
if the previous logical result equals 1.
The Define Reference Operation (LBL) specifies the destination N of a jump. The jump reference N is a
constant between 0 and 255.
You can use the jump operation in the main program, in sub-
programs and in interruption programs.
You cannot jump from the main program to a marker located in a sub-
program or an interrupt program. Likewise, you cannot
jump from a subroutine or an interrupt program to a marker located outside of
this subprogram or interrupt program.
Example
Network 1
I2.0 4 If I2.0 is enabled, jump to marker LBL4
JMP
Network 5 4
LBL
S_bit S_bit
SCR Operations SCR SCRT SCRE

If your application consists of a sequence of operations that need to be repeated,


the term SCR operations (sequential relays) allows you to structure your program in order to
that it directly corresponds to your application. You can thus program and test
your application more easily and more quickly.

57
Chapter V. API Programming

The SCR operation signals the start of an SCR segment if the segment bit is equal to 1.
The sequential relay switch operation SCRT allows you to hand over from one segment
SCR active in another SCR segment, if the previous logical result equals 1. The execution of
The SCRT operation in the presence of a signal flow sets the S bit of the current segment to 0.
activates and sets bit S of the referenced segment to 1.
The Sequential Relay End Operation (SCRE) signals the end of a SCR segment if the result
previous logic equals 1.
Example
Network 1
Network 1: Activate Segment 1 during the first cycle.
SM0.1 S0.1
S
. 1
Network 2 S0.1
Network 2: Start of Segment 1.
SCR
Réseau 3 Network 3: Instructions for Segment 1.

Network 4 Network 4: Transition to Segment 2 after activating the bit


T37 S0.2
of delay.
SCRT
Network 5
SCRE Network 5: End of the SCR area for Segment 1.
Network 6 S0.2 Network 6: Start of Segment 2.
SCR

End-of-processing operations

The Conditional End of Processing operation (END) ends the current cycle, if the result
previous logic equals 1. You can use the End of processing operation
conditional in the main program, but not in the sub-programs or in the
interruption programs.
The Conditional End of Processing operation (RET) ends the execution of the subprogram or
of the interrupt program, if the previous logical result equals 1.
The operation STOP immediately ends the execution of your program, if the result
previous logic equals 1, switching the S7-200 CPU from the 'Running' state
(RUN) in the state 'Stop' (STOP).

V.6. Block-based programming


Programming in FBD language involves graphically connecting blocks to each other.
symbolizing the desired functions. Graphically, the general shape of these blocks is identical.
to the representation used by the ladder language. There are still some differences in the
bit operations, comparison operations, and program management operations.
In addition, contacts and coils do not exist in the FBD language but are replaced by
blocks as shown in table V.3.
Note 4: The logical inversion of input or output Boolean signals can be indicated by
a small circle.

58
Chapter V. API Programming

Operation Graph Operation Graph

IN1 AND OUT IN1 OR OUT


ET logic IN2 OR logic IN2
Detect from Detect head-on N
IN P OUT IN OUT
front amount descendant
OUT OUT
Set to 1 IN S Set to 0 IN R
N N
OUT N
Exit = NEXT/ JMP NEXT JMP
IN
S_bit END
RET STOP
SCRT/SCRE SCRT SCRE END/RET/STOP

Operations of IN1 ==B OUT IN1 I OUT IN1 OUT


comparison IN2 IN2 IN2

Table V.3.Language Blocks FBD.


V.7. Programming in instruction list language
The instruction list language is composed of a sequence of instructions, each instruction must
start a new line of code and must contain an operator followed by one or more
Operands. The standard operators of the normalized IL language are listed in the table below.

Operation Comment
LD Load the operand value
LDN Load the inverse value of the operand
A ET logic between the previous result and the state of the operand
AN AND logic between the previous result and the inverse state of the operand
O OR logic between the previous result and the state of the operand
ON OR logic between the previous result and the inverse state of the operand
NOT Reverse the result
EU Detect rising front
ED Detect descending front
= Write the output
S position the operator to a
R Put the operand back to a
LDB= Equality type comparison
AB= Comparison of type equality preceded by a series contact
OB= contact in parallel with the equality type comparison
BTI, ITB Conversion of a byte to an integer, Conversion of an integer to a byte.
+I ; -I ; *I ; /I Addition, Subtraction, Multiplication, and Division of two whole numbers
INCREMENT Incrementing and decrementing a byte
INVB ; ANDB ; ORB Inversion of one byte, and logical operation of two bytes, or logical operation of two bytes
MOVB Transfer a byte
SLB Left shift of a byte, Right shift of a word
RLB ; RRD Left rotation of a byte, Right shift of a double word
Table V.4. Basic operations of the language Listed instructions.

59

You might also like