Ladder Logic (lad) for S7-300 and S7-400 Programming



Yüklə 1,39 Mb.
Pdf görüntüsü
səhifə9/16
tarix05.05.2020
ölçüsü1,39 Mb.
#31077
1   ...   5   6   7   8   9   10   11   12   ...   16
STEP 7 - Ladder Logic for S7-300 and S7-400


Description  
ATAN establishes the arc tangent value of a floating-point number. The result represents an angle 
in a radian measure within the range 
-π/2 ≤ output value ≤ +π/2
where π = 3.1415....
 
See also Evaluating the Bits of the Status Word. 
Status word 
 
 
BR 
CC  1 
CC  0 
OV 
OS 
OR 
STA 
RLO 
/FC 
writes: 









 

 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
105 

Move Instructions 
9.1 
MOVE  Assign a Value 
Symbol 
MOVE
IN
ENO
EN
OUT
 
 
Parameter 
Data Type 
Memory Area 
Description 
EN 
BOOL 
I, Q, M, L, D 
Enable input 
ENO 
BOOL 
I, Q, M, L, D 
Enable output 
IN 
All elementary data types 
with a length of 8, 16, or 
32 bits 
I, Q, M, L, D or constant  Source value 
OUT 
All elementary data types 
with a length of 8, 16, or 
32 bits 
I, Q, M, L, D 
Destination address 
Description  
MOVE (Assign a Value) is activated by the Enable EN Input. The value specified at the IN input is 
copied to the address specified at the OUT output. ENO has the same logic state as EN. 
MOVE 
can copy only BYTE, WORD, or DWORD data objects. User-defined data types like arrays or 
structures have to be copied with the system function "BLKMOVE" (SFC 20). 
Status word 
 
 
BR 
CC  1 
CC  0 
OV 
OS 
OR 
STA 
RLO 
/FC 
writes: 









MCR (Master Control Relay) dependency 
MCR dependency is activated only if a Move box is placed inside an active MCR zone. Within an 
activated MCR zone, if the MCR is on and there is power flow to the enable input; the addressed 
data is copied as described above. If the MCR is off, and a MOVE is executed, a logic "0" is written 
to the specified OUT address regardless of current IN states. 

Move Instructions
 
9.1 MOVE  Assign a Value
 
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
106 
Reference Manual, 04/2017, A5E41524738-AA 
Note 
When moving a value to a data type of a different length, higher-value bytes are truncated as 
necessary or filled up with zeros: 
 
Example: Double Word 
1111 1111 
0000 1111 
1111 0000 
0101 0101 
Move 
Result 
to a double word: 
1111 1111 
0000 1111 
1111 0000 
0101 0101 
to a byte: 
 
 
 
0101 0101 
to a word: 
 
 
1111 0000 
0101 0101 
 
Example: Byte 
 
 
 
1111 0000 
Move 
Result 
to a byte: 
 
 
 
1111 0000 
to a word: 
 
 
0000 0000 
1111 0000 
to a double word: 
0000 0000 
0000 0000 
0000 0000 
1111 0000 
Example 
MOVE
IN
ENO
EN
OUT
Q 4.0
I 0.0
MW10
DBW12
 
 
The instruction is executed if I0.0 is "1". The content of MW10 is copied to data word 12 of the 
currently open DB. 
Q4.0 is "1" if the instruction is executed. 
 
If the example rungs are within an activated MCR zone: 

  When MCR is on, MW10 data is copied to DBW12 as described above. 

  When MCR is off, "0" is written to DBW12. 
 

 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
107 
10 
Program Control Instructions 
10.1 
Overview of Program Control Instructions  
Description 
The following program control instructions are available: 

  ---(CALL)       Call FC SFC from Coil (without Parameters)  

  CALL_FB      Call FB from Box  

  CALL_FC      Call FC from Box  

  CALL_SFB    Call System FB from Box  

  CALL_SFC    Call System FC from Box  

  Call Multiple Instance  

  Call Block from a Library  
 

  Important Notes on Using MCR Functions  

  ---(MCR<)     Master Control Relay On  

  ---(MCR>)     Master Control Relay Off  

  ---(MCRA)     Master Control Relay Activate  

  ---(MCRD)     Master Control Relay Deactivate  
 

  RET              Return  
 
 

Program Control Instructions
 
10.2 ---(Call)  Call FC SFC from Coil (without Parameters)
 
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
108 
Reference Manual, 04/2017, A5E41524738-AA 
10.2 
---(Call)  Call FC SFC from Coil (without Parameters) 
Symbol 
 
---( CALL ) 
 
Parameter 
Data Type 
Memory Area 
Description 
 
BLOCK_FC 
BLOCK_SFC 

Number of FC/SFC; range depends on 
CPU 
Description 
---(Call) (Call FC or SFC without Parameters) is used to call a function (FC) or system function 
(SFC) that has no passed parameters. A call is only executed if RLO is "1" at the CALL coil. If 
---
(Call) is executed, 

  The return address of the calling block is stored, 

  The previous local data area is replaced by the current local data area,  

  The MA bit (active MCR bit) is shifted to the B stack

  A new local data area for the called function is created. 
After this, program processing continues in the called FC or SFC. 
Status word 
 
 
 
BR 
CC  1  CC  0  OV 
OS 
OR 
STA 
RLO 
/FC 
Unconditional: 
writes: 









Conditional: 
writes: 










 
Program Control Instructions
 
 
10.3 CALL_FB  Call FB from Box
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
109 
Example 
MCRD
I 0.0
I 0.1
MCRA
CALL
Q 4.0
.
.
.
.
.
.
FC10
.
.
.
.
.
.
CALL
FC11
OPN
DB10
.
.
.
 
 
The Ladder rungs shown above are program sections from a function block written by a user. In 
this FB, DB10 is opened and MCR functionality is activated. If the unconditional call of FC10 is 
executed, the following occurs: 
The return address of the calling FB plus selection data for DB10 and for the instance data block 
for the calling FB are saved. The MA bit, set to "1" in the MCRA instruction, is pushed to the B 
stack and then set to "0" for the called block (FC10). Program processing continues in FC10. If 
MCR functionality is required by FC10, it must be re-activated within FC10. When FC10 is finished
program processing returns to the calling FB. The MA bit is restored, DB10 and the instance data 
block for the user-written FB become the current DBs again, regardless of which DBs FC10 has 
used. The program continues with the next rung by assigning the logic state of I0.0 to output Q4.0. 
The call of FC11 is a conditional call. It is only executed if I0.1 is "1". If it is executed, the process of 
passing program control to and returning from FC11 is the same as was described for FC10. 
 
 
Note 
After returning to the calling block, the previously open DB is not always open again. Please make 
sure you read the note in the README file. 
 

Program Control Instructions
 
10.3 CALL_FB  Call FB from Box
 
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
110 
Reference Manual, 04/2017, A5E41524738-AA 
10.3 
CALL_FB  Call FB from Box 
Symbol 
FB no.
ENO
EN

 
 
The symbol depends on the FB (whether it has parameters and how many of them). It must have 
the EN, ENO, and the name or number of the FB. 
 
Parameter 
Data Type 
Memory Area 
Description 
EN 
BOOL 
I, Q, M, L, D 
Enable input 
ENO 
BOOL 
I, Q, M, L, D 
Enable output 
FB no. 
DB no. 
BLOCK_FB 
BLOCK_DB 


Number of FB/DB; range depends on 
CPU 
Description 
CALL_FB (Call a Function Block from a Box) executed if EN is "1". If CALL_FB is executed, 

  The return address of the calling block is stored, 

  The selection data for the two current data blocks (DB and instance DB) are stored,  

  The previous local data area is replaced by the current local data area,  

  The MA bit (active MCR bit) is shifted to the B stack, 

  A new local data area for the called function block is created. 
After this, program processing continues within the called function block. The BR bit is scanned in 
order to find out the ENO. The user has to assign the required state (error evaluation) to the BR bit 
in the called block using ---(SAVE). 
Status word 
 
 
 
BR 
CC  1  CC  0  OV 
OS 
OR 
STA 
RLO 
/FC 
Unconditional: 
writes: 









Conditional: 
writes: 










 
Program Control Instructions
 
 
10.3 CALL_FB  Call FB from Box
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
111 
Example 
MCRA
.
.
.
Q 4.0
OPN
DB10
.
.
.
.
.
.
FB11
EN ENO
DB11
.
.
.
OPN
DB10
 
 
The Ladder rungs shown above are program sections from a function block written by a user. In 
this FB, DB10 is opened and MCR functionality is activated. If the unconditional call of FB11 is 
executed, the following occurs: 
The return address of the calling FB plus selection data for DB10 and for the instance data block 
for the calling FB are saved. The MA bit, set to "1" in the MCRA instruction, is pushed to the B 
stack and then set to "0" for the called block (FB11). Program processing continues in FB11. If 
MCR functionality is required by FB11, it must be re-activated within FB11. The state of the RLO 
must be saved in the BR bit by the instruction ---(SAVE) in order to be able to evaluate errors in the 
calling FB. When FB11 is finished, program processing returns to the calling FB. The MA bit is 
restored and the instance data block of the user-written FB is opened again. If the FB11 is 
processed correctly, ENO  =  "1" and therefore Q4.0  =  "1". 
 
 
 
Note 
When opening an FB or SFB, the number of the previously opened DB is lost. The required DB has 
to be reopened. 
 

Program Control Instructions
 
10.4 CALL_FC  Call FC from Box
 
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
112 
Reference Manual, 04/2017, A5E41524738-AA 
10.4 
CALL_FC  Call FC from Box 
Symbol 
FC no.
ENO
EN
 
 
The symbol depends on the FC (whether it has parameters and how many of them). It must have 
EN, ENO, and the name or number of the FC. 
 
Parameter 
Data Type 
Memory Area 
Description 
EN 
BOOL 
I, Q, M, L, D 
Enable input 
ENO 
BOOL 
I, Q, M, L, D 
Enable output 
FC no. 
BLOCK_FC 

Number of FC; range depends on CPU 
Description 
CALL_FC (Call a Function from a Box) is used to call a function (FC). The call is executed if EN is 
"1". If CALL_FC is executed, 

  The return address of the calling block is stored, 

  The previous local data area is replaced by the current local data area,  

  The MA bit (active MCR bit) is shifted to the B stack, 

  A new local data area for the called function is created. 
After this, program processing continues in the called function. 
The BR bit is scanned in order to find out the ENO. The user has to assign the required state (error 
evaluation) to the BR bit in the called block using 
---(SAVE)
If you call a function and the variable declaration table of the called block has IN, OUT, and 
IN_OUT declarations, these variables are added in the program for the calling block as a list of 
formal parameters. 
When calling the function, you 
must assign actual parameters to the formal parameters at the call 
location. Any initial values in the function declaration have no significance.  
Status word 
 
 
 
BR 
CC  1  CC  0  OV 
OS 
OR 
STA 
RLO 
/FC 
Unconditional: 
writes: 









Conditional: 
writes: 










 
Program Control Instructions
 
 
10.4 CALL_FC  Call FC from Box
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
113 
Example 
MCRA
.
.
.
.
.
.
Q 4.0
OPN
DB10
.
.
.
.
.
.
FC10
EN ENO
FC11
EN ENO
 
 
The Ladder rungs shown above are program sections from a function block written by a user. In 
this FB, DB10 is opened and MCR functionality is activated. If the unconditional call of FC10 is 
executed, the following occurs: 
The return address of the calling FB plus selection data for DB10 and for the instance data block 
for the calling FB are saved. The MA bit, set to "1" in the MCRA instruction, is pushed to the B 
stack and then set to "0" for the called block (FC10). Program processing continues in FC10. If 
MCR functionality is required by FC10, it must be re-activated within FC10. The state of the RLO 
must be saved in the BR bit by the instruction ---(SAVE) in order to be able to evaluate errors in the 
calling FB. When FC10 is finished, program processing returns to the calling FB. The MA bit is 
restored. After execution of FC10, program processing is continued in the calling FB depending on 
the ENO: 
ENO = "1"  FC11 is processed 
ENO = "0"  processing starts in the next network 
If FC11 is also processed correctly, ENO  =  "1" and therefore Q
4.0  =  "1"
.
 
 
 
Note 
After returning to the calling block, the previously open DB is not always open again. Please make 
sure you read the note in the README file. 
 

Program Control Instructions
 
10.5 CALL_SFB  Call System FB from Box
 
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
114 
Reference Manual, 04/2017, A5E41524738-AA 
10.5 
CALL_SFB  Call System FB from Box 
Symbol 
SFB no.
ENO
EN

 
 
The symbol depends on the SFB (whether it has parameters and how many of them). It must have 
the EN, ENO, and the name or number of the SFB. 
 
Parameter 
Data Type 
Memory Area 
Description 
EN 
BOOL 
I, Q, M, L, D 
Enable input 
ENO 
BOOL 
I, Q, M, L, D 
Enable output 
SFB no. 
DB no. 
BLOCK_SFB 
BLOCK_DB 


Number of SFB; range depends on 
CPU 
Description 
CALL_SFB (Call a System Function Block from a Box) is executed if EN is "1". If CALL_SFB is 
executed, 

  The return address of the calling block is stored, 

  The selection data for the two current data blocks (DB and instance DB) are stored,  

  The previous local data area is replaced by the current local data area,  

  The MA bit (active MCR bit) is shifted to the B stack, 

  A new local data area for the called system function block is created. 
Program processing then continues in the called SFB. ENO is "1" if the SFB was called (EN = "1") 
and no error occurs. 
Status word 
 
 
 
BR 
CC  1  CC  0  OV 
OS 
OR 
STA 
RLO 
/FC 
Unconditional: 
writes: 









Conditional: 
writes: 










 
Program Control Instructions
 
 
10.6 CALL_SFC  Call System FC from Box
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
115 
Example 
MCRA
.
.
.
.
.
.
Q 4.0
OPN
DB10
.
.
.
SFB 8
EN
ENO
REQ
DONE
ID
ERROR
R_ID
STATUS
SD_1
SD_2
SD_3
SD_4
M11.0
READY
M10.0
DB 8
CODE
DW12
DW14
DW16
OPN
DB10
 
 
The Ladder rungs shown above are program sections from a function block written by a user. In 
this FB, DB10 is opened and MCR functionality is activated. If the unconditional call of SFB8 is 
executed, the following occurs: 
The return address of the calling FB plus selection data for DB10 and for the instance data block 
for the calling FB are saved. The MA bit, set to "1" in the MCRA instruction, is pushed to the B 
stack and then set to "0" for the called block (SFB8). Program processing continues in SFB8. When 
SFB8 is finished, program processing returns to the calling FB. The MA bit is restored and the 
instance data block of the user-written FB becomes the current instance DB. If the SFB8 is 
processed correctly, ENO  =  "1" and therefore Q4.0  =  "1". 
 
 
Note 
When opening an FB or SFB, the number of the previously opened DB is lost. The required DB has 
to be reopened. 
 

Program Control Instructions
 
10.6 CALL_SFC  Call System FC from Box
 
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
116 
Reference Manual, 04/2017, A5E41524738-AA 
10.6 
CALL_SFC  Call System FC from Box 
 Symbol 
SFC no.
ENO
EN
 
 
The symbol depends on the SFC (whether it has parameters and how many of them). It must have 
EN, ENO, and the name or number of the SFC. 
 
Parameter 
Data Type 
Memory Area 
Description 
EN 
BOOL 

Enable input 
ENO 
BOOL 

Enable output 
SFC no. 
BLOCK_SFC 

Number of SFC; range depends on 
CPU 
Description 
CALL_SFC (Call a System Function from a Box) is used to call an SFC. The call is executed if EN 
is "1". If CALL_SFC is executed, 

  The return address of the calling block is stored, 

  The previous local data area is replaced by the current local data area,  

  The MA bit (active MCR bit) is shifted to the B stack, 

  A new local data area for the called system function is created. 
After this, program processing continues in the called SFC. ENO is "1" if the SFC was called (EN = 
"1") and no error occurs. 
Status word 
 
 
 
BR 
CC  1  CC  0  OV 
OS 
OR 
STA 
RLO 
/FC 
Unconditional: 
writes: 









Conditional: 
writes: 










 
Program Control Instructions
 
 
10.6 CALL_SFC  Call System FC from Box
 
Ladder Logic (LAD) for S7-300 and S7-400 Programming 
Reference Manual, 04/2017, A5E41524738-AA 
117 
Example 
MCRA
.
.
.
.
.
.
Q 4.0
OPN
DB10
.
.
.
.
.
.
SFC20
EN
ENO
SRCBLK RET_VAL
DSTBLK
DBDW12
MW10
MOTOR.SPEED
 
 
The Ladder rungs shown above are program sections from a function block written by a user. In 
this FB, DB10 is opened and MCR functionality is activated. If the unconditional call of SFC20 is 
executed, the following occurs: 
The return address of the calling FB plus selection data for DB10 and for the instance data block 
for the calling FB are saved. The MA bit, set to "1" in the MCRA instruction, is pushed to the B 
stack and then set to "0" for the called block (SFC20). Program processing continues in SFC20. 
When SFC20 is finished, program processing returns to the calling FB. The MA bit is restored.  
After processing the SFC20, the program is continued in the calling FB depending on the ENO: 
ENO = "1"  Q4.0  =  "1" 
ENO = "0"  Q4.0  =  "0" 
 
 
Yüklə 1,39 Mb.

Dostları ilə paylaş:
1   ...   5   6   7   8   9   10   11   12   ...   16




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin