You are on page 1of 440

Hans Berger

Automating with STEP 7 in LAD and FBD


51MATIC 57300/400 Programmable Controllers

SIEMENS

HansBerger

Automating with STEP 7 inLAD and FBD


wooer diagram (LAO) "nd function block diagram (FSD) ~re the graphic-<:>rient.. rl pro9ram min9lan9u a9~ in the prog r~mmi n9 .~oftwaraSTEP 7. Now,n it< fourth ~>dj.lj.orl, this book tntwd uce, in the late,t ver<.ion of STEP 7 w ith new function~. 1\ de,cribe, e lemen ts arld_~pp l icJtion"'lo.. o"" with both SIMATIC 57'100 and 5IMATIC.57400mduding the a pp lications w ilh PROFINET. Speda l lu nciions He PROF INET 1 , SFC 109 Protect and function bloc~< for fieldbu~ !y<; tems <Ire a lso 0 <!e.crim.d. II is 'almed at<lll users 01 51MATIC 57 controllers , First time u se-rs are int""duce d 10 the field of p rogra mmable con1rollers, w h il e advanced USers learn a bmJl ~peci fic applications of th~SIMATIC 57 automation ,~stem. SIMATICiSlh e wo rldl.o'li de sta bljsn.e<l au tomMion syrtem for im plementing indus trial control:systems for madJ;nes, ma n ufact uring plants and industrial pmce,. Releva nt ope n-loop and dosed-Joop comrol tash Me formulated in various pro, 9ramming langllages with the programming software STl;P7 , All programming e xamples found in the book - and ,"ven ~ few extra example' - ~",_available .over tile publishe r'< w eb,ite under Download ....

Contents

Operation pri n~ieje of programmable conl<o l)er,. System overv;'/(; SIMATIC S7 ~nr! STE e 7 - (AD ~"'I FRD pro<Jr~mm;n<J laO<Jua<Jes . Data typ"'. Binary and dig ita l instructions Prog ram seque n ce control User program ,"xewt;on

Ord~r N<>. A19100 153HI951-X_7600 4" edition, 2008

Publicis Corporate Pllblishing www.publids ..Jelbook~

Automating with STEP7 in LAD and FBD


Programmable Controllers

51 MATIC 57-300/ 40 0
by Hans Berger

4th revised and extended edition, 2008

Publicls Corporate Publishing

HiblioiJ1lphic: information publi.hed by the Ikut""he N.tionalbibliom..k The Dc-uttehe Narionall';bliom..k liM. this publication in th~ Dnnsch~ Natiooalbibliopfle: detailed bibliolV"pJ",; data:lre ",... ilablc LIt the lnlCmC1 al hup :l'dnb.d-nb.~.

Th" Jl<OiJ1Imming .,.ample. oO<1OO11lnll" on dc",,";bing III<: L"-O .ne! FBD fUDctioll1 and prO~id'"lI SJM,,-TlC 57 _ ... with progr.mming tip. for wiving speclfio ta.k. with this contron.r. Tho programming example. gi vell 1ft the book do I",t prot.n<! to be complete w lut;"", or to be "ne u,.hle on fulu", STEP 7 rolea.." or S7-300/400 ver.;onl. AddilioNll .Ir. mu>t b. talen in order 10 comp ly with 11>0 ",I_ ""ani safely "'liIu l"i"" . The luthOO" and pub'is"'" ha vo taken ~at e,,", wi:h an I~x\l and illU>tnltioos in book. ".".<thel". orrl>t'll ""n """.r be comple'ely avoided. Th" publisher lfId tho author no [jability. ""anll... oflepl booi fo< any damap ",.ulling from the use of the pmlil'V".rrunll .xamples.

""".-pi

,hi.

The aulhor at>d publi.her are ah.",YJ valefu! 10 bear your "'SJIODSO> 10 th~ conlen'" of me book. PubHcij CorporolC PubliMrina: P.O. IJ.ox 32<1 0 _91030 Eriangen E_mail ' publ io;hin g -bools@publioi . de Inl.""", www.p ub lici .delbooh

ISBN 978-3-89578-297-8
4th edItion. 2008 Ed itOr. Si.m .... "-klkngcselbchaft. Berlin and \h"llch l'ubli,h..-: I'ubIkil COIJl'O'"'lle Publi.hiog, Erla/li"" C 2008 by Publici. KommunihtionsAIClIturGmbll. OWA. ErI""lIen Thi. publiclloon and all parts tlterwf an: plttl"'" by copyrillht. All rights ..,..,."ed Any ux of;1 outoide the striet prm.-;.ions of the copyrigbtl.'" without th., consetll oftht publisher is forbtddon and ..m incur pt;nallia. This &pplil!1 pankularly 10 ",prot.!l,ICIion. ..... <1!I&tKm. mkmfilmillj or otbcrproc:ouin3. and 10 6t""'Je or proces.injl: in electlttoic. 1}'1ttm. It al", oppli 10 tho use of ex"""'", from til<: text. Prinled in Gcmuny

Preface

Preface

The SIMATTC automation sys,em uni,es aJl the subsystem, of an automation solu.ion under unifonn system architecture into a homogeneous whole from the field level right up to process controL This TotaHy Integrated Automa_ tion (TIA) concept pennits integrated ~onfil!ur ing, programming, data management and com_ mun ications within the complete automation system Fine-tuned communications mechan isms permit hamloniou. interaction \xr.vcen programmable controllers. visualization systems and d istributed lfOs. As the basic tool for SIMATlC, STEP 7 handles the par~onth~sis function for Totally Integrated Automation. STEP 7 is used to carry out the configuralion and progranulllng of the SIMATIC 57, SIMATTC C7 and SIMATIC WinAC automation systcms. Microsoft \Vindow. has been .el""ted as the operating system. thus opening up .he world of standard PCs with the user desktop widely used in the office environment. For block programming STEP 7 provides programming languages that comply with DL" EN 6 .1131 _3: STL (statement list; an Assembler like language), LAD (ladder logic; a Tepresentation .imi lar to relay logic di agrams), FUD (fun ction block diagram) and the S7_SCL opt ional package (snucrured control language . a Pascal-like high-level language). Several optiona l packages supplemcf'llthese languages: S7-GRAPH (sequential control). S7.HiGraph (programming wi,h state-transition diagrams) and CFC (conn~ting blocks; similar to func tion b l""k diagram) . The various methods of representation allow evcry uSCr to select the suitable control fUnclion description. Th is

broad adaplabihty in representing th~ control task \0 be solved significantly simplifies working with STEP 7 This book describes thc LAD and FBD programming languages for S7 -300/400, As a valuable s"pplement to the language description. and foilowing an introdnction to the 57300/4 00 automation system, il provides valuable and practice-oriented information on the b asic handling of STEP 7 for the configuration of StMATIe PLCs, their networking and programming, The description ofthc "basic fune tions" of a binary control, such as e.g. logic opcI1llions or storage functions, is panicularly useful for kginncrs or those convening from contactor controls to STEP 7. The digital functions explain how digital values are combined; for example, bask calculations, comparisons or data type conversion. The book shows how you can control the program processing (program flow) with LAD and FBD and design structured programs. In addi tion to the cyclically proce..ed main progrom, you can also incorpor-lle eventdriven program sections as well as influence the behavior oftbe controller at startup and in the event of errors! faults. The book ~onclud~s with a general over view of Ihe system functions and the function sel for LAD and FBD. The COnlcnrs of Ihis book describe Version 5 .4 Service Pack 3 ofthe STEP 7 programming software.

Erlangen, May 2008 Hans Berger

The Contents of the Book at a Glance

Overview of the S 7-300/400 progmnunable logic controller

I'LC functions comparahle to a comactor control sy,tem

Handling numhcN and digi\al operands

Introdncdoll

Ba.k fun<."I1"ns

Digita l fUllctioUJ

Pru~rammabtc

1 SlJ\L\TIC S7-3IJGI4Q(l C"",,.,,Uor

4 BI ... ,), Lo~k Operation.


A.>.iD, OR.nd fxdus;ve OR FUDell"".;

9 Cump.ri..,n Function. Comporjwn Accordu'i 10 Da'" Types INT, DiNT and


~,

Structure of the Pmgrammahk Oll\lmll .. (H",dware Componellts of$7_300(400); Memory Ar"",~


Distributed [10

N""ting t'uru:lions

5 Memory Functio ns

10 .... rllbmetk FUDCtlUOS Fou,-fuooion M.lh wilh INT,


DINT aJ>J REAL numb.:rs:

(PROFIfIUS QP): Cooununiu><ioDs (Sutm.t.), M.-.Juie Addru8C.;

A;,ign. Sci ODd }l.eset.;


Midlme o.,lp"a;

bdge e,-.Iua"oo:
I:.~.tnple

Add,."..,., A,,,,,,
2 ST EP 7 SGR... r.
~: P",&rammID~

of a Cooveyor Bolt

Control SY"t<m

11

Mot~.m.lIcat

.-u.nct1on.

Tri~omctric

FunctiOn>;

Arc functi<m.; 6 Mow FUDction'


Loot! aoo Trunsfer Functions:
~u.ring_ Square_ root hlr3<lion, Exponerrtiatioo,

Ilditiog Projects; Configurina Stal ions; C<)ftfiguring tbe Net""orli:; Syn,bol Edi"'r;

U:>garitlull5

Sy,t= Functions for Data Transfer 12 Com'oT5ign fUDotlon. 7 'f!moro Start SIMATIC Timon with F ive Diffe",nt Ch.,-aotrn.tic., Re ~tting and Scannmg; lEC Timer Function. Data Type C""ve.-.ion; Complement FOImation

LADlFBIf Pru""n &bIOI';


OIJline Mod<: T~tiDgL'LD ODd FUD Pmg ... m.~

3 SI:\-tl\TIC S7
Pm~m

t3 Shift fun<tion. Shifting and ROOIIIn<:

Program I'mce"ing;

Blocl{TyJ>e' :
, ProgralnIl1ing C,><k 1I100KSIlrl<l
1)0", Blocks;

8 Counto ... SIMATJC Counter->; Count up. Count down, SCI, Reset.nd Sc"" Count""'; IEC CountIT Function, 14 Word Lo~i< l'r<:>o;:e;sin& AND, OR and &d""i,'. OR Worrl Logi<: Operation

Addrc.ing V.. iabli;:" Coost""; Rcprc .. otation, Oat. 'r;'PI'; D<:s<ri ption

The Programming Examples at a Glance

The: pre5CIlt book provides many figureS repre~t iDg the use ofl/lc LAD aod reo J'!TOiI1UIIming languages. All programmini examples can be downloaded from the publisller', website _w.publicis.deIbooks. There are NoD Iibruiet LAD_ lJ.ook Md FOD_Book.

The libraries LAD_Book and FBD_Book contain dght programs that are ...entillly illustration, of the graphi~al rcprestntation. Two extens;,c cxamples oIIow the propamming of funcrion$, function blocks and local instances (Con'cyor Example) and the handling of data (Message Frame Example). All the uamplcs contain symbols and comments.

,
106 FB 101 fB lOS

and Looalln'to"" ...

fa

~ 8

103

Fe 4-t

The libraries are supplied in archived fOITII. Before you ean sum working with them, you must dearehive the libraries. Select the FlLE_ DEARCUJVE menu item in the SIMATIC Manager and follow the instructions (see also the REA DME.TXT within the down load files).

To uy the programs out. set up a project corresponding 10 your hardware configuration and then copy the program. incl uding the symbol table from the library 10 the project. Now you can call the example programs, adapt them for your own purposes aud tcstthem onlin e.

Llbran fBD Book

DUI1)'pu EXlmples of Definition and Applieatillll fB 101 Elmlentary Data Typt' fB 102 Complex Data Types Fn 103 Panomcler Types Basic FunctiOn! FUD Reprcs<:nlOlion Examples Fa FB Fa FB FB 1().1 105 106 107 108
Cbapt.r4: Series and Parallel Circuits

Program Processl n!: Ex.mples or SFC Calli fB FB FB FB 120 Chapto:r 20: Main Program 121 Chapt..,. 21: Interrupt ProcesSlnS 122 Chapter 22: Stan_up Char'lC1eristio:s 123 C~aptcr 23: Error Handlins

Conwyor Enml'l e Examples ufBasic Functions and Locallnstanc~ Fe 11 FC 12 FB 20 Fa 21


FB 22

Chapttr5: Chapler6: Chapter7: ChapterS:

Memory Fl1IIC1ion< Mo,. Functi<Kl.'i Timer Functions CO\If\ter Functions

Belt Control Counter Control

F=<
Con"eyor Belt Paru Counter

Digltl l FunctIons fBD Reprnenllotion Examples FB 109 fa]10 FR 111 FB 112 Fa 113 Fa 11 4 FBD Chapter 9: Chapter 10: Ch.lpter H: Chapter 12: ClLapterl3: Chapter 14: Compari:!Oll flmCliOll$ Arithm~tic func(ions Math FunctiolU Conversion F"""ions Shift Func(ions Word Logic

:llnulIc Fnm. En mpll' Data Handling Examples UD151 Data Suucture For tltc Frame HelKkr OUT ~ 2 Data SlIUCture for I Message Fa SI Genc-rale Message Frame FBll Sto~ M~ge Frame FC 51 Tirne-of-day Check Fe 52 Copy Data A~a witb indirt\:t A dd~ss ing Gc n c r~1 [umplcs FC 41 FC 42 FC 43
FC ~

}'ro~r.m

Re~sentalion

Flow ContrOl Examples

FB 115 FB 116 Fa 117 FB 118 Fa 119

Cltap(er 15: Slatus Bils Chapter 16: Jump Funcrions Chapter 17: Mas((1 Control Rday Chapter 18: Block F"",tions Chapto:r 19: Block pll3ffiC(e~

R.ange MoniUlr Limit Value Dc~linn Compound Intere,t CIJculalion Doubleword"",i'le Edge E,.. lualion

Automating with STEP 7

..".

- .

O~"'''ting

......." ,'

proje ct

+
=w~

.'
e

A utomati ng "jth STE P 7 Th is double page shows the basic proccdure for using the STEP 7 programming softv.1lI"e.

L
i"",7~

'"

Start the SIMATIC Manager ami set up a new proj ect or Op"n an cx isting proj ect. All the data for an automation task are stored in the fonn of objects in a project. Whcn you set up a project. yOll create conta iners for the accumulated data by set_ ting up the required s/alions with at least the CPUs; then the containcTll for the user programs arc also created. Vou can also create a program container d irect in the projttt.

Use pmject ass istant

Cooflgu ra central rack (select paw-er supply

a nd CPU)

Creat.. Pruj..ct
contain",

CPU MIh DP ma$ter:

~"

al~~~rt PROf' I6US

CD
tnunstaUOrt

, ,,

In the nexi steps. you configure the hardware and, if applicable. the communications conne<:tions. Following this, you creale and test the program.
The order for crealing the aUlo_ malion data is not fixed. Only

1Open Hardware cbj&e1


"~I
~",.

Conf'llU'" expansiofl rack (proceed 8 S for central

-,

lhe following general regula_ lion applies: if you want 10 process object s (data), they must exist; i f YOll want to insen object,. the relevrutl containers must he available. You can iotcmtpl processing in a projC\:t at any time and continue again from any locatinn the next lime you stan the SIMATI C Manager.

rack and CPU


Mark DP m a~t?: I

Sa~ e

and canpi le

insert a ootMr ttatiot1

CD
Project structu re

COOfogUf6 000111 .... s tation

is ""I up

Compiled configuration data ere located In 11>8


object
Sy~

'"

DB/a

Automaling wi,h STE P 7

,
:::~~
Slart netwo<l< conffguration

...
u " . ' p~r"m

...
u"

:f
Compiete symbol tab le Insert miss;"" objects
Incr~~nt81

commun ica~o ns

fJJ

Switch onl;ne

!
load s)'$tem data

SOU'C<Ioriemed pro-

M '

.!
P",ameterlze CP modu les ro lovam Isof(v;.....

1
J

'::;'~

"

Creato program source ~ Ies

, ,

.-

(j)

Define data structur..


De~n"

program structure

1 I
I

P"",ram UDTs afld gk>bal DBs Program FCslFBs, ge""rat.. inUance DBs

Single slep

,
I

Se leCllllodule with "connection capability" and conllgure connections with t~" connection table

Program

08~

,=1
~
.
COfTact e'rors , updata offlin .. database

I ,
Conf'gure " Iobal data communicalions

J p il6 program source fi les

!
Gan era!" rnf...-&nco d ata

j Test n,,~t
;

(j)

Compiled connecti<>n data are Inserted In the object System Dale

C ompile<! progfam locale" in the contain .. ' Blocks

Teste<! and n xacutable program in t he CPU and in the programming dev"",

"

Cont<111<1

Contents

:Jnmidvctl(ln . . .

......

1.1
1. 1.1 1. 1.2 1.1 .3 1.1.4

S IMATIC S7-31111/41111
rro~nmm"ble Controll~r.

"
'"
20
20 20

,
2.1 2.1 . 1 2.1.2

STEP 7

Pr(lgrammjn~

50fh, a re

49

STEP 7 11a,is Package I Illllallation Automation Liern~e Manager SL"-t.'\TIC Marutgcr . Proj ects and Libraric~ Multiproja"1s . Editing I"rojects. Creating Projecu . Managing. Reorgan;~ing and Ar-chiving . l>roj ect Versions C!"""in g and editing tnullipr()je~t~ Configuring Stat ion . Ar",nging Mooule ..

of the Programmable ContruU.,. . . Componenu. S7-300Station. S7..400 Stati"". fault-tolerant SThfAllC. Safely-n:Ltted SIMATTC. CPU M~mory Arcas. Distributed 1 . 10 PROFUIUS l)P

Stru~IUn.:

2.1.3

2. IA 2.1 S 2.1.6 Ocline ITdp . . . .

" " "


53

50

I.I.S
1.1.6

14

" "

2.2
2.2.1 2.2 .2 2.2.3 1 .2 .4 2.3 1.3 .1

"

"
28 28 31

1.2.1 1.2.2 1.2.3 1.2.4 L3

PR QF""mTO
Acruatorl Sensor Interface. Gateways

..

"
Jl

" " " " " " " '"

Communication . Introduction _
SubllCt~

J5

2.3.2 Addr.-ssing Module. 2.3.3 ParnrneterU.ing Module.~ 2.3 .4 .!'-etworking Modules ...ilh MPI
2 .3.S Monitoring and Modifying Modules. . . . Configurin g the Network ..
C(lnfi~uring the Network View. Confi guring a Distributed L10 with the Network Cunfigurntion . Configuring Connections . .. Gateways loading the Conne<:lian Oata Mntchin g Project.;n 3 MultiproJCCt ....

60 60

!J. I 1.3.2

\.3.3
1.3.4
" 1 4.1

Communications Connections .

Scn~Ce'i.

Madule Add1X'<;scs.
1.4 .2 1.4.3 \.4.4 1.4.S

1.4.6

Sigual Path . . . . Slo\ Addre~ .. Logical Add!""s . ModuJ~ Slart Addu,," . Diagr>oStie~ Address . . Acidre!lK'5 for nus Node;; Address
Art:a~

., " " " " " " "


" " " '"
"

J5 31

H
2.4.1 2. 4.2 2. 4.3

'62 1
62

" "
" " '"
70

2.4.4 2.4.5
2.4.6

68

2.5
2.5.1 2.5.2 2.5.3 2.5.4

Creating the S7 I'rogmn . Introduction. Symbol Table . Pro);I"3ffi Editor. Rewiring Addre. s I'riOOty Refel"l:!l<:c Data . l.no:uage Setting .

'"
71

70

I.S

\.S.I
I.S.2

J .5.3 !.S .4

U ...."T 0lI1li An:.a Process Im.gt . Consistent U ... r Data Ait M~mori~,

76
77

2.S.5
2 .5.6 2.5.7

79

" "

Contents Variables, Constant, and Data Types General Remarks Concerni ng Variables .. Addressing Variables. Overview of Data Type. Elementary Data Types . Complex Data Types Parameter Types User Data Types.

2.'
2.6.1 2.6.2 2.6.3 2.6.4 2.6.5

Online

Mo d~

Connecting a PLC Prote<:ting the User Program CPU Information . Loading the User Program into the CPU Block Handling Testing the Program Diagnosing the Hardware Detcnnining the Cause of a STOP Monitoring a nd Modif)'ing Variabl es . Forcing Variables Enabling Peripberal Outputs. Test and process operation. LADffBD Program Status. Mon itoring and Modify;ng Data Addresses SIMATI C S7 Pro gram . Progn.m Process ing . Program Proccss ing Methods Priority Classes Spe<:ifications for Program Processing Block s Block Types Block Structu!"<'. Block Propenies . Block Interface.

"' "' 82

"'

"
3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7

" 6 '16
120

2.7
2.7.1 27.2 27.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8

"

"

86
80

'" '" '" ,n


>28

86 87 88
90 90 90

Basic F llnctions . . . . . . Binary Logic Ope rMlon . Series and Parallel Circnits (LAD) NO Contact and NC Contact Series Circuits. Parallel Cire"its. Comb inations of Binary Logic Operations. Negating the Result of the Logie
Op~ra\ion

D'

,.,
4.1.1 4 .1 .2 4 .1.3 4.1. 4 4.1.5 4.2 4.2 .1 4.2.2 4.2.3

'"

'" '"

,
3'
31.1 3.1.2 3. \.3

" "

"

D2 D2

U3

.. . .

94 95

Binary Logi c Operations (FBD) Elementary Binary Logic Operations .. Combinations of Bina ry Logic Operat ions. Negating the Result of the Logic Operation . Taking Account of the Sensor Type-. M emory Function s. LAD Coils . Single Coi l Set and Reset Coil. Memory Box f BD Boxes. Assign .. Set and Reset Box . Memory Box Midline Outputs. Midline Outputs in LAD Midline OutputS in FBD

'" '"
03 ' 038

'.2
3.2.1 3.2 .2 3.2 .3 3.24

" 98
99

.. ..

'"

' 39

3.3
3.3. ! 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7
3A

Programming Code Blocks Open ing Blocks Block Window . Overview Window. Programming Networks . Addressing. Editing LAD Elements. Editing FBD Elements. Programm ing Dma Blocks . C!"<'ating Data Blocks Types of Data Blocks Block Windows and Views

'"' , "" '" ,., '" '"


.08

4.3

'"

5. I I
5.1.3

'" '"

'42

5.1.2

'08
.09

,.,

'" ,44

'" 112

3.4.1 3.4 .2 3.4.3

'" '"
'" '"

5.2.1 5.2.2 5.2.3

'" '" ' 48


"8
' 50 ' 50

' .3
5.3. 1 5 3.2

'"
U

Contents

'A
S.4.1 S.4.2 5.4.3

Edge Evaluation . . . . . . . . How Edge Evaluation Worb Edge EVlIlu.o.Tion in LAD Edge EvaluaTion in fBD . Binary Sealer

'"

7.7
7.7.1 7.7.2 7.7.3

lECTnners ..

.. . . .

180

IS2

'" m '" '"


'62 '62 '64 '65 '65

Pulse Timer SfB 3 TP . . . . Qn..o..lay Timcr Sfn 4 TON . OffDelay Tnner SFB 5 TOt'. Counters .. . . . Progrll.mm ing" Counler Seuing and ResellinJ; Counters. CounTing Checking a Counler. IEC Counl<TS . . . .

'80 '80 '80


18'

" 5.5.1
5.5.2

..

Solution in LAD. So luti(>Il in FilD . Ellample of a Conveyor Control


Sy~tem.

'" .. , '" "


R.2 8.3 8A

'6 6 6. ' 6.'


6.2 .1 6.2.2 6.2.3

'"' ' 85
IS'

Mo\"t

Fun~tlons.

General MOVE !)ox the MOVE Box . Movmg Operands . . . Moving Constants . System Functions for Data Transfer . .
Proc~5ing

16' 16'

163

186 8S1 Up Counter SFO 0 cru 187 8.5.2 Down Counter SfB I CTD. '"7 8.5.3 Upldown Counter SF8 2 eni D . 187 Part;; Counter Eltampl\! . '.6 18. 8.'

'"

6.3

6 .3. 1 ANY Pointer . . . . 6.3.2 Copy Dala Area . 166 6.3.3 UninlemJptibte Copyi ns of a Duta A~a .. 166 6.3.4 Fill Data Area . . . 166 6.3.S Rcading from load Memory 168 6.3.6 Writing into Load Memory 168

ott)lal .' uoclions .. .. .. Comparlsoo


Fn n~ltons

19' '93 '93


' 97

'"

"
!J.2

Process ing a Comp"ri.f<)n function ..... Description of the Compllri:SOll Functions . . . . . . . . Arlt hmetir
Pnxe~.iog Fu n~tl on

7 7. '
7.1.1

Thnrn . . . . . . . Programming a TlITler . Gclk."T1IllleprescnllUion of a Timer. . . Staning a Timer . Specifying the Duration of Time RCS<:ltinll A Timet. . Cheding a Timer . Sequence of Timer Operations Timer Box in a Rung (LAO) Timer IJ.m< in B Logic Cin.:uiT
(FU D) ..

17' 170 170

"

10.1

an AriThmetic

f unction
10.2 10.3 10.4

.....

.. . .

"7

CalculaTing with Dala Type Jr.'T . CalculaTing with Dala Type REAL. Mathern.lleul Funcll(mt Proc essing 8 Mathematical function Trigonometric Functions .
Arc

Calculating wilb Oata Type Dt"T 200

'"

7.1.2 7.1.3 7.1.4 7.U 7.1 .6 1.1.7 7. 1.8

'71
173

'" '"

'00

II
11.1

7.' 7.3 7.' 7.5 7.6

Pul., Timer .
EltteT1ded Pulse Timer . On-Delay Tim..... Rclcnli\"e On-Delay Timer Off. Delay Timer . . . .

'" '" '" m


'76
177

'"
20' 21)'

11.2
11.3 11.4

FUIIClioDs. . . . . . . .

,\liscdlaneollli Matbmlatlcal functions . . . Con version }'unctlon . Procrssing a COO"ersiOD function

''''

'78

"

'''' 207
. 207

12. \

'"

"

Contents

12.2
12.3

Conversion of [NT and DrNT Numbe rs Conversion of BCD Numbers Conversion of REAL Numbers Miscellaneous Conversion Functions .. Shift Funcdons Processing 8 Shift Function Shift Rotate Word Logic

209
2 10

"

Block Fun ction . . . . . . Block Functions for Code Blocks B lock Calls' General Call Box. CALL CoiL'Box. B lock End Function. Temporary Local DOlO Sialic Local DOlO Block Functions for Data B locks

18. I I 8. I I 18.1.2 18.1.3 IS. I .4 IS .l.5 18 .1.1; 18.2 18.2. I 18.2.2 18.2.3 18.2 .4 18.3

'" m
DO DO 238

12.4 12.5
D

210

m
m m
2 15 2 16

239 2<0 241 2"

13 .2 13.3

'"

"

. .. ... .

14. I 14.2

Processing a Word Logic Operation. Descr iption of the \Vord Logic Opt:rmions

'"
'"
m
220

Two Data Block Regislers 2" Accessing Data Operands . Opening a Data Block Special Points in Data Addressj ng System Functions for Data Blocks .

'" '" '"


2"

Program Flow Control

18.J.I Creating a Data Block in Work Memory . 18.3.2 Crcaling a Data Block in Load Memory . 18.3.3 Deleting a Data Block. 18.3.4 Testing a Dala Block
Block P a rameters . B lock Parameters in General

249

2>0

"

Status Bits . . . Descrip!ion of the Slat", Bits Sening ' he S!aIUS BilS Evaluating the Statu, Bi!, Using the Binary Result

15.1 15.2 15.3 15.4

'" "
221 222 224 225

'" '"

\ 9.1

19 LI Defining the Block Parameters . 19.1.2 Processing the Block l'aramcK"" 19.1.3 Declaration of the Block
Paramelcrs

m m m m
253

225 15.4. I Scuing !ne Binary Result BR 15.4.2 Main Rung, EN/EKO Mecbanism 225 15.4.3 ENO in the Case of User_wriuen Blocks . 226

19.1.4 Declaration oftne Function Value 19.1.5 Initializing Block Par"",eters. 19.2 19.3 19.4 19.5
Formal Parameters Actual Parameters . "Forwarding" B l<x:k Param eters
F~amplcs

'" '"
m
2S3

" "

Jump F unction . Processing a Jump Func!ion . Unconditional Jump JumpifRLO - I". Jump ifRLO - "O". Ma.ter Control
R~la y

16.1

m m
228 229 229

260
260 260 26' 262 .269

16.2 16.3 16.4

19.5 I Conveyor Be l, Example. 19.5 .2 PariS Counter Example 19.5.3 Fe~ E~ample
Program Processing .

17. 1 17.2 17 .3 17.4

MeR Dependency . MCR Area MCR Zone. Selling an d ReSClling lIO Bits .

m m

'"

"

Main Program. Program Organization.

20.

'" 23O
270

232
233

20.1.1 Program Strucrnre. 20.1.2 l'rogram Organi~.ation.

'" "

20.2

Scan Cycle Control

272

20.7

S7 Communication . . .

DO DO
332

20.2.1 l'roccss IllliIge Up<Jating . 20,2 .2 Scan L-yd~ Monitoring Tim~ 20.2.3 M ;n;,num SC/ln C yde Tirll<.', Rackground SClInning .

272
274

27S
176 276

20.2 .4 Re.<poru;o: TIme . 20.2.5 Stan infonnatil)f1 .


20.3 20.3.1 20.3.2 20.3.3 20.304 20 .3.S 20.3.6 20.3.7
20.3.~

20.7.1 f~ndan1entals. 20.7.2 1\>.o-Way Data Exchange . 20,i.3 Onc-W.yD"tanchange. 20.7,.1 Tnmsfcning Print Dahl. 20.7.S Control f unttiollll. . . 20.7.6 _\Ionitoring runctions . 20.8

m
335 335

3"
339

Program f unctioos

m
27K
2RO

IE communie,uion ..

Tillie or dsy . Read Sy'tem Cl"",k Run-Time Metcr , . Compressing CPU Memory , Waiting and Stapping . . . Multiprocessing MOlle . . . . Determinin& the Oil Program Runtime. .. . . . . . . . Ct.angin8 program protK1ion .
Cmnmunication via Distributed I/O

no
282 2K2 2M2 283 286 287 287

20.8,1 Basks , . . . 20.8.2 Estah lishing and cleari ~ s down Co""ect ion~. . . , , 20.8.3 nata transfcr with TCP "flliv~ or IS(}...-,n-TCI' .... ,' 20.8 .4 Dato. transfer with UDP. 20.9

no
341 343 345

PIP c"",",unication with S7-300c 346

2004

20.9 .1 fundsmCfltals. 20.9.2 ASCll driver and 3964(R) pro<edure 20.9,) RKSI2 ~omputer coupling. 20 .1 0 Config'Jration in RUN . . . 20 .10. 1 I'r..paration of Changes in Con figuration. . . . 20 .1 0.2 ChangeCnnfiguT'/lti(l<l . . 20 10.3 Load Configuration . . . . 20.IOA CiR Synchroniution Time.. 2[l.IO ,S I:.ffccts on l'rogram Exe;:ulio" 2[l,10,6 Control CiR Pro<;~ss 21 21.1 21 .2 Inlcrru pt H a n dlln K General Remarks .

'"
347 . 349 352 352 353

20.4.1 Addressing PROFI BUS DI'. 20.4.2 Confi~lIrin g I'ROFlBlJS Of' 2004.3 Special F'unct'oru; for PROI'IRIJS 0 1' . . . . . . ' 20.4,.1 Addres<ing PROFL"'I:.T 10 . 20.4.5 Coutigm;ng PROF'l'NET 10. 20.4 .6 Special FuncHons for PRo.l'1NET 10 .. . .. . 2004 ,7 System !)loeb for Distributed
1/0 .

292

'" 3"
300

3S3
3S4 354 354

314 320 320 322 324 324

356 356

20.S

Global Dma C<.>mmun; catiw .

20 .5.1 Furtdamemalll . . . . . . 20 .S.2 Configuring G O communication 20 .5.3 Syslcm Functions for GO Communicotion. 20.6 S7
l:J"si~

Time-of-Day Inttmtpts .

Commuuicatioll .

20.6. 1 Sla\ion -lnternal S7 BAJic Communication 314 20.6.2 Sys\CItl Funcf;Oru; for Slation-internal 57 3 .... ie Commuruealioll . 325 20 .6.3 Slahon- Extcmal S7 FllSic 327 Commnnication .. .. , 20 .6.4 System Funcf;on~ for Station _Exter_ na l S7 Ra,i o Communication 318

21.2 .1 Handling Tlme-ofDay Interrupts 358 21.2,2 Configuring Time-of-Day lnt~m,pts with STEP 7 , 359 21.2.3 S~.tcrn t 'unction! for Tirne"" f-Vay lntcrrupt~, 359 21.3 Timc-Delay inteTTUpt~ 360

21.3 , I Han<iling Time-Dellly lntcrrupu; . 361 21 .3,2 Confi!(uring Timc-IXI~l' lnt~'1TUf't. " 'ilh STEP 7 . .. .. , . 362 21 .),3 Syilt~m FUtlction$ for Tim,,_Iklay Intcm.lpt~ , 362

"

C()nt~nts

2 1.4

Wakhdog

Int~ITl,pts

363

12.S

Parameterizing Module"
3R6

21.4.1 Handling Watchdog IJl\ " rrupt~. 364 21.4 .2 Coniiguring Watchdog Inlcrr"plS with STEP 7 365 1 1.5 Hardware InteITllpts 365

22 .5.1

21.5 . I Generating 8 Hardware Interrupt


1 1.5.2 S~rvi"ing Hardware Interrupts . 11.5.3 Configuring Hardware Interrupts wilh STEP 7

365
306

Gcn~ral remarks on parameICrizing modules. 22,5,2 System Bloch ror Module 'Paramelerizalion 22.5.3 Blocks for Transm illing Data Records

'88

390 393
;93

23
367 23.1 23 .2

'Error Handling
Synchronous Errors. S}"chronous Error Handling

2 16 21.7

DPVllnterrupts Multiprocessor Interrupt . Synchronou, Cycle Interrupts.

367 369 370

395

21 .8
21
~. l

Proces,ing the Synchronous LYcl~ Interrupts. 370 21 8.2 Isoehrone Updating OfProc~s., Image. 2lX3 Configuration of Sync monous Cydc Interrupts with STEP 7 372

23. 2 .1 Error F ilters 23.2 .2 Masking Syn~hronous Errors . 23.23 Unmasking Synchronom Errors 23.2.4 Reading the Error Rcgi,\cr 23.2.5 Entering a Subs\i,u{e Value. 23 .3 23.4 AsynehrotlOl1< Errors SY"em Diagnos!ics.

'"
;oJ ;oJ

397

;97

398

'00
400 400 401 403

21.9

Handling Interrupl Events

372

21.9. I Di""bling and Enabling inl~rrupts 372 2 1.9 .2 De laying and Enab ling I nl"rrupg 373 21 .9.3 Reading additional Interrupt Infonnation. 374

23,4,1 DiagnoSlie 'Event' and Diagno8{ic Buffer. 23.4.1 Writing User Entries in !he l)iagnosri~ Huff"r . lJ,4,3 Evaluat ing O iagno'tic Interrupt; 23,4,4 ReHding the System Stat"s US{.

22.1

"

Starr_up
G~neml

Char~cteri"tks

Remarks

'" 376
376
377 377 377

23.5

Web Server
th~ lV~b S~"ver

23.5. 1 Activating

22 .1.1 Opera{ing Modes .


22.1.2 HOLD Mod~ . 22.1.3 D i,abling the Omput Y.odules . 22.1.4 Re,mn Organization Blocks

23.5 .1 Readin g Oil! \Veh infomlation. 23.5 .] Web information

Appendl~

..

22.2

4U(i:
.97 "8

Power_Up
Mod~

378
378

22 .2. I STOP

22.2.2 Yfemory Resct 2 2 .2.3 Re'toring the fa~!Ory setlings


22.2.4 Retentivity 22.2.5 Restan Parameterizati<m
22 .3
Typ~,

378

Supplemen{S to Graphk Progrllmmin1:

no
m
379

24.1 24.2 24.2.1 24. 2.2 24.2,.1 24 .2.4 243

Block Protection Illdirect Addressing.

'"

of R~'tHn

380 380 380

22 .3 1 START-UP Mode 22.32 Cold Re<ran 12.3 .3 Warm Restan. 22.3.4 Hot Re8{art.

m
383

Pointers: General Rem<ll"k s A rea l'oi11l~r. DB Pointcr ANY Poin!er 24.2.5 "V"riabk" ANY Poinler BrieflJescription of the -MessHge Frame Example" .

'"' .08
408

"0
410

22.4

Ascenaining a Module Addre.s

'"

ConteDts

"

Bhxk Librari es . .. Organization BI<xks.

......

25 .1 25.2 25.3 25.4 25.5

'" " m
'"

fun ctio n

~t

LAD.

16. 1 26.2 26.3

Bask functions. Digital Functions Program Flow Control . Function Set FIJD . Basic Functions. Digital Functions. Program Flow Control

System Function Bl<xks. IEC Function Blocks S5S7 Converting BI<xks . Tl-S7 Converting BI<xks PID Control BI<xlcs . Communication BI<xh . MisceUanwus Blo ch. SIMATIC_NET_CP .

",
426

'"
'28

'"
420

421

25.6 2S.7
258 25 .9

'" '" m
423

"

27 .1

'"
429

27 .2 27 .3

<3, m
433

25 .10 Redundant]O (VI) 25. I I Redundant 10 CGP

'"
'"

Indu .. . . . . Abb re,'lations.

'"

IntTOd uction

Introduction

This ponion ofth~ book provides an o,-erview of the SIMAllC S7 -3()(J/400. The S7-3 00/400 programmable co ntroUer is of modular design. The modules with which it is configured can bc ccnmll (in th~ vicinity of the CPU) or d i<!rihuted without any special setting' or param eter as, ignmems hsving to be madc _ In SIMATIC S7 systems , distributed i/O is an integr,,1 pun of the system . The CPU, with iv; V.u101l.~ memory a reas, forms the hardware basi. for proce ssing of the user programs_ A load memory ~onta iru; the complete user program: the pans o r the program ", levant to it, ex eculion at any given lime are in a "ori< memory whose short acce<> times arc the prerequis ite for fa st progrrun processing .

T he fir<;t chapter contains an ovcrview o f the hardware in all S7 -300/4 00 prOb 'Tammah lc con troller. anu the second chapter comains an OVI.-T" view o r the STEP 7 program mi tlg softwan.: _ The basis for the description is the fun clio n scope tor STEP 7 Ver<;ion 5. 4 SP3 . Chapter 3 SIMATIC 37 Program" s erves a, an introduction to the most importBnt elem ents "I' an S7 program and shows the programming of individual bloch in the programming lan gunges LAD nnd FBD . The functio ns and operations of LAD and H:lV atc then described in the subs~'qucnt cbapters of the book. All th c description_< arc explained using bric f ~xam ples_

STEP 7 is the programming wftwarc for S7300/400 and the automation tool is the 31,\tATfC Manager. The SIMATlC M an"gcr is an application for the Winnov." op"rating systcnts from Microsoft and contains all fLInetion, need<;"d to set up a project. 'Vhen neces,ary. the SIMATIC Manager ,tan, add itional tool, . for example to configun.: , talion" initia liz~ moduks. and 10 write and tcS! pro gra,,,s,

You ionnuiate your automation solntioo in the STEP 7 I',ogramrmng languages. The SI I\ IATIC S7 program i. structured , that is to say. it cons ists of blocks w ith de fLlled functions that are ~umposed ofnctworks or o lllg". Differe nt priori ty c1as,cs allow a graduated interroptibility Oflhc u.er program currently cxccnt ing _ STEP 7 works w ith variahles of varion, data types starting with binary variables (dam type BOOL) through digital v ariables (e .g . data type TNT or REAL for comp uting tasks) up to complex data type, such as arrays or stmcrure. (~ombinations ofvs riables of different types to form a single v ariable).

SIi\lATIC S7_3 00/400 Prol:rammMb lc C o ntruliH Structure of the prognunmab le co ntrolkr; distributed 110; communi cat ions; IDmhde addre"es: operand areas

STEP 7 Pro~~mmlng Sorman


STMATIC Manager; processing 'I proj ect : cont,guring a stati on; ~onfiguri"g a nctwork; w riting programs (symbol table. prob'Tdm editor); switching online : testing pro b",'ms

STi\J ATT C S7 P rogra m Program processing with priority classes; program blocks: addressing va riables; prob,,-amming blo<:ks with LAD and _FBD; variahles and eon .tams; data types (overview)

SIMATIC S7 3000'4(IO J>rognmmable ControUer

SlMATIC 57-300/400 Programmable Controller

1.1

Structu re of Ihe Programmable


Controller

It II . Iso possible 1000nn~ di,mibuted 1/0 to a l!anon (Ie<: Chapter 1.2.1 PROFlBIJS OF). The .... cks connc<:t ll>e modules with two buses: the 110 bus (or P btu) and the communication bUI (or K bu.). The liO bus is designed for high-spi:cd ex change c>f input and output signals. 1M comrnUniClltion bUi for the exchange of l"lie amounts of data. The communication bll$ conne<:\!j the CPU and the programming de"'lce interface (MPI) with function modu les and communications prt>ccNOB. 1.1.2 57300 Statlnn

1.1.1

Compo nen t.

The SfMATIC S7_3001400 is modular progNlmmable controlieT comprising me following componet"':

> Racks
AcootnlllOdate the modules and oonnect them to each other
~

Power supply (PS); Provide!< me internal supply vollag~s Central proce$,ing unit (CPU) St~ and pr""e..." the USef progrnm Interra"" modules (L"-1s); Connect the- TIIcki 10 ODe another Signal modul~ (S'-1s); Adapt the 'ignals from the system 10 the internal signalleve1 or control actuators ... ia digital and analoa: sianals complex or time-en tical processes illdq>end01ltJy of the CPU
E~ecutc

Centnllzcd configuration
In an 57.300 controller. I.! many as 8110 mod ules can be pluggffi in lO the central rack.. Should this slllg.le-tier configuraltOll prove in,ufficinll. you ha,., rv.o opIiOlls for control lers equipped with a CPU 3D or higher.
I> ,\

t>

I>

> Function modules (FMs);

tv,o-tier configuration (wilh 1M 365 up to I meter l>etween rad,s) or

t>

Communication. p~ (CPs) Establi.h the oonn~ion to subsidiary n<"I_

A configuration of up to four tiers (with 1M 360 and Lvi J61 up to 10 mctm between TIIcb)

worb

(.ubnCI~)

> Subnna
Connecl programmable conlroller5 to eacb other or to other dcviccJ
A programmable controller (or station) may com;stofseveral racks. whkh are linked toone another via bm cable,. The pOwer sU;lply. CPU and VO modules (5\-1,. FMs a&d CPs) are pluaac:d into me central rack. If th= is not enough room in the cenlnl! rack for the LO modul"" Of if you ,,"ant some or 111 1 mod.lIes ,0 to be 5CJHIrate from the ccnlTlll reck. expansion rach are .... ailable which Ire Connecl<:d 10 the centro l rack via interface module!< (Figure l.l).

You can <>pc:nIte a maximum of 8 modules in a TIIck. TM Dumherofmodules maybe: limited by the maximam permissible c = t per rack.. whIch is 1.2 A. The modules all' linked to one anOther ... ia a backplane bm. which combines the fUDctiuns of the P and K buses . lura l bUl u\l,menl A special feature regardina: configuration is the uSC of the FM 356 application module. An 1':>.1 356 IS able to split~ a modules backplane bu< and to tllte o\"er control of the- remaining mO(\. ules in the split-off'"local bus legmen'" it""lf. The limilll!;oO$ mentioned ,beve regarding the

20

I. I Struct ure of the Prugrammable Controller

Modular configuration
of aD S7-300 Stati"n

Four-tier contigural;on wilh 1M 3()ti ""d [~j 361

Two-t i. , ,,,,,f'gur.non WI'" l.\t 3M

Modul a r con fiaura tion


of aD S7-JOO . tation
], ' ... "",,,I CQO.wli ,,,,,~ . N 460- 1

w_

Loco! r><Li<
","'l.lrn~ i th

1.\1 %()'l 1.\1 <60-<

5V

(N 46\ 1)

"""""',>Coo

1:-.< .{,ll

Loc. l "'1llI" up'u 5m witt""" ~ V


tr:.rwniMiOIl (l\t46 j-{))

R omot<; ",ng<

"PlO 100m witboul 5 V

.... ''<In;'';on
(1M 461 ])

Romot< rang. up (oWO m


""I00U' ~ V

'Oln.m i" ion (1M 461 4)

R range """". fur up


10 WO tll

S5 oxpan>ion uni" (IM 314)

F ; ~u",

1.1 Iiordware Conillt(uMion for S7 ]()()/ 400

I Sn.tATIC S1_300/400 Pro&rvmmabk ControUII'f packUIIC that is inlegrated in the SIMATIC MaMb'l:T afu:r installation. The Technology Cl'U . have u I'ROFIBU S DP i(1tcrface that allow. opcrutioll liS DP master or DP sla,c_ The Ll'U. an: uJed fur Cf(>M-SCCIOT IIUlomation tasks in series mcch~nical equipment manufacrure. special medtanical equipment manuf.... 1urc. and planl building.
F.nu(~

number of modules and the )lOwer consumption ~I!<O apply in (hi, case. S.andard CPU,
~ staDdard CPUs an.: Qvail abk in vern""s lhat difft:r with regard 10 memory capacity and proeeuing speed They IlUllle from the small o:jl" CPU 312 for lower-t"nd applicalions with moderate proce'<.<ing speed ~uin.:rncnts, up 10 \~C CPU 3\9-3 P:\/O P "im ilS larjlc rrogram memory 8ml high pro<.:es~ini performance r"r CroSl-~OC{or aulom,l1ion tasks, Equipped " im lhe ",IC\lant interfa~~$, some CPUs can be us~ for central control of the distributed !lO via I'KOFTBUS and I'ROFINET. A micro memory ~ard (MMC) is ~uired for o~l'Il1ing the .t.I\IIdard CPU, - ..s with all inno,"'ted S7-300CPUs. Th;" medium opeDS up Dew applicali.,," ~ibililies compared to the pm.iously u,ed memory card(,;ee Chapt<;1" 1.1.6 '"CPU Memory Areas").

Cl'U5

The CPUs 3xxF an: u,;ed in production plant. with increa,ed safety requirements. The relevu,ut PROF lBliS and PROflNET interfaces al low the QPC11I{;On of s.al~ty_related distributcd Ii o u~in.a the PROFhiafe bus profile (see "S7 0151ribu[(:d SafC1y~ under 1.I.S ~Safety-related SIMATle'). Standard modules for normal apphcalion' can be uxd parallel to safety-"'Iated ~ration ..

SIPLUS S7_300

The now dis<:omin ued CPU ) 18 can be replaced by the CPU, 3 17 and 319, Compllet CPU.

The SIPLUS product family offcfti CPU, and module, based on the S7-300 tha' can be use d
til harsh environmenlS. With hori~.ont~1 iostallalion, you have lID extended tem~rarure range of _lSoC to~, lncy ha"e inc",a.ed immunity 10 vibration and shock. and they JT>I the incrc:a.<ed requi..,mellls for humidity, condensa lion and frttring. Please note the I.tthnical da1a for the module concerned. SeleCl~ types oft.bc SIPlUS product mnge are "vuiluble on request for use on rolling stock in aceurJancc w ith EN SOISS "Railway applications - [lIectronic ~uipmenl used on rolling ~1<>ck ~.

'''e )"-" C CPU. permit C<>IISIJUcuon of com

pact mini programmable CUDlrOIlLT>. Ikperlding on me vcr;ion. they alrtady contain:


~

In\cgral liOs Digital and analofl inputs/outputS Integral technoi<JiY function,

I>

Counting. mCaliurcmCIl1, control. po,itiooing


I>

Integnol communic~lions in'crfaccs PROF1BljS OF masU:T Of slave, poim;.,.. point coupling (PIP)

1.\ .3

S7-400 Sta lion

Ctnrrallzed eonlieunli()n
The conlrOiler me\( for the S7-400 i$ available in the \... Rl (18 slots), U R2 (9 stol~) aod CR3 (4 sh)ts) vcrnions. UR I and UR2 can al.o be used as expansion r~cb_ The power supply and the CPU a lo;O occupy slots in !he rack<. possihly evm tWo or more per module. If necess.ary. the number of slots available CM ~ inc",ascd usina e~J'ans;on "",ks: L"'R I and cR I ha"e 18 s\o!$ each, UR2 and ER2 have 9 ta.eh.
The 1M 460-1 and 1M 461-1 in!erf.cc modules m~e it pmsible 10 haveonc exPMlion rack ptr

Thc technological function.s u.rc ~)">tem block.! which use the onbo..rd 110 oflhe CPU.
T~~hnology

CP Us

Tbc C PUs }xxT combiM open_loop c01ltrol fU[IC'\ioru; ",-im muple motion control function,. The open_loop control component i, dcsigned ai in a standard CPU. 11 IS o;Q(Ifiilln:d, parametcri~ nnd progr.1mmed \I~mg STEP 7_ The technology objects and th~ IlIOtion conlrOl com pooncnt require the oplional 57-Technology

I I Stnlcture oflhe Programmable Conlroller

intcrface up to I.~ meters from the cenlral rack. including the 5 V "'pply voltage. In addition . a, many a, four expansion racks Can be operated up to 5 meters away u.ing 1,,1 460-0 and I~ 41i1_0 interface modules . And fL nally, 1M 46O .} Bnd 1M 461} or 1M 460-4 and 41i1_4 interface modules can be used to operate many a, four expansion racks at a distance of up to 100 or 600 meters away.

a.

You can op~rate all analog and digital modules a llowed in these expansion units. An S7-400 can accommodate as many as four 1M 463 -2 interface modules: as many as four S5 expansion units can be con n~cted in a distributed configuration to each of an 1M 4632'8 two interface,. Fault_tolerant SnlATIC

A maximum of21 expansion racks can be con nected to II central ra~k. To distinguish bem'een racks. you set th~ number of the rack On the coding switch of the receiving 1M. The backplane bus consists of II para1lel P bus and a serial K bus. Expansion racb ERI and ERl arc de,'igncd for ",imple'" signal modu les which generate no hardware interrupts. do not have to be supplied with 24 V voltage via the P bus, require no back-up voltage. and have no K bus connection. The K bus is in racks URI. UR2 and CRl either when these rackS are used as central racks or expansion rach with the numbers I to 6. Segmented rack A s!",cial feature is the segtn""ted rack CR2. The rack can accommodate m'o CPU, with a sh"",d power supply while keeping them functionally separate . The t",o CPUs ~an =change data with one another v ia the K bus. but have completely separate P buses for their own signal modules. 1\1ultiproccssor mode

1.1..1

Two des igns of SlIvtATIC S7 fault-tolerant automation systems are avai lable for applications with high fault tolcrance d~mands for machines and processes: ,ofh-vare redundancy ,md 57400HlFH. Software redundancy Us ing SIMATTC S7-3001400 standard components. you can establi,h a software-based redundam system with a master station controlling the process and a standby Slation asswning comrol in the event of the maSter failing. fa u lt tolerance through software redundancy i, suitable for slow processes because transfer to the standby station can require several second s Mpending on the configuration of the program mable controllers. The process signals are "fro ~en"' during this lime . The slandby stalion then continues opcr~tion with the data last valid in the master stati on. Red undancy of the input/oulput modules is implemented with distributed VO (ETIOOM w ith L\1 153} interface module for redundant PROFlBUS DP). Tbe optional "Software Redun dancy" software is available for configuring. fault -tolerant SIMATIC S7-400H
The SIMATIC S7-400H is a fa"lt-tok""'t programmable controller with redundant contiguration comprising two central rack!!, each w ith an 11 CPU and a synchronizmion module for data comparison via fiber oplic eablc. Both controllers operate in "hot standby" mode; in the event of a fault. the intacl controller assumeS o!",ration a lone via automalic bumpless tTanskr. The U R2-H mounting rack with 1\\'0 times nine s lots makes it possible to establish a fault -tolerant ,ystem in a single mOllnting rack.

In an S7_400, as many as four speCIally designed CPUs in a suitable rack can take part in multiprocessor mode. Each module in this station is assigl1ed to only one CPU, both with its address and its interrupts. See Chapters 20.3 .6 "Multiprocessing Mode"' and 21.7 "'.\1ultiproce5sor Interrupt"' for more details.
Connecting SlftlATIC SS module. The 1M 463 -2 interface module allows you to connect 55 expansion unit' (EG 183U. EG 185U. EG 186U as well as ER 7012 and ER 701-3) to an S7-400. and also allow, ~ emral ized expan.,ion of the expans ion units. An 1M 314;n the S5 expansion unit hand les the link .

I SIMATIC S7_.;OO/400 Programmable Ccmtroller

The 110 can have normal availability (singlecharmel, single- sided configuration) or enhanced ava ilabil ity (single--channd .witched eontiguration with ET200M). Communication is ~arried out over a simple or a redundant b"s. The user program is the same as that fo r a nonredundant COI)(roller; the redundancy function i, handled e"elu ,ively by the hardware and is invisible to the user. The ,oftware package required for configuralion is indu ded in STEP 7 VS .3 and laler. The siandard library Red",,dUtll fa already supplied contains bloch for supporting lh" redundant 110.

F_CPUs cUlTently available arc the CPUs 315F2DP and 3 17f-2D P for S7-300, the CP U 41 1iF2 for S7-4OO, and the basic muduk IMI5 1- FI CPU for ET2ooS. The Fmodul e. and f-sub modules are connected to S7-400 u.ing PROI'! B US DP with the safety_relevant profile PROFlSafe . U,e o f F- modules in the controller rack is additionally possible w ith S7-300. STEP 7 w ith th e optional S7 Distributed Safety package is necessary fo r configuration and progranuning of the failsafe system . The safetyrelevam scction of the program is programmed u,ing F_LAD or F-PBD with a limited operation set and fewer data types oomparcd to the basi c lan guages. If a fault is dete<:tcd in the ""fety program, the F-CPU eme", the operating ,tate STOP. The option package also contain , a block library fo r the safety program with failsafe blocks and templatc . S7 F/FH Systems S7 Fff H Systems is a failsafe automation sys tem ba.ed on S7_400 with main applications in th . process industry. S7 F/FH Systems is based on the S7_400 automation system . The F-modules and F-submodu les arcc conne<;ted to S 7400 using PROI'TBUS DP and the safety- relevant profile PROFISate. With S7-400F, a failsafe uWr program can be i n~orporated into the standard Uscr program . Tn addition to failsate ty. tl><: S7-400FH also provides increas.d availabil ity. If a Mtected f"ui( results in " STOP of the master CPU, a switch is made w ith(mt feedback to the CPU running \tl hot standby mode (""c ].1.4 " Fault-to ler",,! SIMATlC"). Con fLguration is carried out using the standard applications of STEP 7, V5 .1 and later. The option package 'S7 F Systems" is required for paramctcrL,ation of the failsafe signal modules and for programming o f the ""fetyrelevant program components, p lus Ih <: option package "eFC", VS.O SP3 and later. thc option package . $7 -SCL" V 5.0 and later and - for the fa ult-tolemnt funclion, the option package "S7 H System," V5 .1 and later.
Spc~ial

l.l .S

Safely-related SIMATIC

Failsafe automat ion systems control proce"es in which the saie state can be achieved by dire<;t swi tching off. They arc u!<Cd in p lants with incr,",sed safety requirements. T he ""fety requjr<.:m~'11ts achievable with SIMATIC S 7 are : Safety Integrity Level SIL I III SIL 3 according to lEe 61508, Rc,!uin:mcnt Category A K I to AK 6 according to DTN V 19250 (DIN V VOE 0801 ) and Category I to 4 accord ing to EN 954L The safelY functions are located as appropriate in the saf~ty_related user program in a correspondingly designed CPU (f-CPU) and in the f31lsafe inputs and outputs (F-modu\es and F_ .ubmodules, sec "Fai lsafe I/O"). The ""fcty technology with F-C PU and f-rnodu les (for the safety_re lated p lant component.) c an be int,,!,'mled in an S7-30014OO P LC in additi on to the standard application . Safety-related communi cat ion using PROF!BUS DP applies thc specially developed PROFlJ:l US protl\ e PROFhafe . Th is permi!> transmi",ion of the user data of safety functions with in the standard data ttlegram . SlMA.TTC S7 provide, two systems for implemelllation of "Safety In'egrated" ; S7 D is tributed Safety and S7 FIFH Systems . 87 Distributed Safety S7 f)istrihuted Safety is a failsafe autorruotion system mainly for appl ications with mach ine controls (for protect ion of mach ine. Hnd personnel ) and in the process industry.

library

~<Ul

f unction blocks from the supplied Fbe called and interconnected using

I. I Structure of the Programmable Controll~'r

efC (Continuous Function Chan). In addit ion to functions for pro.:rmnming safety functioru. they abo contain functions for Crror d.le<;tion and re'ronse . In the event of faulls and failures. thi. guarantees that !he faihaf. system is hdd in a safe statc or is transfe'TT<:u to a saf~ ,tatc. If a fault is dctcctcd in th c safCIY prograP1. the bilsak ~om""nent of the plan' i< ,witched off, wherca__ the remaining pan cominue, to oper a'e. An f_mntime license must b~ pre,em on each CPU to peTIllit opt''''tion of an S7-400f/fH. fail;afc ,ignal module, (F.modulcs) ar~ r<:q\J ired for ,afety operatio" . and are operated in the ET200M disrribU1~d VO station. "ailsafc 110
1b~ fai lsate signal modul es (F-modules) are require<! for ,afe'y <)p<..--ration in lhe failsafe ,ystem,. Fail safery i. achieved with the ;t\legral ",fely fu,,"tioru and appropriate wiring of th" serums and acl\ill.ton;.

uratioru), and fmther projc~l-specijic d" ta ,uch as symboltahle, and comments. Tne Qnlin~ dafa "o",ist of the mer pwgram and the system data on the C PU, and are ac com m<Jdoted in tw<) areas, namely load memory and work memory. A.i>o presenl in addition arc the 'ySlcm memory and """ibly a back up mem"'"y.

Th. 110 moduks contain memories for lhe signal state oIrhe inputs and outpu18. T he cpe s have a slot for a plug-in ",,,mory ."b, "wdu/e. The load memory, or pans thereof. is located hom: (sce " Physical design of CI' U

memory" later). T he memory submodule is


dcsigned as a m"",ory card (57-400 CPU,) or a, a micro memorv c,.,-d (S7_300 CPU. and ET 200 CPUs d~rivcd from these) . The finnwarc "f !he CPU operating ,yst~m can also be updated using the memory s"bmodule.
i\I. m o~

card

The F_module, can also he used in standard appl ications with incre"sed diagnostics require ments . The F-moduk" can ]:x; "Pe--ratcd in redundant mode to incr~ase the availability hoth in standard and ,aferyoperation with 57 Ff FH 'yOlem,. The failsafe 110 is a,ai lable in vat,om versIOns: .,. The fa ilsafe signal modules of 57 -300 de,ign ar~ us"d in the ET200M distribu1ed VO slalion or ec-ntrally toge'!he--r "ilh lhe CPU 3 15f_2DP
>

T he memory module for the S7-4OO CPU. is the memory card (MC). There arc two 'ype' of memory card . RAM eards an d flash EPROM e..,-ds.

IfYl>" want \<) expand load memory only, use a RAM card . A RAM card allows you Il> modify th~ entire user program onlinc. This i. nece,sary, for c,ample, wh~n t~"ting and staning up l arg~r program,. R."l"" memory cards 10""' their conte'll t$ ""e"II unplugged.
I t you wan t to prote~1 your user program, includmg configuration data and moouk paramete", against po\<-,,' failure following testing and ,tarting up even without a backup battery, uSC a fla,b. EPROM card . In this ca.,e, load the ~~,ti re program offi incom" the flash EPROM card with the card plugged into the programming device . With th~ ", levant CPUs, you can also load lhe program ""line w ith the memory card plugged into the CPU.

The fJil",fe power and elc"tronics moo"les arc \J>I'd in the ET2005 distributed liO station. lor whieh the 1:>1 151.FICPU basic module is also available as a f"ibafe CPU. Fail,afe PROfIBU5 DP standard , I ay~s can also be used with S7 Dimibuted Safet)".

\>

1.1.6

C PU l\-Iem ory Areas .\licro


m. mo~'

Figure 1.2 shows the m emory area, in the programming device, the CPU and the ' ignal modu les whicl1 are important for )"our program The programming dcviee conMins the offl;ne data . These consist "f'hc usc' program (program code and user data), the syst~m data (e .g. hardware, nen.,.ork and inte rconn~C1ion coniig-

card

T he memory suhmooule for the n.w~"I 57 -300 CPU s i8 a m icm memory card (MMC). The data on the :>fMC are ,aved non-volatile , but c"n he n:ad, writtcn andddeled as w ith a RAM. This re'rome penn it ' dJia backup without a batler),.

I SIMATIC 57-3001400

P~le

Canlrolkr

.... .~

Hardware

I d.ta t>k>cks r -f--ff (contlguration


dataonlinel

System

Sym~

+ll<.

Arcnive<l
(compressed)
~data

'""

Paru

01".,. hlgllNghred

.,... """ IN PfjratnftIei1z9d In CtIn.In CPUs.

PleNa nolO. "".,. _

InllRUp!

momc:wy _

syslfNn

memotY~.

1ncre.S& '.Il'. In IhI!


In redlJClion

commotl ph.,.;c.l memotY 1ft

.re.

r ". compl~t6 proj6cr dllrll can btJ ioadfHj in rhfJ archIVed stat. kim ".,. CPU'~ load """""Y. If """ssaiY. ltMly""" be_lOthe
ptOgT1ImmIfIf/

$}'$Iem memo.y rowns


in tI>e

TIm ... funclion$

""'" """""

.JIe,

do'*" on _-..d.

FI",,,, U CPU Memnry A"'~.

The complete load memory is p~sent on tile MMG. meaning thlIt an MMC is al""ays requirW ror op=l.1ioo. The MMC can be used IS a portable memory medium for user programs or finn....= upd;!tel. Using special sY'tern functions you C3n ",ad or write data block!; on the MMC from the ~ prognun, for exam_ ple to ,."ad recipes from tile M\fC or 1 create a 0 measured-value arcbive 00 lh~ MMC Bnd to provide it witb data.

program in Ihe load memory is not processed as the eootrol program.

If a CPU does not ba~e. micro mo;mory card. the load memory is designed as I memory integnlted in tI:re CPU or as a plua-in memory caro. II ~.n be designed as a RAM or ROM.
Ifload mrnlOTY consists of flit inlq.ratcd RAM or " RAl\-1 memory card. a blrckup banery is required in order to 1c.C<.1' the ~cr prognlIIl retrnlh~. Where load memory i~ i1npl~memed .1 intcgnlted EE PROM, as a plug-in flasb EPROM memory card or as micro memory can!. the CPU ~an be opettled without bancry

I..oM memo ry d
The rntm user program. Including configuration data (system dati). is in the load memory. The U ""," program is 11 ...ay~ Initially transferred from the programmina device 10 the load mem_ ory. a nd from !hcre 10 Ille work mrnlory. The

backup.
From STEP 7 VS.l onwards, lind with appropriately designed CPUs. you Can save the com-

1. I Strucrure of the Programmable Controller

p lete project data as a compressed aRhiv... file in the load memory (sec Chapter 2.2 .2 "Managing, Reorganizing and Archiving"). Work
m~rn ory

o Timers (T)
Timers arc locations used to implement waiting and monitoring times.

o Counters (Z)
Counters are soJhvare-levcllocations, which can be used for up and down counting.

Work memory is designed in the fonn of highspeed RAM fully integrated in the CPU. The operating system of the CPU copies the pro_ gram code "relevant to execution"' and the user data into the work memory. "Relevant"' is a characteristic of the existing objects and does not mean lhal a particular code block will necessarily be called and executed . The "'actual"' control program is executed in the work mem-

o Temporary local daIS (L)


Loc atiODS used as dynatJlic intenncdiate buffers during block processing. Th~ temporsry loca l data are locatccl in the L stack, wh ich the CPU occupies dynamically during program execunon . The lett~'TS enclosed in parentheses ...,present the abbreviations to be used for Ihe d ifferent add...,sses when wriling programs . You may a lso assign a symbol 10 e ach variable and then use the symbol in p lace of the address identifier. The sy.tem memory also contain! buffers for conununieation jobs and system messages (di agnostics buffer) . The sile of these data buffers. as well as thc size of the process image and the L stack, are parameterizable on certain CPUs. Phy.ical de.ign of C PU memory The physi~al de.ign oftbe load m"",ory is d ifferent for the ,"ariou~ types of CPU (F igure 1.3). The CPUs w itb micro memory card do not have an integrated load memory. A micro memory card mu<;t always be inserted to permit operalion. The load memory on the micro m emory card reacts as if it contains RAM and ROM components . The program is transmitted and teSied completely nonnally in the RAM, Bnd then written into the ROM by means ofa menu comma nd following the test. Retentivity of the user program is achieved w ith Ihe micro mcmDry card . With Ihe CPU 3 17. pan of the work memory can be used for retentive data bl ocks. The rest of the work memory (complete memory less ...,tentive data quantity) Can be used for the pro-gram code and the non_retentive data. The integrated RAM load memory with the S7400 CPUs is designed for small programs and for modificalion of individual b locks ifthe load m emory is a flash EPROM memory card. If the complete control program is larger than the

NY
Depending on the product, the work memory can be designed either as 8 corrdaled a~a or divided according to program and data m emOries, where the laner can also be divided into retcutive and non-retentive memories. Whcn uploading the user program into the programming device, tbc blocks arc fetched from the load memory, supplemented by tbe a~tual values of thc data operands from the work memory (further infonnation can be found in Sections 2.6.4 "Loading the User Program into the CPU" and 2.6.5 "Block Handling"').
Sy't~m

memory

System memory contains the addresses (vari_ able s) that you a ~Ces, in your program. The a ddresses Qre combined into arcas (addre ss areas) containing a CPU-specific number of addresses. Addresses may be, for example , inpms used to scan the signal stBtes of mom en_ tary-contact switche, and limit switches, and outpUtS thaI you can use to control contactors and lamps. Tbe system memory on a CPU contain, the following address areas: ". Inputs (I) Inputs are an image ("process image"') of the digital input modules. o Outputs (Q) Outputs are an image ("process image") of the digital output modules . Bit memories (M) Store< ofinfonnation accessible throughout the whole program from any poinL

I $IMATIC S73OO/400 Programmab le Controller

51 300 and ET CPUs without adju stabl a deUt retentiv ity

Micro me

card

iC"'" '-____________--,_______-,Work m emory Program codl> Use< data System memory

l oad mamory RAM and RO M

57300 and ET CPU. w ith adjustable data ret.ntlvlty Micro "'.,," ca r<l Loadma mory RAM and ROM

,C,'"'--_____________________ ,
Work. mamolY Prog ram code User data Sy"em memory

non-ret&ntive Us-erdata
fele~tive

5 7-400 CPU M&m CI'lrd Load memory AAM

C'"
load memory

RAM

Load memory FEPROM

Work memory Program code

Systam ..... mory

Work memory Use r data

Figu .... \.3 Phy<ical Design ofepe Memory

integrated load memo!)', you require a RA"I memory card for te>t i~g. The test ed progrllm i, then transmitted by the programmi ng device 10 a Tlash EPROM memory card which you insert into the CPU for operalion. The work memory of S7400 cre, is divided into two pans: one part ,av~' the program code. the other th e user data. Th e system and work memories itt the S7-4OO CPUs constirnte one (physical) unit. If, for example. the jLze of the pfoI'~ss image change,. this has effects 011 the size of the work memory.

DF use, the PROFlliUS imbnctwork for daTa tnm omi,s ion. PROFTNET 10 The Industrial Ethernet subnetwork (for f""he, information, see Chapt~ 1.3,2 "Subnels'J.

1.2.1

PROFIBUS DF

PRO FlBU S Dr provides a standardized interfaee for transferring predominantly binary pro CO" data b etween an "interface module" in the (c eIltral) progranunabl e conlrol!er and the field devices. This "int"face module" is called T he DF maoter and The field devices are the Df

,h,cs.

1.2

Distrib uted VO

Distri buted VO refers to modules cor.nected via PROFlB US Dr or PROFTNET 10, PROF/RL'S

The DP maSter and all the slaves it control. form a D P maSter system. There can be up 10 32 'lations in one .egmen t and up to 127 stations in the entire nemork A DP master can control a number of DP , laveo spec ific to it.el f. You

1.2 Disuibtne<! I/O

can also connect programming devicu to the I'ROFlBUS DP network as well as. for tumpit. ,Jev;ces tor human machine interface, 1iT200 de\kts or SIMATIC SS DP ,la\",s.

IlP mastu
Th~ DP master is the IOCtive node on th~ PROFlBUS n~".vorL It exchanges cyclic data with "11'" OP slaves. A 01' master can be

c>

A CPU wilh int~grnl DP IIlltster interface or plug-in im~rtace submooule (c.g. CPU 31 ~2DP. CPU 4 17) An interlace module in colijunction wilh a CPU (e.g. 1M 467) A CP in conjunction with R CPU (e.g. C P 3425. CP 443 -5)

PROFIB US OP is usually opc,.,ucd Q8 a "mono lnllSl~r syslem". thaI is. one Dr mnster conlrols severnl DJ' .I~~e~. Tbe Di' maSter is the on ly tTU<.ter on tbe bus. with Ihe exception of a lemporarily a\"~il .. bk PJUb 'nWlIlliny dtvicc (dllanOSI;CS and $("",,;ce device). The DP ma~ler and the Of' slal'e~ L\Silned to il form a DP IlUblc-r system (Figure 1.4). You can al>iQ install several DP mastCT syslrms on one PROFlHUS .uhnel (multi mast .... s~. tern). Howe' er, IlIi< ine,..,aS("S the ""~iX>nse lime in indIVidual eaoe. hccause when a OP !1U\su,.r has initilllucd "its" or slaves. the access !'igh\.< fall to the " ex t DP masler that in tun, initializes "il ." or .<Iaves. elc. You can n.-dUCt Ihe response rime ira OP master system contains only a few OP sla\,("5. SinCe II i~ possible 10 opcrau: ~c"~TaI Di' IILIIS\("f$ in o~ S7 stalion. you can distribute the OP sllt'-es nfa slation o'-~-r >c'~,.,.1 Df' mailer '~Slcm$. In multiprocessor m<><k. eve')' CPU has its OWII Dr maSTer s)'Stems,

t>

to

The,.., are "Class I ma<tcn" for data exchange '" proceso op"rntion and "CIIO$$ 2 maSTers" for <ef\~c~ and diagnostics (e.j. a pNgTIlIDmiag
de"ic~)"

or .I~H'
The OP .Ial'es are!h~ passive nodes on PROF!nus. in SL\1ATlC S7, B distinction is made
bem'c~'Il

:>

Compacl DP slaves They behave like a sing le modtllc lowards the pr maSlcr

> Mod\dar Of' sla""" Th~y comprise severnl moo.lulcs (submodules)


t>

Tntelligent Dr 5Ia,"("< They contain a tnnJl'ol progr-am lhal trois The lower_level (o",n) mndules

COfI-

S7 ".floa "ltb DP ",,".r,

c=-~., .w.

<-8. Io--r 200Et

[)rlL)r

PROflBUSDP DP".. DPRSnlC link


DPAS-ln~

LiDk

'I

50",,! roD1I1;""

9,.. "'-'pr>tflu ... ~b Ii.... dioJII"'lk.

Fillurt 1.4 Comron<n'" of 3 PROFIBUS Of' Masltt SY'l<.m III lin RS4~~ sCiln.m.

I SIMATTC S7 3()(1!4()(1 Programmable Con""lIcr

Compact PROFfBUS DP slaw,s


Examples of 01' slaves includ e the ET200B (vers;on w ith digil,,1 input/output modules or analog inputioutpU! modulc~; degree of protee tion II' 20; max . data transfer ra!e 12 Mb itls). the ET200c (rugged construction IT' 66/67; dif ferent variant. w ith digita l inputs/outpUtS and analog inputs!outruts: data transfer Ta!e 1.5 Mbit/s or 12 Mb it/s) and the ET200LSC (di crete modularity with freely combinable digital input/outpu t modules and analog inputloutput modules; degree o f protection IT' 20; data tra~S' fer rate 1.5 Mbitlsl The bus gateways such as DP/AS . i link behave like a compact slave on PROFl BUS DJ'.

the number of stations ""d the cKponsion orthe suhnem-'ork can be increased. The repeater provides 'ignal regeneration and d.etrical i.olation. It can be operat.-d at trans m ission rme, up to 12 Mbit/s. including 4545 kbitls [orPROFIBUS PA. The RS 485 is nO! eonfigur~-J; it need only be considered when calculating the bu. parame ters, Dl a gn ostles rep ea t er Using a diagnostics I~pca t er. you can detennine the topology and carry outl ine diagnostics in a PROFlfIUS segment (RS 485 copper cable) during runtime. The diagnostics r~-peater pro-vide, s ignal cc!!yn~mtion and electrical i,olation of the Con1)ccted segment s. The maximum segment length is 100 m in cach case; (~e (rans mission rate can be between 9.6 kbivs and 12 Mbitls. The diagnostic. repealer has connection. fOT three bu. ,egment s. The cable from the DP mas!cr is connected to the infeed tenn inals of bu , ,egmcot DII. The two other connections DP2 and DP3 contain the test circuit, for deter mination of thc topology and line d iagnostics on the eonne<:ted bus segments. Up to 9 funher diagnos tics repeater, can be e01)ne<;ted in series. Tbe diagnostics repe ater is handled like a DP sl ave in tbe mast~r system . In the event of a fault. it sends thc dctennined diagnostic, data to the DP master, These are the topology of the b us segment (sta!ions and cable lengths). the contents of the segm ent diagnostics buffers (last ten event, w ith fault in[unoation, location and cau,e) and the ,tatistics data (statement on quality of bus ,ystem). In additi(m, the diagnos. tics repeat~r proviM, monitoring functions for isochronc mode. Thc diagnostics data can be fetched and also graphicall y displayed hy a programmi ng device w ith STEP 7 \/5 .2 or later. Line diagnostics i. triggered from the USer program by the system funclion SFC 103 DP _TOPOL. and read us ing SFC 59 RD REC Or SfB 52 RDREC. In order to set the clock on Ihe diagnostics re~at eI. you read the CPU time using the system function

Modular PROFIBUS DP Jlave.,


The ET200M is an example of a madular DJ' slave. The design corresponds to an S7300 sla lion with DrN rail. power supply, Th-f 153 '1l!e rface module instead of the CPU and w ith up 10 R , ignal moouln (SMs) Or function modules (FM'l , The data transfer cate is 9.6 kbitls to 12 Mbitls. The ET200M can al.o be de,igned with (.lcli,'e bus modules if the DJ' master is an S 7.400 sta lion. This means that the S7 300 input/output module. can be pl ugged in and removed during operation under power. Opera tion of the remaining madules continues. The mod ules no longer ha,e to be plugged in without gaps, The ET200M ~an b( used with the 11>.1 153-3 interface module as a slave in a redundon, bus, The 1M 1533 has rnro connec tions, one for the 1lT' master in the master station and une fN the DI' master in the standby station.

jntclligo:rll PROFfBUS DP slaws


Eumplcs of intelligent DP slavcs arc CP Us with an intcgral DP (slave) interface, or an 57 300 station with the CP 342 -5 communications processor. Equally, an ET200pro station with the 1M 154-g PN /DI' CPU interface N an ET200S station w ith the 1M 1517 CPU inter. face module can be operated as intell igent DP slaves . RS 485 '""p e ater The RS 4S5 rel"'ater combines two bus seg ments in a PROFIBU S subnet,vnrk. As a resu!!.

1.2 Distributed lfO

S FC I READ_CL K Rnd transmit it using SFC $8 \VR_REC or SFB 53 WRREC.


The {hasno~tic. repeater is configured and parameterized using STEP 7. A GSD file is available for opemtion on non-S~tAT!C ma.-

> A CPU with integral PROflNET interface


(e.lI . CPU 317-21'1'0101')
t>

A CP module in conjunction with a CPU (e.g. CP 343-1 )


dl" i e~

,=.

10

1.2.2

PROFIN ET 10

Th( 10 de,ices arc the passi,c stations 011 !he PROFCIlET.in the case of SIMATIC S7. these can be the modular 1/0 devices such a~
ET200M. ET200S and ET200pm. The gateways PK'PN coupler. IE/PB link and IEiAS -i link nre 1l1so 10 d~vices.
10 su pHviSQr

PROFINET [0 offers a itandardizro interface for transmi .. ion of mainly binary proces> data betwe~n an 'imerfaee module in the (cemrnl) proilranunablc comroller and the field devices uiinlllndustrial Ethernet . This "interface mod ule' is referred to as lhe 10 controller and the field deVIces as 10 deviccs. The 10 courroller with all the 10 devices oonrrollcd by ;1 constirute a PROFINET 10 syslem.
PRonz., I::T 10 system
A I'ROFINET 10 "ystcm comprises th~ 10 con_

10 supervisors arc dc\ ices for paramc'erization, Startup, diagnostics. and human machine imcrfacing, e.g. progmmming devi""s or HMJ de,ices.
1.2.3
Actuator/Sensor
lnlHrac~

troller in the cemral stalion and the 10 devices (field devices) nsigned to it. The Industrial Ethernet subuet connectina them clm also bc shared by other sUitions and applications (Figure 1.5).

10 controller The 10 controller is the BCtive station on Ihe PROFr'lET. It exchanges data cyclically with 'its' 10 devices. An [0 controller Can be:

II ne tworking system for the lowcst process level in automation plantS in accordance with ,he international standard EN 30295. An AS-i master controls up 10 62 AS-i sla"es vi. a 2-wiT(: AS-i cable ,bal carries both the contfQl signals and the supply voLUIge. (figure 1.6).

The Actuator/Sensor interface (AS-i) ;s

One AS-i ""gment can be up \0 100 m in length: in combination with T(:pcatcrs and e",tension plugs. a maximum e",pansion of 600 m can b(: achieved.

IE/ PR linJ.

I SIMATIC S7-300/400 Programmable Conuoller

"

PROFmUSDP

Indy,niol Etheme,

~ link

ASi IE/AS-; li"k

AS-i a<tu.""

AS-i .emo,

AS-i d"tributor

B;""'Y actuators a nd n<Ol'S ",';'0 ASiAS IC

Binary "motor< 000 S=or< without ASiASIC

runhc:r AS; do,'ioc,

FIgure 1,6 Connecting the ASi bu, 'ystcm to SII>lATiC S7 With "ASlnterface SafelY at Work", you can safety sensors such"" em. rgencY-<Jft' switches, door contact switches, or ",fety light arrays direct to the AS_i network up lD Category 4 in accordance with F.'I9541 Or SlL3 inaccor dance with mc 61508. This requires safe ASi slaves for connecting th~ ,afcty smoors and a safety monitor that combines the safe inPUIS with parame1erizable logi~ and ~nsures safe shut. down.
~onne~1

o module: It occupies 16 input bytes and 16 out

Inslandard mode,lh<' CP 3432 behaves li ke an l'

put bytes in the analog aililress area (from 128 upwards). Upto 31 standard slaves or 62 A/B slaves CilaV"" with ~xtendcd aJdross area) Can be op,:",t ed on the CP 343 -2. The ASi Sla'"C8 are paramc teri<ed wi1h default valllC' stored in the CPo In exle"ded mod~, the full range of functions in accordance with the ASi master spc~ification is available. If you use the Fe bl""k suppl ied, maSter calls can he made fwm the user program in addiTion to standard mode (transfer of parameters during operal;on, checking of 1he desired! .~lUal configurati on, test and diagnoslics) , AS I slin'e. AS; ,lave, can be bu.-enabled ,ensors and aC mator. with ASi AS ICs, or they can he AS; modul ~s. You ~Onnecl ,ensors and actuators with AS; ASICs to a passive module. Convon tional sen,ors and actuators can be connected to an acti,'e module. ASi ., laves ar~ available in the standard ,'~rsion with One standard sla,'c oc~upying one of the maximum of ) I possible addresses. The user program handles the standard slaves lil:e h;nary input> and outputs. AS; slave> with eXTe nded addressing mode (AlB slaves) ""cupy an address in pairs so that up 10 62 slave, can be operated 00 one maSler.

ASi master Standard ASi masters can control up lD 31 standard ASi , lave, with a maximum cycle lime 01'5 ms. In the ca, e of extended ASi mas lers, tllC quantity structur. increases 10 a maxi. mum of 62 AS-i slaves Wilh an extended ad dress area Wi lh a maximum cycle time of 10 ms. Slave, with an extonded address area occupy one address in pair,; if standard slaves al"<' operated on an extended master. they each oc cupy one addrc>s ,

The AS-I ma~lcr CP 3432 is used in an S7300 station or in an ET200M stalion. It supports tho foUowing ASi slavc-s:
c>

Standard slaves
Slav~"

""

wilh extendcd addre"ing mod . (AlB

slaves) "" Analog slaves to slave profile 7.3 or 7.4

L2 Distribmed I/O

"A slaves" arc treated like standard slaves. and "1:1 slaves" arc addressed via data records. AS-; AlB slaves can al80 a~quire and transfer analog "alues

Connecting PROFIBUS DP PROFIBUS PA

10

1.2.4

Gateway.

Gateways allow data exdmn gc k tween device, on different subnets, and the forwarding of configuration and parameterization in fonna_ tion beyond subnet boundaries (Figure 1.7). Conn.-cring two PROFIBUS .ubncts The Dl'lDP coupler (Version 2) conne<:ts m'O PROFIB US suboets to ~ach other, allowing you to exchange data berorecn the DP ma,ter'; , Both "ubnel< arc i,olated and can be operated at different data tram fer rates up to a maxim,un of 12 Mbi t/s , In hath .ubnets. the DPtDP coupler is as<igned to the relevant DP master as a DP slave with a freely sckctable node address in each case. The maximum size of the transfer memory is 244 bytes of input data and 244 b;1CS of outp ut data, divisible into a maximum of 16 areas.lnp.,l areas in one ,ubnct must correspond to output areas in another. Up to 128 bytes can be tm,nsferred consi,lently, If the s ide w;th the input data fails, the correspond ing OUlpUt data on lhe other side is tnaintained at its la't value The DPIDP conpl~r is configured and parameterized with STEP 7. A GSD tile i, available for operation on non-S iemens masters.

PROFlBUS PA (Praces. Automation) is a b.,< systcm for proce" engineering, halh for intrinsically-safc areas (Ex area Zone I). e .g. in the chem ical industry, as "ell as for non-intrinsically_,afe area< such as in the food and beverages industry, The protocol for PROFIBUS PA i, based on the standard EN 50170. Volume 2 (PROFlBUS DP), and lhe transmission technology is based on IEC 115H-2. There are two methods of linking PROFIBUS DP and PROFIBFS PA:
I>

DP/PA coupler. when PROFIBUS DP can


be operated at 45 .45 kbitls

I>

DP/PA link which converts the dala transfer ralC' of PROFlBUS DP to lhe data tramfer rate of PROFlBUS PA

The DP/l'A coupkr enables connection of PA field devices (() I'ROFlBUS DP. On PROFl BUS DP. the DPIPA coup ler is a DP slave that i, op<rntcd at 45.45 kbitls. Up to 31 PA field de" ices can k connected to One DPIPA coupler. The field devices fonn a PRQFlB US PA segment with a data transfer rate of 31.25 kbilis All PROFlBUS PA segment. wgetlJcr fonn a .hared PROFIFHJS PA bus system. The DPIPA coup ler i. available in two veT<ions : a non_Ex version with up to 400 mA output curren! and"n Ex version with up to 100 mA OUlPUI current.

PN.'?N ""uple'

T fJPB
link

Serial <oM<Clio"
FiIlU~

1.7 Gateway.

33

I SI\lATIC S7_300/400 Programmable Cuntroller The DP/PA link enables the connection of I'A field devices to PROFlBUS OF with data tranSfer rates belwccn 9.6 kbitls and 12 jl,fbitls . A DI'/I'A link comprises an J),.j 157 interface module and up to 5 DP/PA ~cmplers that a1"<' connected to each other via SIMATlC S7 bus connectors . It maps the bus system consisting of all PROFlBUS FA segments to a PROFI BUS DP slave. A max imum of 31 PA fie ld devices can be connected per OP/PA linl.. SIMATIC POM (process De\~ce .\bnager, pre" iously SIPROM) is a cross-vendor too l for paramet~rization, startup and diagnostics of in _ telligent field devices with PROFlBUS PA or HART functionality. The DOL (Device Description Language) is available for parameter_ izing HART transducers (Highway Address able Remole Transducers). From STEP 7 V5.1 SP3, the control technology modules arc parameterized with the Hardware Configuration; you must then no longer use SIMATICPOM. Connecti ng PROFIBUS 01' to the AS-I Ule rfate A DPfAS-Int~ rf:lce link "'Dable, the connection of PROfiBUS OJ' to the AS-Interface. On PROFIBUS OP, the link is a modular OP slave with a data Il1Insfer rate of up 10 12 .Mbitls in degree of protection lP 20. On the AS-Interface. it is an AS-i master that controls the AS-; slaVe!; , The link is available in the vers ions DPIAS_i Link 20 and DPIAS-j Link Advanced. The following AS-; slaves cao ~ c011lwlled :
t> t>

link suppon, the procedures 3964R and free ASCII protocol. The PROFlBUS OPfRS 232C linl< is connected to the dovice via a poinl-lo_point connection. Conwrsion to the PROFIBUS OP protocol takes place in the PROFIBUS OPfRS 232C link . The dala is transferred con,istently in both di1"<'ction<. Up 10 224 bytes of user data can be tnmsfe=d per message frame. The data transfer rale on PROFIBUS 01' can be up 10 12 Mbitls: RS 232C can be operated at up to 38.4 );bitl, wi th no pati ty_even or odd pati ty, 8 d ata bilS, and I stop bit. Connecllng two PROFlNET su bnets With the PN/PN Cou ple r, you connect two Ethernet subncts to each other in order to ex_ etlangc dam between the 10 controllers of both subne\S . The", is galvanic isolationlxtv..ccn the subnets. The PN/P:"oI Coupler is a 120-mm-wide module tbat ii installed on a OrN rail. The subnets are connected using RJ45 connectors. Two connections with internal switch functi on are available for each suboe!. From the "ie''''point of the relevant 10 control ler, the PNIPN Coupler i, an 10 device in its own PROFlNET 10 system. Both JO devices are linked by a data transfer area wim 256 input bytes and 256 output bytes, divisible into a maximum of 16 area,. Input areas in one subtlet must correspond to output areas in another The PNfDP Coupler is cont1gured and paranlC_ terized with STEP 7. A GSOML file is available for other con ilguring tools. Connection of PROFINET TO to PROnBl'S 01' You can connect the Industrial Etherne t subnetworks and PROFIBUS using the lEfJ'B link Pl\'IO. If you use PROFINET 10. me IE/ PB link PNlO takes over the role of a proxy for the DP slaves on lhe PROflBUS. An JO controlkr can access 01' slave, just like 10 devices us ing the IEIPB link. In standard mode, the lElPB link i, tran,parent for PO/OP communications and S7 routing ~twecn subnetworks.

Standard .bves. AS-i aMlol! slaves Slaves with extended a<klre"sing mode (AlB slaves) Slaves with data transfer mechanIsms in accordance with AS_i spe<: ificalion V3 .0 (DP! AS-i Link Advanced)

t>

C onnect ion of PROFlBCS j)p to a .erial interface The PROFIBUS DP/RS 232C link is a converter be!v.'een an RS 232C (\'.24) interface and PROFIBUS DP. Devices wi th an RS 2J2C inl<.>tface can be connected 10 PROFIBUS OP with the OPIRS 232C li nk. The DP/ RS 232C

1.3 Communications

The IF.JPB link PNIO is a double-width modul~ ofS7-3oo dcsign. The IEIPB link is connected to Indusnial Eth~rnet via an S-contact RJ4S socket. and to PROFIBUS via a 9-contact SUBD sockct . The IE/PB link is configured usins ST EP 7 as an 10 device lO which a DP master system is connected. When switching on, the subordinale Dr slaves are also provided with the configuration data from the 10 controller. Please note that limitations exist on the PROF!_ BUS DP following an IElPB link. For example. you cannot connect a DPIPA link, the DP segment does not have CIR capability. and isoch rone mode cannot be configured. Conn .. cting PROFlNET 10 to the AS_Interface

1.3

Communications

Communi cations _ data exchange betwe~"I1 progranunable modules - is an integral component of SlMAT1C 57. A lmost all communications functions are handled via the opernting system. You can exchange data without any additio nal hardware and w ith j ust one connecting cable between the two CPUs. If you use CP modules. you can achieve powerful network links and the facihty of linking to non-Siemens systems. SfMATIC NET is the umbrella term for SIMATIC communica1ions. It represents information exchange between progrnmmable conrrollers and between programmable controllers and human machine intcrface devices. There are various communications paths available depending On performance requiremcms .

I.J.! An IE/A S-i link enables the connec tion of PROFIN ET 10 to the AS-Interface. On PROF!NET 10, the link is an 10 device. On the AS-Interfacc. it is an AS_i mosier thai controls the AS-i slaves. The 10 controller can aCCe" the individual binary and analog values of the AS i slaves directly. Connection to PROF/NET is made via twO RJ45 connectors with internal switch function. The AS_lntcrfacc bus is conne<:tcd to 4-pin plug-in screw-type contacts The link is avail~ble in the versions single master ~nd double master (in accordance with AS-Interface sp:ification V3.0) for the connection of up to 62 AS-i slaves in each case and imcgra l analog value transfer. The following AS-i sla\'es can be controlled,
to to

Introduction

The most significant communications objects are initially SIMATIC stations Or non_Siemens devices between which you want to exchangc data . You require modules with communications capability here. With SIMATIC 57. all CPUs have an MPI interface over which they can handle communications.

In addition. there arc communications proccssors (CPs) available that enable data e"change at highcr throughput rates ~nd with different protocols. You must link these modules via nct _ ..... orks. ,\ network is the hardware connection between communication nodes.
Data is exchanged via a conn ection in aCcordance wilh a specifi c eXe<:U1ion plan Ccommunications ,crvice) which is based, among other things . on a specific coordination procedu: (" protoCor). S7 connection i5 the standard between S7 modules with communications capability. for example . Using an S7 connection, f igure 1.8 shows thc objects involvcd in conunun ication between rv.o stations. The uSCr program of the left_hand station contains the data to be lransmined in a data block (DB) . The conunun;cations function in the example is a system function block (SFB) . Assign the parameter RD with a pointer to the data to be sent. and trigger the transmission from the program. The communications

Standard slaves. AS-i analog slaves Slaves with extended addressing mode (AlB slav~s ) Slaves with data mmsfer mechanisms in accordance with AS-i specification V3.0

p.

The IE/AS-i link is configurcd and parameterized with STEP 7. A GSDML file is avajiable for othcr configuring tools.

1 SIMATIC S7-300/400 Programmable Controller

51 MATIC 57 station System memory

51 MATIC 57 station CPU User program Connection ID System memory

CP Operating system

Received data

Communications function

Bus interface of the module 5ubnet Con'lec:.tiQD

Connection resources

Figure 1.8 Data Exchange Between Two SIMATIC S7 Stations

function is additionally assigned a connection ID with which the used connection is specified. The connection occupies a connection resource in the CPU's system memory. The data are transmitted e .g . to a CP module in another station via the module's bus interface. Connection resources are used in both the CP module and CPU. Because of the connection ill (and the configured connection path) the communications function in the receiver station "recognizes" the data addressed to it, and writes them into the data block of the user program by means of the pointer in parameter RD . N etwork
A network is a connection between sev eral devices for the purpose of communication . It

Communications serv ice


A communications service determines how the

data are exchanged between communications nodes and how the data are to be handled. It is based on a protocol that describes , amongst other things, the coordination procedure between the communications nodes . Th e services mostly used with SIMATIC are: PG communications, OP communications, S7 basic communications, S7 communications, global data communications, PtP communications, S5-compatible communications (SENDI RECEIVE interface). Connection
A connection defines the communications rela-

comprises one or more identical or different subnets linked together. Subnet In a subnet, all the communications nodes are linked via a hardware connection w ith uniform physical characteristics and transmission parameters, such as the data transfer rate, and they exchange data via a shared transmission procedure. SIMATIC recognizes MFI, PROFIBUS, Industrial Ethernet and point-to-point connection (PTP) as subnets.

tionships between two communications nodes.


It is the logical assignment of two nodes for

ex ecuting a specific communications service and also contains special properties such as the connection type (dynamic, static) and how it is established. SIMATIC recognizes the following connection types : S7 connection, S7 connection (fault-tolerant), point-to-point connection, FMS and FDL connections , ISO transport connection, ISO-on-T CP and TCP connections, UDP conn ection and e-mail connection.

36

1.3 Communicat ions


l\ fP 1

Communicatiun~

function!

The communications functions are the u,er program's intenaee to the communications sen'ice For SIMATIC S7 - internal communications. the communications functions are integrated in the operating system of the CPU and they arc called via system blocks. Loadable blocks are ava ilable for communication with non-Siemens devices via communications processors O v.. rvl" w of communications objects Table 1.1 shows the relationships ~tween subnet', modules wil h communications capability and communications services. In addition to the commun ications services shown, POtOP com munications is also possible via MPL PROFlBUS and Industri al Ethern~1 subnets.
1.3.2

Every CPU with SlMAT1C S7 has an " interface with multipoint capability" (multipoint interface. or MP!) . It enables establi.hment of subnets in which CPUs. human machine interface devices and programmmg devices can e"change data w ith each othur. Data e"change is handled via a Siemens proprictary p rotocol. The ma"inuUl1 number of nodes on the MPI network is 32 . Each node has access to the bus for a specific length of time and may send data frames. After this time, it passes the access rights to the next node ("token passing acceSS procedure). As transmission medium. MPI useS either a shiel ded twi'ted_pair cable o r a glass or plastic fl~r-optic cable. The ma"imum cable length in " bus segment with non_electrically_isolated interfaces i, up to 50 m depending un the transmission rate. and up to 1000 m with e lectrically isolated imerfaces. This can be increa,ed by inserting RS485 repeaters (up to 1100 m) or optical link modules (up to'" 100 kIn). The data transfer ratc ;s usually 187.5 kbit!s. Ove r an MPI subnet. you can exchange data between CPUs with global dam communi cations. sllIlion -c" temal S7 basic communications or S7 communications. No additioual module. arc required. PROFIBUS PROFlBUS stands for Process Field Bus" and is a vendor_independent standard complying with lEe 61158/EN 50170 for universal autOmat ion (PROFlBUS DP and PRO FIBUS FMS) and for process automation aceording 10 lEe 61158-2 (PROFIBUS PAl. The ma"imum number of node, in a PROFT BUS network is 127. where the network is divided into segment.s wi th up to 32 nodes . A distinction is made between active and passive nodes. An active node receives access rightS to Ihe bus for a specific length of time and Olay send data frames . After this timc. il passes the access rights to the ne"t node ("token passing" aCCeSS proccdnre).lfpassive nodes (slaves) are assigned to an aClive node (master). the master c"ccutes data e"change with the slaves assigned to it while it is in possession of the

Sub nelS

Subnet' are communications paths with the same physical characteristics and the same communication~ procedure. Subnets arc the central objects for communication in the SIMATIC Manager. The subnets differ in their perfonnance capability ;
t>

MPI Low_cost method of networking a few SIMATlC devices with small data volume,. PROFTBUS High -speed e"change of small and mid range volumes of data. used primarily with distributed 110. Industrial Ethernet Communications between computers and programmable controllers for high_'peed e"change of large volumes of data, also used with d istributed II0s (PROFC'lET 10). Poim-to-poim (PTP) Serial link between two communications partners with special protocols.

t>

t>

t>

From STEP 7 Y5. you can use a programming device to reach SIMATIC S7 stations via subnets. for the purposes of, say, programming or parametcri"ing. The gateways between the subnelS must ~ located in an S7 station with "routing capabi lity".

37

1 SIMATiC S 7_300/400 Programmab le Controller

T_bl. 1.1 Communication,Objec"

SfC call'

"
BUS

Dr interrace

(DP ma,ter Of DP ,lave)

SFB/SFC call,.

.,
Station_ internal 57 basic commun icati ons CP )42_3: PROfIDUS DP VO CP 433 _5 Ext.: PROFIBUS UP VI

H.,.dwarc conliguflItion,
SF BiS FC call.,

CP 443 - ~

~xl...,d.d

- --

FMS int'-TIace CPU, with

Industrial

PROFINET 10 (10 controller)

"
TCP/lP and C OP.

CP44.11

CP343-11T 57 cr 4431 Advanced CP443 -1 1T

tah le,

38

1.3 Communicalioll5 access rights. A passive node <;\oxs not receive access righls The PROFIBUS network CRn al!l<) be physi~ally designed a.s an electrical network, optical nelwork or wireles couplina with various trans_ mission rates. The length ofa Sejmcttt depend. on the tranSmission ratc. ~ elcctrical network can be configured with a linear or!reC topology. 11 uSC!! shielded. rw;,\ed two-wire cBble (RS485 inlerfaee). The transmission rate can be ~djuS!cd in steps from 9.6 kbitlS 10 !2 Mbiti, (31.25 kbitls with PROflBUS PAl. The oplieal network L1ses eilher plastic. PCF or lila" fiber-optic cables. 11 is suitable for large distanccs, provides electtical iSOlation. and is insen~ilive 10 electromaanetic inlerferences. The transmission ntte can be adju<1cd in <1epS from 9.6 kbitl. 10 12 Mbits. When using <>pli cal link module. (OLMs), design:< arc possible wilh linear. ring or Star topologies. An OL:vI also provides the connection hClweC11 cltrical and optical networb wilh a mixed design. A co~t-opt itllized version is the design a.~ a linear structure with integral interface and optical bus Icnninal (OST). lising the PROFTRU5 infrared link module (ILM). sinille or several PROFIBUS sla,''''' or I~gments can be provided wnh a wireless con_ nection to PROnSU5 slu,cs. The maximum transmission rate of \.S Mb,,,s and Ihe ma.ximom rangc of IS til mean. ,hat commUniCalion i~ possible with moving parts, You implemcm connection of distribUlCd VO via D PROFIBUS subnetwork; the relevant PROHBL'S DP communic"ions service is implicit. You can ~ eitherCPUs with integral or plug-in DP master, or the rele~ant CPs. You cpn also nperate station-internal 57 basic com_ munications or S7 communications via this net_ work. You Can transfer data with PROFffiUS FMS and PROFIBU5 FDL us ina the relevant CPs. There are loadable blocks (F\15 interface nr SEND/RECEIVE interface) available as the interface 10 the user proaram). I nduSlrlal Et hernel Industrial E,hemet is the Jubnet for connecting complllcrs and programmable control lers, with tlte focus 00 the industrial area. defined by the intc-mational standard IEEE 802.3/802.3u. The standard IEEE 802.11 alb/gib defines the con_ ne<:tion to wireless local area nel\>fOrks (WLANs) and Industrial Wir.,]ess LAN. (lWLA1'>s). The number ofst8tionl networked using Induslrial Elhernet is unlimited; up to 1014 stations arc penni.sible per segment. Sdore accessin&. each nodc check-< to ee If anolher node is curremly tran,mining, !fthi. illhe case. the node waia for a mndorn time before attempting another access (C5MA/CD acces. procedure). All nodes have eq ual acce~.~ rillhts , The pbysical connections on Industrial Ethernet consist of point-Io-point conncctions bc1ween communication nodes. Eacb node is connected wilh precisely one paMer_ To enablc &e"eral nodes to communicatc with eacb othC'!". Ihey arc conntcd to a dtstnbutnr' (swilch or hub) Iha, has scveral conncctions.
A .,..-ITCh is an active bus elemcnl that regener_ Rtes signals, prioritizes them, and distribul<:s them only to Ihose devicc~ thai are connected to it. A h"b Kdjusts to thc lowest datu transfer rate at the ~onnttlions, and forwards all signals unpriOliti .. to all conne<:ted dcvices. .ed

The n~tworlt" can be confiaured as a linear. star. ITCC or ring topology. The dala tramlfer rates Ill"<:> 10 \'fuitls, 100 Mbitl$ (FRS! Ethernet) or 1000 Mbitfs (Gigabit Ethernet, not on I'KOFrt.'ET), Industrial Ethernet can be ph)'~ically designed as nn electrical n~"1",otk. oplical nctwork or " 'ireleu network. FutConnccl TWisted Pai!"$ (FC TP) "ith RJ45 connections. or 1ndu.~triaJ Twisted Pai!"$ (ITP) with sub-D connections are available fOf implcmcnlina Ihe electrical cablina. Fiber optic (FO) cabling Can consi" of alass fiber. peF or POF. It ofT~n galvanic isolation, is impervious to elei.:.romagnetic influences, and is suilable for long distaJlccs. Wireless .ransmission uses the frequcn cics 2.4 GHz and 5 GHz with data transfer rates up to 54 Mbitll (dcpending on the national approvals), You can cxchange dala with 57 and IE communications via Industrial ElMnIe{ and utilize the S7 fUDCtions. With appmpriaICly designed modules. you can also establish ISO trnnspnn connCCtions. ISO-on-TCP connc~ t ions. TCP, UDP and e-mail connections,

"

I SIMATIC S,_300/400 Programmable Controller

PROFII'I,'ET PROFINET i~ the open InduslIial Ethernet slanJard of PROFillUS International (PNO) _ PROFINET use, the Industrial Ethernel subnet a, the physical medium for data trmsmission, taking into ac~ ounl the requirements of indClStrial autolllillion . For examp le. PROFINET offer. a real_time (RT) response for eommWlication:; with field devices. and isochronou, real_time (IR1) transmission for motion control appl ications. Compatibilily with TCFlll' and the IT '1anda~ of Industrial Ethernet are retained. Siemens applies PROFlNl:T to two automation cOllcepts:
~

AS- I nt~rface

The AS-Inlerfacc (.duatorlscnsOf interface , AS -i) networks the "ppropriately designed binary S<;"tlsors and actuators in accordance w ith tbc A S-lmcrface specification lEe TG 178. The AS-Interlace docs not appear in the SIMATIC Manager as a suimel, ""Iy the AS -I master is configured with the hardware configuration or wi th the network conliguration_ The transmission medium is an unshielded twisted_pair cab k that ,upplics th e actuators and sensors with both data and power (power s upply r"'1 uircd). Netvwrk range can be up l<> 600 m with repeaters and extension p lugs The data transfer rate is set at 167 kbitls .

Component Based Auramalian (CllA) uses


PROFINET for ~ommunicat ion bem-'e~n control unit, as components in di,uibuted systems . Th~ configl!Talion tool lS SIMATIC iMap_

A maSter ""nlrots up to 62 slaves thro ugh cycli c scann ing and w gmlmntee' " defined ""pense "me.

PROFfNET 10 lISes PROFINET to transmit data to and from field d~Yices (dimibuu:d 110). "Ibc con fi guralion tool is SIMATiC STEP 7 .

1.3.3

Communication s ServlcO/"S

Point_to-poiut

eonn~eti"D

A poiut-IO-point connection (PTP) enables dala uchangc via a serial link. A point_to_poinl CO llnection i< handled by the SI.MATIC Manager "s a .nbnet and configurc<1 ,imilurly. The tran"nission medium is an electri(al cable with int~'tfac e_dependent assignment. RS 232C ( V.24), 20 mA (TTY) and RS 4221485 are available a, interlace,. The data transfer rate is in the range 300 b it,,). tu 19.2 kbith with a 20 rnA interface or 76.8 kbit/s v.;th RS 232C and RS 42214~5. Th~ cahle length depends on \he physical interface and the dIlta transfer rate: it is 10 m with RS 232C, 1000 m w ith a 20 mA interfuee at 9.6 kbitl. and 1200 with RS 4221485 at 19.2 kbitls_ 3964 (R), RK 512, printer drivCl"S and an ASCn driver"", ""ai iable as protoco ls (proc cdur<"). Ib e latter enabling definition of a u,er_spec ific procedure.

Data exchange over \he "ubnets i, control led by different communications servic e, - dq>cnding on the connection sdcetcJ. The services are provi ded by the CPU ,>r CP modules _ In addi lion to communications wilh ficld devices (PROFIDUS DP, PROFlI:IUS PA <HId PROFl/'>.'ET 10, so:.: Chapler 1.2. I "I'ROflI:lUS DP " and t. 2.2 --PROFINET 10"), the service, listed be low arc available depending on the mooule u>ed.

J'G communication .
1'G communicalions i, used to exdlllnge data between an engineering station and a SIMATIC sta tion . II i. used. for example, by a programming device in online mode 10 C"Xe<:U1e the function, "Moni tor variables" or " Read diagnostics buff~r" or to load user programs . The ~ommuni ca tions functioru required for PC; commun ication, arC integrated in the operating system of the SIMATIC mooules . PG communications Can be c."'e<:uted over the MPl, PRO FIBUS and InJu,mal Ethernet subnets. By applying S7 routing, the PG communications '''III aho be used beyond , uhneK

1.3 Communications

OP communic ation>
OP con>m"nkations i~ us~d to ~xchallg-e data between an operator stat ion and H S!MATIC statim' , For example, .1 io "sed by an HMI oe~iec for opcmtion ~n,j monitori!\g. or 10 read and Wrile variablcs. Tbe eomml.micatio!\s functions requircd for OP commll!\;cation~ are im,,gn.tcd 'n the opcratina system of the SL\{ATIC modules. O P communicauons can be excculcd overthc Ml'1, PROFlB US and l ndu~tri"l F ibernel ",hocts. S7
bY~lc

conlanee wi ,h RYC 793.1S0-<Jo-TCP in accor' .... nee with RFC 1006. ur UOP in accordance WI th RfC 768 . Th~ C(Jmmunication functions are luadablc runction h locks (fH~) containeo in the Smmh",J Ubra'Y of STt::!' 7 under Comm,, tliClllimr Block. The function blocks are c"lIed in the main program and they control eO'.mC'CItOn buildup ""d c1"ardown as ",ell a, <!ala transfer,
Glohal dara
communk,.tlon~

communicatIons

S7 \)asic eOmJl\oni<Hlion~ i~ an e,em-conlrollcd .oeMc" forexchanging ~mal1 volume, of oata he\v.ecn " CPU and a module in the same SIMATlC station ("statiouintemaJ"') or between a CPU and " m<..M.lule ,n a different S I'\1ATlC station rstalion-<:=xlemal"). The con nections are established dynnn>icaUy when required. The communicillion~ fun ctions rO'l"i,...'<1 for th" S7 basic communicati ons are integrated in the opcratina sy.tem of the CPU, c,g. you triggcr thc data traM fer in the user pro Iron! by mca!\S of system funetio'" SfC. StatiOll.internal S7 basic communications is necuted ov~r PROI'I HUS, .lJItion-c:xt~m81 oyer '\1 PI.
S7 cn mmuuic"tion,

Global data communi~ation. enahles e~~hange of~mal1 volumes ofdalli between s~veral CPUs with out ~dditional proirammin.: overhead in the user pro.:".m. Transfer Clm he cyclic or evenl.dri>'cn. The commulU~ali,)ns function. I'C'qUlred an: inregrated tn the openti".: system of the CPt:. Global <lala communicarions is only poII~iblc ov~-r rhe MPI bu. or th" K bus.
PIP C(lmmllnicatioDS

I'll' commun ications (poi~t.to point connection) \Tnnsfe~ data o,~r. ~crial intCTfa~e. e,g. hem-'een a SIVIATIC slition and a printer. Thc cummunications functionti requi red arc intcb'1'llted in th~ operating sy.tem. e.g. as system fW'lction blocks SFB. Olla uchan.:" is prn;siblc tHing various tJaru<fer procedurn. SS-i:(lmpatible
~omm"nICltl ... n.

S7 ~('mmunicati(m";' an cvenl ..controlled service for exchanging laracr v()lume, of data bc!We~n CPU modllles with c()!\trol and lIl<mi. toring funeti()n, . Th~ connections are .\.iuic. and ~rc programmed using ST EP 7. The commUnication. furn.-tiuru. required fO'l" S7 communieanons arc cuh~-r integl1l1led In Ih~ o~ ...tinll ~}'$Icm of ti>e CPt: ($}ostem function blocks S FB) 0>" they are loadable function block>; (FB). S7 ""(Immunic,tion. can be: c~ccutcd o,er the Ml'l, PROFlBUS anrll.ndu>tri~1 Elhe rnet subnel s.

fF: communlcatlon
WiLh "'Optn eommuruclttion via lndu5lrial Eth,,",cl (IE communicatiOn fO'l" shon). you tJ<tmfer data b<.-tween tv."\) devices connC'Cted to the Ethernel SlIhnel. Communication can be implemented using the protocols Tel' nativc in 8C-

S!.compaliblc C<Jrnmun ications is an eveplconlrQll ed se,""ie,," for dUh' tr"nsfer tx.--tw","n SI\.1 ATIC "ations and non.SIMATlC station., The connections are shuie, Ind areprogratnntCO tHing STEP 7. The C(Jmmuo ications functions are usu~lly load"blc functioD5 FC with wbich you can control the transfer from the user pmIIl"rn. nata are ...,m aDd rccei""d OYcT the SlN"DIRECEIV E intcrfllce. and data can be fetched and written over thc rRTCllfWRl T [l int erfucc (S7 is a passive p"nner) . S5 -cQrnpatible ~ommunicati0n~ Cull be implcm~nted witb Industrial Ethernet usmg the Tel', ISO on TC I', lSO tl1lnsport and UOI' connectio,,~, and with PROrlBUS using FDL
Slanda r d co mmunk,.,loM

Standard communicatiuns n~l'$ standardized, wndor-indc~ndent protocol, for m<la transf.. .,..

41

I SI.MATIC S7-3001400 Programmable COnlroller


PROF'lBU S F'MS (Fie1dbus Mc:....ge Specification) provides services for the programbaicd, device-indcpcndctlt ttansfer of suuccured variables (FMS variables) in accordance with EN 50170 Volume 2. Oam exchange is carried QUI using &tatic FMS connections over a PROFIBUS subnel. The communications functi on' arc loodable function blocks FB with which you COllirol the transfcr from the user program.
basic communications, you define the panncrs via the node addresses.

Conn ecrloo resoon ...


Each connection requires connection I\.'$OUI"I:CS on the participating communications partner for Ihe en d point of the connection or Ihe tran_ sition point in a CP modulc. If, for example. S7 functions 8re executed via a bus interface orlhe CPU, a connection is aSlligncd in Ihe CPU: the i;IIIlC functions via the M P! interfaco of the CP occupy one connection in the CP and one eonncclion in the CPU_ Each CPU bas a specific Dumber of pos:sible tOnnectiorul_ Limitations and rules CJlist rcgard_ ing the use of connection rt'SOUl"CCS. For eltampie, not evCTY connection rc5OUt"a! can be u.sed for every type ofCQnne<:tion. One connection is reserved for a progranuning device Bnd one connection for an or (these cannot be used for any other purpose). Connection resources arc also required temporarily for the "non-configull'd connectiolU" in 57 basic communications.

Using an IT communications processor, S tMATle station;" linked to the IT ~'Hfl"'unl ullo n . Tnmsfer over Industrial Ethernet comprises POIOP/S7 communications IIDd S5~om patible CQmmunieations (S END'RECE lVE) with the ISO, TCM P and lIFD U1lrI~port protocols. It is additionally possible to use SMTP (Simple Mail Transfer Protocol) for e-maH!, HTTP (Hyper Text Transfer Protocol) for ItCcen using Web browsers, and FTP (File Transfer Protocol) for program -controlled data nchRnitc with devices from diffcll'nl operating systems.
1.3.4

Co nnections

A connection is either dynalnic or slolic depending on the communications service selecled. Dynamic connections are DOl configured; their buildup Or c1eardo""." is e' ent-dri\ClI ('"Communications via non-configun.:d connections"). There can only ever be one non-conftiured connection to a communications pamer Stalic oonnections a~ configured in Ihe conneclion table: they are built up at Stl<rtup and remain throughout the entire program execution ("communications via configured connection~"). Several connecl ions caD t>e established in parallel \0 onc communication, partner. You use a "Connec!ion type" to select the desircd communicat ions service in the nct","OrIc configuration (see Chapter 2_4 -"Configwmg the N~

1.4
1.4. 1

Module AddrcsSf.'S
Signal Pat h

When you wiTC your machine or plant, you determine wltich signals all' connected whert' on the programmable comrol1er CFigun: 1.9). An input signal, for example the signal from momentary_contact switch +l tPOI- S lO. the o ne for "Switch motor on". is run 10 nn input modul . wh.r~ it i, connecled to a specific lenninai. Thi~ terminal has an "address" called the 110 addrcs. (for instance byte S, bit 2). SefOR every program execulion Slart. the CPU then amomatically copies the sianal to the proeen input image, where it i5 then accessed t i an "input" address (I 5.2. for example)_ The cxprcs.ion "[ 5_2" is the absolute addrt'Sl. You can now give this input a name by "$ign_ IDit an alphanumeric symbol coITcsponding to Ihis input signal (such as "Switch motor on") to the absolmc address in thc symbol table. The

w<>ri<..,.

You do n()I need to configure connections ",'im the ~twork configuflnion fOJ global data communic.tions and PIWFlBUS DP or forS7 basic communications in the case of S1 fu~tions. Vou define the communications partl1CN for IIlobal datK communications in Inc global data table: in the case of PROFIBUS DP and S1

1.4 Module

A~

" HPOI . L _SIO ( ..

,~,

modulo

.,

0

,,Byten

., "'
.,

,
Byf1I
n~ I

~'

.,..

.
----

Process-image

. .".
11 -+

1234 56 7

-, ._.
r

start add", . .

~".

i:
U.", P
~ s_ c "

.""

.,...

",,",a

Abso"'t"

.... m (LAD)
on mo lor"

!"11m IFBDl USII' ~ S ... ;tc:h on motor"


,,~

15.2

II

II

-:::0-:::0-

I'lgu,,' 1.9

Co",,!ution ""<",,,,,n Modul. Add.r<: . AbwlU1e Add, nd Symbolic Add, ... (P.,h of a Signal from Sonso< 10 s.canll;lIi III the Pmg""n) eltpl"C$$;on "Switch motor 00" is the symbolic addro:ss.
1.4.2

signal and eac h serial connection in tbe system hlu liS own unique addres~. Correspondingly, dislribuled UO modules also have a "geographical address". In this case, the number Of me DP master sys tem or the PR O F! /'-'TIT 10 system and the station nutnl:>er replace the rack number. You u~e STEP 7'5 "Hardware Configuration" tool 10 plan !.be hardware configuration of an S7 station as pcT the physitallOClltioo ofthc modules. Thi s tool also makes it Jl'O'Isible 10 set Ihe module start addresses and paramet"ri'!e me modulcs (see Chapter 2.3 '"Co nfiguring Stations").

S lo t A ddress

Every slot bas a fi xed uddress in the progra mmable controller (an S7 stalion). This slot addreu cons;",s of the number of the mounting rack pnd the number of the slot. A module ;s uniquely described using the slot address ("geographical addressl. If the module contains interface cprds. each of these cards is also a~sii"cd a submodu1e add ress. In this way, each binary nnd analog

I SIMATIC 57_3001400 Programmab le Controller

1.4,3

Logical Addu"

1.4.4

Module St art Add res.

The logical addn:ss correspond, to the absolute address, U is also referred to as the user data address. for you uSe this aJJrc,s to access the user data of the input/output modules in the user program, either via thc process image (inputs I and outpulS 0) or direclly Qn \.be modules (peripheral inruts PI and reripheral outputs PQ) , The range of logical addresses comm~'IlCCS a t 7.cro and ends at an up!>"r limit ,pecifIC to I.hc CPU With digital mooules, the individua l signals (the individual bil<) a", combined into bWlChe, of g, rererred to as bytes. Modules exist with one . two or four bytes. These bytes have the relative addres"'s 0, L 2 and 3, addressing of the byte, commences at the modules stan address. E.umpie: wi!h a digital modnle with four byles and the ,tar! address 8, the individual bytes with add"",,,,s 8, 9. 10 and 11 addressed , Witb analog m<>dules, Ihe individlllli analog <ignals (voltages. cur",nts) are referred to as "channels", each of\vhich requires two byte,. Derending on Iheir design, analog modules cmt with 2. 4. S or 16 channels wrt'Csponding to an address range of4.l;.16or32bytes.

n'e module start address is the smallest logkal (user data) add,e",e, of a module : it idcmifi"s the relative byte zero of the modu le , The fol_ lowing module bytes are then assigned succcs,iv ely with addrcsses .
In the case o f m ixed modules containing inpu1 and output f""ge, . the lower range start address is defined as !hc module star! address . If Ihe inpot and output range, have the same start addn:. u<;c Ihe input address ,

Using th e hardware wnfigurm ion. you determi ne the position ortbc US<.T data addresses in the address volumc or !he CPU by defining Ihe modul~ "an addressc . The lowest logical addre" is also Ihe moduk .tart address for Ihe modules of the distributed JIO and even for the virtual siNS in the tIlIn.fer memory of an intel _ ligent DP , lave The modules ,tan addrcss is used in many cases to identify a module. Other than thi', it has no 'peeial meaning ,

104.5

D I"gn ostics Addrc ..

Usitlg Ihe hardware configw-ation, you a,sign a logical addrc",~'S to each byte ora us<:d module. The address'" a"" assigned as standard starting at ~cro, but you call change the proposed add","" The logical addresse, ohhe individual modnles mll", not overlap. Th~ logical addresses are defined sqmralcly for \.be input and QUlput module.', so that an inpnt byte can have the same number as an output byte, The user data or Ihe distributed 110 an: also addressed in hyles using 3 logical address. In onkr to guaram"" an unambiguous a"ignmcnt of all user data of a CPU (or more exactly: all u",r data on a P bus), the logical aJd",sscs of Ihe distribuled 110 must not overlap with Ihe logical addresses of the central module<;
It i. usually the case thaI the digital modules arc

Appropriately equipped modules can ,upply diagnostics data that you can evaluate in your program. If ccntrali/.ed moduks have a user data address (module start address), you accesS 1he module via thi, addre.s when reading !he dia"'1l0Sli ~s data. If the modules have no USer data addn:s> (e.g. power supplies), or if they are part of Ihe distrib uted VO. thm' is a diagnosti cs add""" for this purpose. The diagnostics address is alw,"ys an address in Ihe 110 input arca and oC~1,!pics one byte. The mer data length of th is address is zero; if it i, located in the process image, as is pennillcd, il is not taken into account by th~ CPU whCl1 updating \.be pro<:css imag e. STEP 7 automatically ""signs the diagnostics address counting down from the highest possible 110 addres,. You can change the diagnostics addre~< with \.be Hardware Configurdtion funeIton The diagnost ics data can only he read w ith speci al system functions: accessing this add,..,,,s Wilh load "8Iemcnl, has no effect (see also Chapler 20.4 "Communicati()ll via Distributed VO").

assigned ac"ording to addrcsses in the process image so Ihat thcir .,i gnal <latuses are automatically updaled and they can be add"""ed u,ing the address area, "Input" and "Output". Analog modules . FM modules and CP modules are assigned an address which is nO! w ithin the process un age.

1.4.6 MI'I

i\dd...,sscs ror

Ru~

"odes

I>

Ibe L Stack. (sec Chapler III.I.S " Temporary Local Data")

Module. that arc nodes on aD M l'l ne t,,"or\: (CPUs. FMs an d CP S) also have an " '11'1 addren. This address is decish'e ror !he link 10 programming devices. human machine interface devices and for glob.al data communicalionl. I'l~asc nOle lhat with older revision levels ofthc 57_300 CPU . !he FM and C I' modules oper. aled in Ihe .arne Slat;on receive Hn MPI address derived fro m the MPI addrc~s of the CPU. In the case of newer S7-300 CPUs. the MPI addre.sc, of FM aod CP mndulc~ in thc ,ame sialion can he detennined independently oflhe MPI address o f the CPU. VKOf'lBUS DP EliCh 01' lItation (e.g. Dr maSter. DP slave. progTanuning device) on the I'ROFIBUS also has a node Md dre~s (station number) with which it can be unambiguously add resS\:d on thc bu s, I'ROFn<'ETIO Staliom on the Industrial E.thcrnct havc a faelory-SCt MAC . dd",~, ",hich is unique world_ wide. An II' ad d l"fi~ is addillonally reqoired for identification on the bus. and ,s configurcd for the 10 cOlltroller. Thc II' addresses for the 10 dc"icc~ are deri ved from thc ll' addr~ss of the 10 cOntrol ler. The 1 comrollcr (thc ,n ter0 fdce) an d each 10 device i~ additionally assigned a dl"'"jce na nw. The 10 device IS addressed by the user program by m~anS of a dC" lcc number (stalion numbcT).

To this are added the code an d data bloch with the block.local variabl e~, depending Oil the user program.
1.5.1
addrcs~

User Data

A~a

In SlMATIC S7. each module can havc two areas: a user dala ar~a. wbich can be directly addressed with Load and Transfer Stalemems. and a syslem dala area for trallsfer_ rillg data records. \\'hen modules are access~"<J. iI makes no diff""TenCe wh"ther they are in 11I~k.s with centralized configuration o r uS<."<:I as distributed YO. All modules occupy the ~me (logical) add~s space.
A module's user data propcTtie! depend on the module type. In the case o f sill nal modules. they nrc either digital or Bnalog input/output ~igllll l s. and in th~ ~HSC offu nctio n modules and COllununications processoN>. Ihey might. Inr uarnple. be conlro! or Rtatus infonn ation. The "olume of user daQl modu lc-Hpeei fic. There are modules tha! occopy onc. t .... o. four or more b>,es in this ...-ea. Addressing ah'1IY. begins at rcl~thc byte O. The address o f byte 0 iJ the module <tan address: it i~ 5tipu lated in the coofiauration table.

'S

The user data represent the VO address area. divided . depend ing on Ih e dir<:ctiot! oftrnnsf~T, inlO peripheral input. (1' Is) and periph".,-al OUIpulS (PQ5). If the us"r data arc in the area of the process imag ..... the CPU automat ically hand les Ihe rrunsfcrs when updatinillhe process images. Pe rlphcra l lnpurs

1.5

A ddress Areas

The address areag available in every programmable cuntrolkr are


!>
I;>

the peripberal inpulS and outpul'o Ihe process input image and the process out_ put image Ibe bit memory area Ihe timer and eounler funclions (scc Chaplers 7 '""Timers" and 8 "Counlers"')

You use the peripheral input (PI) address area when you read from Ihe user dala area on input modu l c~. Part of'he PI ad dress area Icad. to the proces' image . This part alwuys l>cg in. at I/O addreu 0; the leogth of the an;a is CPU-specific. Wilh a Direct liO Read Opcllllion, you cllll the modules whose intcrfaces do not lead to the proces< Input image (fOT instance nnalog input modules). The signal stateS of modu les that lead to Ihc proees. inpm image can also be r~ad with a Direct Rcad operation.
acce$~

!>
I>

I SIMATTC 57}00/400 Programmable Controll..-

The momentary signal states of the input bit ,

an: then ,ca nned. Please note that thi' 'ignal


st"le may differ from the rdevant lnPuts in the prOCe>S image ,in~c the proc~S5 input im"g~ is ur<ioted at The beginning of T program ,caD. he Peripheral inputs may oceupy the saf"e ab,,," lute addre>ses a, peripheral outputs .

additional memory area sitnilarto the bit m=OIy area. Thi, appl ies both for the process input image and the process OUtpUT image.

Pcrlpbc"aloutpuIS You u,e the peripheral outpUT (PQ) addre,s area whe"Jl you wriTe vnlu~s to the u'er data a~a on an OU(plit module. Pan of the PQ add~8s area leads TO Tbe process image. This part always begi ns at 1/0 address 0; the le ngth of lhe area is CPU_specific.
With a Dire<:T I/O Write operaT ion. you can a~cess modules whose inK'Iface, do not lead to the process outpul image (su~h as analog output modules). 1bc sig,;al states of modules ~on' trolled by th~ process outr\lt im:.g~ ~an also be dir""lly aITcctcd. The signal statcs of the outpu1 bils th~n change immediately. Please nOte tha1:' Dirc~t I/O Write operation also upd ates the sig nal S!.a\ CS of (he ~levant modules in the process output image! Thm. there is no di fTercnce betwcen the rrocess OUtpUT image and the sig. nal S!~tc~ on the output module .

On suitably oquirped CPUs. say. the CPU 417. tile size of the proce-s image can be parameterized. If you enlarge the proc~ss image, you reduce the size of The wOIk memory accord ingly. Followin g a change 00 the ,iu oftl'c pro cess image, the epe c"~eute, ini\iali zatioll of the workmcmory, with the same effe<:t as acold
t~ S \art

Inp uts
An input is an image of thc corresponding bit on" digiml input moduk. SC>UIJling an inp ut is th~ same as .canning the bit on 1he module it,clf. PriOI to program C~CCllli on in every program cycle. the CPU'~ operating sy'tem copie, the , ignal ,tate from the module to the proce" inpUT Image.
Th~ use of a proce.s input image has many adv "mages:

<> Inputs can be scarmed and linked bil by bil (liO bits cannot be dircctly adilie,,,,d).
I>

Peripheral OUtpUT' em re",rve the some obsolute addr~sse s as peripheral input'.

1.5.2

Process Image

Scanning an input i, much faster lha" acce>s in g an inp ut module (for cx~mple. you avoid the transient rce"vcI)' 1ime o n the lIO bu" and {he system memury rc,ponse times are ,'horTer (han the module's response times). The pmgram i, therefore CKC<:UTCd that much mo~ quickly.

The process image contain! the image of \.he digital input and digital outpUt mooul." and is thus divid~d into proce" input image and proce," OUTput image . The process input image 1 .' ac~e"ed via (he addre', area for inputs (1), the procCICS O\J (PUI image v ia the addrC:ls arca for Oll(PUlS (Q). A. a rule, t h~ machine or process i, ~on(roned via the input' and outputs . The pr,x".. image ean be divided into suhs idiary proce" images that can be urJa,Ied either a uOOmatically or v ia the user pmgram. Please r<feT 00 Charter 20.2. 1 "Proce>s lmag: Updating" for more details. On the S73UO CI'U, and. from IO/9 ~. "1'0 on S7--400 CP Us, you can usc (hu addusses ofth. proce>s imagc not occupied by modules as

,. The signal State of an input i, \.he ,arne throughout the em ire pro"'ram cycle (the,"" is data cons i,tency throughout a program cycle). When a bi : on an input module change;;, Th e changc in the signal ;;tate i.' trans ferred TO thc inpu t at the ,tart of lhe next program cycle. " lnplll, can ab o be set and re.et becaus e they are localed in random access memory. DigiTal input mod ules can only be rcad . Inputs can be set during debugging or startup to sim ulate ,Cn,OI Slates, thus sinlplifying program tes ting.

advantage, arc offset by an increased progwm re'pome time (please also refer to Chapto: 20 .2.4 '"Re;;ponsc Time").

"Ib~,;e

1.5 Address Area.

Outputs An outpu t is an image of the corrc'p,mding bit on a digi tal output module. Setting an output is the same as setting the bit on the output module it self. The cpe's operatin g system copies the signal state from the process output im age to the module . The use of a pn)l:e" output unage has many advantages:
~

In th e case of direct access to user dala (loading and lransterring), the d ata are rcad and wriltt:n as b yte. won! or doublcword. The load and tmns f~,. instruetiolli<. upon which the MOVE !>ox w ith LADIFBD and the as~ignmcnt ofvariabIe s w ith elementary data types w ith SCl_ are ba;;ed. arc desi gned as interruptible . J f you w ish to transfer a data b lock wilh morc than four bytes w ithout interruption belween system memory and work memory. usc the systcm fu nction SFC g I L'BLKlVlOV. Data tran sfer betwcen a DP slave and DP master is cons istent for a complele slavc cven ife.g. the tran<fer area for an intellig~n t DP slave i, di" ided into several consistent blocks. Data cons istency with internode communication is the same as with direct a~~CSS (I -, 2- and 4- byte consistency). This similarly appli es to data transfer between 10 controller and 10 devic es on Ihe PROFTNF.T 10. When configuring stations of the distribut~-d VO w ith three or more than four bytes of user data, you Can specify th e con.istent user data "reas. T hese areas are tran, ferred consistent 10 the parameteri~ed target area (e.g. data area in wo rk memory or proc ess image) u,ing the system functions SFC 14 DPRJ} DAT and SFC 15 DPWR DII.T. P lease note that the "normal" updating of proc ess image. can be interrupt.. d folluwing each transmi tted doubleword. An exception wilh newcr CPUs is tile ,ransfer of user data blocks for dimibUled 110 using a partia l procc~. image if the u s", data b locks can be configured as consi"ent using the hardware configuration . You can also influence th~sc data blo.:;ks in the process image using a direc t access. but you could also possibly d~"roy the data consistency. C PU-specific data apply to the maximum size ofa consistent ar.. a for data transfer with global data communications. S7 ba s ic communication, and S7 comnmnications through thc op"rming system (s~e Tcchnical spec ification< in the C PU man llal). D iagno"ic. data and parameters are always transferred consi ~tell1ly in data records (e .g. d,agnosucs data ",nh the SfC 13 DPM RM DG or SFH 54 RALRM. or parameter data tran.ferre..! \0 and from m odules w ilh the SFB 52 RDREC and SfB 53 WRREC) .

Outputs can be set and reset bit by b it (direc\ addressing of L10 bits is not possible). SeUin g an output is much fasler th an acc e ssing an output module (for example . you avoid the tramiem reeove.-y time on the L10 bus. and the system memory response times are ;;horter than the modulc response times). The program is there fore e~eeuted that mu~h more quickly II. multiple s ignal state change at an oU!put during a program cycle does not affect the b i\ on the output module. It is the signal state of the ou!put at the end of lhe program cycle that is transferred 10 the module . Outputs can a lso be scanned because they are located in random access mcmory. While;t is possible to write to digilal output modules. it is not poss ib le to read them. The scalming and linking of thc outputs makes additional storage uf thc oU!put bit to be scanned unnecessary.

"

These advantages are offset by an increased program response time. C hapter 20.2.4 "Respon se Time" describe~ how a programmable con troller'~ response time comes a!>out.

1.~ .3

Consistent User Data

Data cons istency m eans that data can be han d led ill a b lock. Transfcr ofa data block m ust not be interrupted. and it is not perm issibl e for the data source or target to be changed from the other end duritlg a transmissi on e ither. For examp lc. if you transfer four bytes ind iv idually. the Jransmirting program can b e interrupted by a program of h igkr prioritybctwccn each byte. and this progr.un cuu ld change Ihe data in the souree or target arca.

I SIMATTC S7-300/400 Programmable Controller

1.5.4

Bit Memories

CPU i~ parameterized. Please rer.,- to Chapter 21,1.4 "Retentivity" for additional infonnation.
Clock
m~m .. rics

The area called bit memories holds what could be ..,garded "" the controllers "auxiliary wntaetors", !:lit memories arc used primarily for storing binary signal states . Thc bilS in this arca can be lTeatcd as outputs, but arc not ".xternalizoo", Bil mcmori~'S are located in the CPU's system memory area. and is thcrefo.., available at all times. The number ofbilS in bit memories is CPU-specific , Bit memories are used to store intennediate results that are valid beyond block \xlUndaries and are processed in more than one block. Beside, the data in global data blocks. the following are also available for storing intcnnediate results

Many procedures in the controller require a periodic signal. Such a signal can be imple. mented using timers (clock pulse generator). watchdog interrupts (time-controlled program execution). or simply by us ing clock memories. Clock mClllorics consist of bits wbose signal smles change periodically with a mark-tospac~ ralio of I : I. The bits are combined into a byte, and correspond to lixed f..,quencies (Figure 1.10). You spedfy the numb<:rofc1ock memory b its when you parameterize the CPU. Please Dote that (he updating of clock memories is asynchronous to cxution of the main program Clock memory byte

o Temporary local data, which are available in all blocks but valid for the Current block call only. and

o Static local data. which arc available only in


function blocks but valid o'"cr multiple block calls. Retentin bit memories Part of bit memories may be designated "reten tive"'. which me""s that the bits in that pan of bit memories relain their signal state, e,en under off-circuit conditions. Retentivity always begins w ith mcmorybyte 0 and end, at the des ignated location . Retet\\i vity is S<:t when tbe

17 1 6 1 5

j41 3 1z l tlol

5 Hz (fllcke<lng light) 2.5 Hz (fast ~as hi ng light)


,",

I 10H~

0.625 Hz (slow flash ing light) 0.5 Hz


F lgur~

, "'

, ,25 Hz (nuh ing light)

1.1n Contents of the Clo<k MclYl{lty Byte

2 STEP 7 Programming Software

STEP 7 Programming Software

2.1

STEP 7 Basis Package

who.e size must be at lea S! twice lha! of the mllln memory. You should ensure lhere is sullic icnt memory on the drive contain ing YOllr pr<Jjcct data. The memory requirements may increase for cenain operations. such as copyi ng a pmjed.ifthere is in.uffic ie nt space for the 'wap-ou.] file, eIT<JI" such 'IS program crash.s may occur, You are recommended not to Slore th e proje~t uala on the drive containing the Wind<Jws s wap_out fi le. The SETUP program on the CD is used for instaUation, Of STEP 7 is already factoryinStalled on the programmi ng device , In addilion to STEP 7, the CD also includes, in/a alia, tb e AUl<Jmation L icense Manager (see Chapter 2. 1.2 "Automalion license Manager") and lhe STEP 7 electron ic manuals with Acrobat Reader. A n MI'l interface is needed for tho <Jn line eonnceti<Jn t<J a programmable c ontroller. The programm ing dellkes have the multipoint inter_ face already bui lt in. but rc, musl be "'trofined witb an M1'I modu le. If you want to usc I'C memory cards OT micro memory cards , you will n eed a pronuner. STEP 7 VS h as multi _user capabilil y, thaI is, a project tbat is stored, say, on a cen lral ""rver can be ediled simultan~<Jusly from several workstation . You make the necessary scllings in tbe Windows Control .Pan el with th~ "SL"-1ATIC Workstation" program. In tbe dial<Jg 00,.. that appears, you can parameterize the w"rkstat;on as a s ingle_u.er system Or a multi mer system witb the protocols used, Dein"allation of STEP 7 is carried OUl wi th the setup program or in the usual manner for MS Windows u,ing the "Software-' program in lhe Windows Control Panel.

Thi s chapter describes the STEP 7 basic package, Ver;ion 5.4 SP3, Wh i!c Ihe fIrst chap ter presented an overview o f Ihe properties of the pTOgmmmable controller, this chapter tells you how to sel th~se pTOpenies ,
The. basic package contains the statement list (STL), ladder logic (LAD) and function block d iagr4tn (FBD) programming languagc"_ Tn addition to the basic package, optio n packages such as S7-SCL (Structured Control Language), 57 -GRAPH (sequence p lanning) and S7-H iGraph (>tate-trans it; on diagram) are a lso available .

2 .1 .1

ImTaliution

STEP 7 VS.4 is a n_bit application whi ch executes with MS Windows 2000 Profe>sional with SP4, MS Windows XI' Professional with S1'2, MS Windows ServcT 2003 S1'2 standard edition as workstation computer or MS Win_

dows Vista 32-Bil Ultimate and Business. MS


Intemcl Explorer V6 .0 <JC high~T is requi",d under all op"rating 'ystems You require administrator privileges in order to in'tall STEP 7, and yo" m"st be registered at least as a main "ser in order to work with STEP 7. Ify<JU wish to w ork rapidly with STEP 7 or pm_ Cess large projects. e .g , w ith sev~ral hundred modu le s, you should uSe a pmgrarruning dCllke or PC with up_to_date ptoeessing power. STEP 7 V5.4 <Jceupies approximately 650 I<J 900 Mfl ou the hard disk depending 011 the ,e<Jpc of installat ion and the number of installed languages . A swap_out fi le is 81.0 needed.

2 STEP 7 Programming Softw=

2.1.2

Autum.llon LIcense Manager

2.1.3

SII\-IATIC M.nager
III

A license (right of usc) is required to operate

STEP 7. This consists of the certificate of license and the electronic licen;;~ key. The licCIlse key is provided on the license key disk or a USB stick.
A license key ~an be present on the license key disk. on a USB stick and on local or networked hard disks. A license key wi\] only function if it is present on a hard disk with write acce"" You use the A"wmalion License Manger to transfer and administer the license keys . Tn.tallation of the Automatic License Manager is a requirement for operating STEP 7, You can insmll the Automation License Manager together with STEP 7 or on its own.

The SIMAflC Manager is the main 1001 STEP 7: you will find its icon in Windows ,

The STMATlC Manager is started by doubleclicking on its icon. When first started. the project Wi7-&rd is displayed. This can be used for simple creation of new projects. You can deactivate it with the check box "Display Wizard on starting the SIMATlC Manager" since it can also be called. if r",<uired. via the menu command Ftu; ~ "NEW PROJECT" WIZARD Programming begins wilh opening or creating a "project". The example projects supplied are a good ba> is for familiarization. When you open example project ZEnO I_09_ STEP7_ Zcbra with Fn.E ~ OP~N, you will see the split project window: on the left is the snu clUre of me open object (the object hierarchy), and on the ngbt is the selected objo<-1 , Clicking on the box conta ining a plm sign in the left window displays additional levels of the stlUerure: sek'Cting an object in the left half of the window displays it, cOntCnts in the right halfof the window (Fig-

Thc type of license key is defined in the ccrtificate of liC<.'tlse: '" Single License This license is applicable for an unlimited time. and perrni"ible on anyone computer.
~

Floating License This liccnse is applicable for an unlimited time. and provided for procurement yia a network . Trial License This license i, limitcd to 14 days. or to a certain number of days starting with ils in itial use , It can be used for testing and val idation. Upgrade License This li cense permits upgrading of an authorization/license key from a previous version to the current vLTsion.

(>

(>

ure2.1).
Under the SlMAT1C Manager. you work with the objects in the STEP 7 world. These "Iogica\"' objects correspond to "rear' objects in your plant. A proj~ct contains th.. entire plant. a sta tion corresponds to a programmable controller. A projed may contain sewrnl station. con nected to one another. for example. via an MPI ,ublleL A Slation contains a CPU, and the CPU contains a program. in our case all S7 program, Th is program. in tllID. is a "container" for other objects, g< as thc object Blocks, which conlch tains, among othcr things. the compi led blocks. The STEP 7 object' are connected to one another v ia a tree structure. Figure 2.2 shows the most important parts of the tree slIUcrure (the "main branch'". a. it were) when you are working with the STEP 7 basic package for S7

During installation of STEP 7, licensing will be requested if an appropriate license key is not yet pre~nt on the hard disk You can also cany out licensing at a later point in time, The license key is saved on the hard disk in specially identified bl""ks. To prevent unintentional destruction of Ihe licen'" key. please observe the lnfonnation on the handling of license keys proYided in Ihe help functionofthe Automation License Manager

application s in offiine view. The objects shown ;n bold type are containers for other objects. All objcc15 in the Fi!!lIrc nre avuHable to YOll in th e omine view. These Ire Ihe object;; thaI are on the programming device's hard disk . If YOllr programming device is onlinc on I CPU (normallya I'LC u'Tllet system), you cln switch 10 the onlinc vicw by wlccllng VIEW ~ ():.,"1.I1'<1"i. This option displays yel another projCCt window containing the obj"""t~ on the destination device; the objects shown in iulies in the FigUre are then no 10ngC!" included.

Edi ling sequl"nce. The following applies for the general edit; n!! of object" To selec, an objecl mCanS to click on it <.>nee with the mouse 50 that it is highlighted (this is pos~iblc in both halves <>fthe project window). To name a .. object meallS to click on the name of the ""lected object (a frame will PI'r>eat around the name and you can change the name In the window) or select the menu item EPlT ~ OBI1'= PIlOI'ERTlliS and clliinge the name: in Ihe dialog box. Willi some o bjeclS sucll as CPU, you can only change the npme willi the relevant tool (application), in this case with lhe Hardware Configuralion. To open Oil objecl. doublc-click on thai objeC"l. Iflhe object is a container for other objecl5, the SIMATIC Manager d isplays Ihe contents oflhe object in the right half of the window. If the object i. on the low.".t bierarchical level. Ihe STh-lATiC \1anager stans the approprilite tool f.". editing the object (for instancc. doublcclicking on a block starts the editor. allowing the block 10 be editcd ). In thi. book. the menu itcmii in th~ standard menU bar al thc top of the window are describ<.:d

You can sec from the title bar of the aClive project window whether you lire working omine or online. Forele8rer dIfferentiation. Ihe title bar and Ihe window title elUl be sct to a different color Ihan the om,nc w;ndow. For this purpose. select OI'TlONS ~ CUSTOl>l1ZE and modifY the entries in Ihe Vicw tab.
Select OPTtOSS ~ CUSTOl>1t.Zt: to chan!! .. Ihc SIMATIC Manager's basic scnings. such as Ihe scssioll languagQ, the archive program and thc ",oragc location for projccts and librari es, and eonfigurinllthc archive program.

2 STEP 7 PruWummins Software

Con, aine, fo, aU dabl of. programmable conlrolier

MPI P I P PROFI8US,
Industrial EthlImet

Sub""'t

e",,,,,jo< tlle ne,wQrk pamm01C,",

"'tting f",. ,ul",,"


(fiu\"'ionan,;e~

"n,.,; k software)

Cont.l"or for.U d ota of

fl,. SI.\lATIC 3001400 slatlon


,m.,,,,,, ""d the p.mmel"" t?r
mooules
. ,,~

Confogura tk><> table

C<><\Iains \he "'{)n!igumtlon <Iota lOt the


,~.

Con<ol"", for tI,c ,0,,",co<lo," '.bl_ Connectloos

lb. u r prugr.m

OmUli", the dc!i nition. of <1'<' >rnmun i <.,;on. wnno<;' ions , he''''''''''' DOd., in a network

Cootaimr for aU dato of the "5Or p"'gr.m

Symbol table

Con", i"" the of'rm""l, (- n.me,) to the ab""luio addI ....,s of ;;lobol dat.
pro~r.m

""'!If\IDC"'' '

Co"'.in~r

for tbe

.onrco.
C"",.i~ 'he S<>un;" for \he mer program (~., for STl ailtl SeL progra,ns)
pJ'()~ram

Source programs

Contain.. for the compiled

and

. o nll~nratio n

User program: OrgantzaliOrJ bfocI<s


FUl'ICtion blocks FUl'ICliC'(ls Data bk>cl<$

Cont.in 'h comrilO<! <00< ."d 11K ohta

Data types

th~

('on ... i" 'he d.!1"jti<m, Qf u,e::- d.>ta l)'pe"


C"","i~

System lurlctlnns System functlons blocks System data blocks Variable table$

' be ~.Il intorf""" for blocks ,n\egtllled in tho Cl'l)

t~e

$y,te>n

Contain the """'piled daut roc tho configurntioo Ubie Co"tain the vari.ble, foc rrwWt(>o";'\j1
2nd modif0nlr

not ."'Iln." to any h.rdw ....

",ilh ,h. """'e ltrue"'" as

'0 hard,,=c
F igure Z,Z Object Hiera",hy in a STEP i Project

an S7 progrom ,hat i, '",igm>.1

(The undcriinMt objects arc on ly ptesent in the omine data llllOnagemenL)

2.1 STEP 7 !Jui. l'ackage


II~ "Ixro.lor sequence.. Programmers experienced in the usc of the op<:rator interface usc the icon~ from the toolbar. The u~c of thc riRhi mf)uS~ blmolf is very dfeelive. Clicking on "n object uncc with the right muu,;c bunon screcn~ II menu sho ..... ing the Cll""nt editing options.

tion blocks in colijl1nelion with program conversion) :. Tl-S7 Convening Rlock~ Contains addhiolial loadable nmctions a nd function blocks for the TI-S7 converter

> IEC Function Blocks


2. 1.4
Proj ~cn

and lib ra ries


t>

In STEP 7. the "main objects" althe lop of the object hier-ITchy an: projects and libraries. Stuning with STEP 7 V~.2, ~ou can combine projCCt~ and libraries into Ilmhiproj<xts (see Chapler 2.1.5 Mulliprojects').

Contains loadable functions for editing variables of Ihe eomple~ data types PATE_ AND_TL\l Bnd STRING Communication Blocks Conta ins loadable functions for controllin g CI' mo<lules 'ii.celianffiUS Block< C.IIntains block!; for time SUtmping and time synchronization Cont.ltlns loadablc function clOS<.'d -loop centrol
t>

1>

I'roJecu are used for the ~y~teftUl.lic storing of dilla and programs needed for solving an automalion task. E5Sentially, these arc
I> I> I>

> PID Control Blocks


block!; for

Ihe halth"are configuratioo data. Ihe parameterization dala for the modules. the configuring dala for communicatiot\ via networks, the programs (code and data. symbols. souKes).

t>

OrganJ~ation Block, Contains the templatcs feT the organization block. (es<enlially the variable declarotion for the stan in formation)

The objects in a project life arn.nged hi...-archi_ cally. The opening of. project is the: AAt step in editing all (subordmate) obje<:ts "hich Ihat object contains. The following sections discuss how 10 cditthe<e objC<::ts.
Ll/)rar/e.f an: used for storing reusable progrnm

components. Librarics an.: u'lIlttlized hierarchi~all)'. They may contain STEP 7 pwgmms which in tum may conmin a USer program (a coolo.iner for compiled hlocks), container f.llr source progrnms. and a symbol table_ With the exception.llf online connecti.llns (DD debugging plbsiblc). Ihe crealion ofa proiflUll or proiJ1lm .celien in a library provides the same function_ alily as in an objecl. As suppl ied, STEP 7 V5 provides the Slmidard Library containing thc followini: prollTams:
(>

Yeu will lind an <"'en'iew of the con,ents of these librarics in Chl!.pu:r 2S "l:ilock Libraries-. Should )'OU. f.llr c~amplc. pUKhase lID 57 module with standard blocks. the associated installalion progIaIll instails the sllIndard blocks 8.'l a library on the hard disk. You Can then copy these blocks from the library 10 your project. A \ibmry is opened with FILl! -+ OrLO.."': , and can then be cdited in the same WHy as a project. You can BI~ creatc y.llur .IIWI'I lohraries. The m=" ;'CTTl FILl! -+ N~w gencn.. c. a new obJC<:1 al the top of the objcet hio:rarehy (project, library). The location in the directory structure wbe'" Ihc SThiATIC Manager is t.ll create a project Dr library must be specifi..d under the menu item OI'T10S~ -+ CUSTOMt7.ll Dr in lhe "Ncw dialog" ho~ The 'I'SfoR T menu is us..d 10 add new obj~''''s 10 c~isting ones (such .s adding a new block 10 a progr~m). Before doing so, however, you muSI firsl select the object ~vnUliner in whieh you want 10 insenthc ncw object from the left half oftbe SIMATIC Manager wind.llw. You eopy obj~"C1 conlainers and .IIbjects with EDrr -+ COpy and EOIT -+ PASTE or. as is usnal willI Wind",.... by dragging the sc lceled object

System f unction Blocks Contains tho: call inl~-rf.c<:s of thc .ystem blocks for offline pro8fllmming integrated m the C[,U S5-S7 Convening Blocks Contain.,; loadabl~ functiom fo, the S51S7 convertcr (replacement of S5 standard fune_

I>

2 STEP 7 Programming Software

with the mouse from onc window and dropping it in another. Please note that you cannot undo deletion of an object Or an object container in the SI"1ATIC Manager.

Tests & troubleshooting, as wel l as SIMAT IC on the Internet


Hap ---> CON1EXT-S E..';STTTVE HELP F I provides context-sensitive help, i.e. if you p re ss Fl, you ge t irl fonnatiorl cOrlcerning an object selected by th~ mouse or concerning the current error message.

2.1.5

Mult ip roject.

In a multiproj ect. proj ..><:IS and librari es arc combined in an entity. The mult iprojccl allow, pruc~"sing o f communicat ions conncdiOnl; such as 57 connections between the projects. A mulliproject can then be handled almo.t like a s ing le project. Limitations : stations comlccled together by means of direc t data exchange ("internode communication") or through global data communication must be P,,",SCnI in the

In the symbol bar, then: is a b utton with arl arrOw and a questiorl mark . If you di ~k on this bulton, a questiorl mark is added to the mOuse poin ter. With this " Help " m OU8e pointer. you c an now click on an o bj e ct on the scre.:rl, e ,g . a symbol or a menu command, arld you wi ll gCt the associated online help.

"arne project,
In a muitiproject. it is possible to carry out paralld processing of ind ividu al projects by vari_

2.2

E d i ting Projects

ous

cmployc~s

without problem . The individ

ual projects can be pre,em in different dire<:tories in a networked environment . The croSsproj ect fu nctions, such as thc match ing of ,ub networks and connection.<, are then carn ed oUi centrally when processing the multiptoj:t, In the case of central SlOrage on a s erver, only th ~ operaling systems MS W indows 2000 Server and MS Windows Server 2003 are pcnn;llcd
It is a ls o advantageous to create a muitiproject if yo " wish to make th e individual proj ects sm aller and clearer.

\Vhen you sct up a project, you create "coma irl erg'" for the rcsuitirlg data, therl you generate the data and fill these containers , .'Ionnally. you cr~ate a project w ith the rel e vant hardware. configuro the hardware, or at Icast the CPU, arld receive in return containers for the user program. However, you can also PUl an S7 program d irectly into the project conmirler withom involving any hardware at all ).jete that irlitial izing o f tho modules (address modificatiorls. CPU settings, c on fi guring COrlnections) is po ssible only with the H ardware Configuratiorl tool We strongly recomm end that the entire proj ect editing process be carried out using the SIMATIC Manager. Creating, copying or deleting dire~\Ori es or files as well as changing name< (') witb the Wirldows ExplOl"<'r within th e Slmcture o f a project carl cause problems with the SI1>tATIC M anager,

2.1.6

Online Help

The SI"tATi C Manager's online help provi des infonnation you need during your programming se ss ion without the need to refer to hardcopy manuals. You can sele<ot the top ics you need infonnation on by <~lecrin g the HELl' menu, The online help option OETT ING START ED , for instance, provides a brid summary on how to use the S IMATIC Manager.
H EL P ---> CO:-'OEN TS ,tarts the central STE P 7

2.2. 1

C r eating P rojects

Project "izard The STEP 7 Wizard helps you irl crcatirlg a new projecl . You specify the CPU us ed and the w izard c reates for you a p roject with an 57 station an d the s c1ecl ed C PU as we ll a.\ an S7 program container, a SOurce comainer and a b lock cot)tainer w ith th e selected orgarl izatiOrl block...

Help function from any application. This contains all the bosic knowledge, If you click on the -'Home" symbol in the menu bar (start page), you will be provid ed with an introdu~ tion to the centra l topi~s of STEP 7: Starting with STEP 7. Confi guring & programm irlg.

2.2 Edilinll J>roje<:ls You


~Iart

Ibe

proj~1

wi zard using fILE .....

''''cw plI.orrcr WIZNW.


CrT.Unlt a
s~clion
proj~et

the hanlwa~ configuration. the open station no" al$O shows the CPU .
When it configuTl:s the CPU. the StMATIC Manager also c~ate s an S7 program with all obj~ls. The project StruCture is now ~ornpl etc.

"ilh th e 57 stllll"n

If you ,,'anI 10 ~r~ale a project "",an<lally'. Ihis OUllincs tbe nessary ICI;ons for you. You will find general infonnalion on oper.lIor enlri~ for objCCl edillng in Chaplet 2.1.3 "SIMATIC Managd' . C....aring a "e"'proj'",,1 5d~1 F u.E ..... NEW. enter a name in the dialog box. change the type and siorage lor;&l;on if n~e$~pl)'. and confinn with "OK" or RETURN, /nsenil'R a nrw station in II,,, project the proj~t and insert .. suuion wilh I:-SERT ..... STATIO:- ..... Sl\IATIC 300 ST,\TIO:(in Ibis CaR an 57-3(0).
Confi!,.",rill!:" ~1"tjQlI
S~ICCI

17.....;ns Ihe com"n/! o/IM S7 program


Open the CPU; in the right half of the proj~'C1 ",indo"- you ,,;11 sec the symbols for the S7 prog"am and for the connection whle.
~n the 57 program: the SIMATIC "1anager displays tbe .ymbol. for the compil ed user program (tbe compiit,d blocks). the container fO<' the source prognrnu. and the symbol tablc in [he right balfofthc window.

Open the user "rogrnm (Bloch); the SIMATIC Mannier d i~plays the symbols for the compiled configuration data (Syslem dalo) and Btl emply orvanizsllOD blor;k for the main program (OB I) in the ngh! halfofthe window.
Ed/ring user progr"''' objects We have now arrived at !he lowest level of the object hierarchy. The first lime: 08 I is ol,,:ned. the window with the objcct properties is displayed and the editor newed 10 edit the program In the organi~ation block is opened. You add anotber em pty block for incremental editin g by opening lN~[RT ..... S7 BlOCK -+ (Blocb must be highliahted) and scl~ting the requi~d hlock type from the lisl provided.

Click on the plus box next to the project in Ihe lell half of the proj~t ""ndow and .elKt the statio,,: the Sf'iATIC Manager display, the Ilardwan:: object in the ri~t hal r of the wmdow. Doubl eelicking on H"",/wur-e starts the Hardware Con tlguntlion 1<>(11. with which you edit Ihe ,"nfiguration tables. If the module catalog is nOI OD the scree". call it up wilh VIEW ----> CATALOO. You begin cunfiguring by selecting the rail with tbe mouse, fur instance under "SJ,\L\T1C 300" and "RACK 300". "holding" it, d'dggini it \0 tile free ponion in the upper luM of the $talion "-;nd",,, and " Iening it go" (drug & drop). You tllen oce .. table rcpreSt.'Uling the SIOI8 01\ thc mil. Next. "clect tile requi~d modules from (he module ~~talog and, using the pro<:~'<Iun:: descrilxd above. drag and drop them in thc appropriatc $IOts. To enable funbcT OOllinl of tile proje<;l Strw;ture. a 5tation requires at le35t one CPU, for instance t h~ CPU 314 in slot 1. You can Rdd al1 othcr modules later. Editing of lbe hardware configuration i8 di,;cussed ;n <iel8il i" Ch~pter 2.3 -Conllguring Slations".
SIO~ and compile the station. th= clo", and rerum to Ihe SlMAT1 C Manager. In addition 10

\\1I<:n opened. the .s)'~I"'m dmo object shows a list o f uvuila ble system dnla blocks. You receive The compiled con fi guration datu. Thes~ fy stem data blocks are editW via the llarm."r;: ohject in th~ eomai""r .varlo". You can lfIIlUlfc-r SJ'~ lem dala to the CPU with PlC ----> DOw:-rwlill and paramcterize the C PU in this way. The objCi container 5oll":"" is empty. With Snurc~ selected , you can ~elecl I'<SIlII.T ..... 57 SOI'T\\AItE ..... STL SOLlI.CI! IU irl,ert an empty .0\lfCC text file or you CIlD select lNS(Jt T ----> E.'Cl FR'iAL SouRCE to 1JltlI.rer a source leKt file created, <ay, with another editor in ASCII format \0 the 5olirce< container. Crutlng. proJeCI without pn S7 ftlllon If you wish. yoo can create a program witbou\ first having 10 confillu~ a station. To do 50, generate the cont ainer for your provarn your-

2 STF.P 7 PruIlTII.mmin, Soft",'.", Sele<:tthe projcetllmll!'~l1ernte an 57 progrnm with Il-SER1 ..... I'1\OO~M ..... 57-PROU1\A.\1, UndCT Ihis S7 program, Ihe SIMATIC Manag~r ereat~ the objecl contairICMI So"rce,~ and Bloc-la, Blocks eOD ... ill5 un empty OB I , CITa lin g a library You can also ~.te program under a library. for in~tat>l.'<.: if you "ani \0 usc it more than once. In thi~ way. the standard program i~ a1",-a)'S avsilable and y"" can copy it enti: or in part into your current program. Please Dote Ihut yuu ell!llWt ~tabli~h online coMCCtiuos in ~ libnuy. which mean~ Ihat ynu cun debug a STIlP 7 program only wilhin a project.
2.2.2
~I[

progrnm ARJ.cxe is not suitable for MS Wi n00"'" Vista). You can ulso open A RJ archives ....i'h PKZip V8.6 CU. Projecr.. and libraries cannot be edited in tbe "",hi>'w (compressed) st~tc. You can unpack an archiv~d object "~th Fll.E ..... RI1UEVE and then you can edit it further. The rctrieved objccts ~TC automatically ac<.:cplcd mto Ibe project or libmry management ~tem. You make the .-.cUing. fot archiving and retriev_ ing on the .. ATChi,...... tab undCO' OPTIONS -+ CL'STO~I1Zr;; e.g. setling the tarset d irectory for archiving and rclrie .. ing or ''Generate arch ive palh aU1omatically~ (then no addilional specificatinns are rc-quircd when archiving hceause the DIme o f the archive file is genernted from Ihe pmjecI name) . Anbivlng a project in the CPU With the "Ppro priatcly de, igned CPU . you
~"n

J\lanwglnll' An:bJvlnS(

~t'()IIIYnl/.lnw

and

The SIMATIC MRnager

ma;ntain~

a list of all

known "main object~". arrangcd I,ccording to user proje<:ts, Hbrurin, example projects ~Tld multiproject . You in.t,,)\ the examrle rroject< ""d Ihe srand~rd tibr ..ric~ in conjunc tion wjtb STEP 7 and you install the u~er proje<:ts, th~ muhiprojeets and your own libraries yourself. When yuu c~ccute FI\.F ..... MANM;E, Ibe SIMAllC Manager ~how.' you ~ Jist of all k.nown projecl5 and libraries wilb nHme und path. You Can then deletc from the li~t projects or librnrie~ y"" no lonll~r want to d isplay ("Hide') or include in Ihc list new pl"ojcs and libraries ("Display"). When il executes f ILE ..... RJ:.oRnANlZE. Ihe SIMATIC M IUlaIll"f c1imin~teli thc saps created by dd~-tions and opl;m;n:s dat.a memory similarly to the way a deftagmen ... tion propm optimiz~ the: da ... memory on the hard di.le. Tbe rcorgani~ation can take some time. d"pcncling on the dat& mo,'crnerus involved. You can al.o archive a project or library (Fu_ "
.... A R('HlVF;). In this case. the STMATIC Manag~r

the load m~'lllory of the CPU, \hat j,. Oil th~ memory card. Tn this way. you ~a" save all pIOj~ct data ~ircd for full eXe<:u tion of the uSeT P"Opam, such as ~y mb[)b or !IO"rce fole~, direct at the machine or plant. If it i>e<:omel oe<:e ..ary to modify [)T supplemenT the progT'dIIl, y[)U load the locally Stored data QtlIO the h~Td di 'k, correct the uscr progr:om, a nd ss .. e the up_to_date ptoj<:C1 data aKai n 10 the CPU. loading lhe proje<:1 data onto a memory ~3rd or micro memory .ard plugged into tho: CPU, open the proje<:t, mule the CI'U and scle<:t PLC ..... SA\'E TO fo.IDlORY CARD. In the reverse direction, lransfer the siored data ~k to the progrnmming device with PI.C ..... RFTltTl'vJ; t'ROM MEMORY C.o.RD_ l'1ease note Iha' when you write to a memory card plugged into the CPU, the entire eontenL~ o f tbe load memory IlR" ",TitlC1l 10 the CPU. including the .' Y"tcm data and the user P"'l7"m .
\\"h~n

'l<>Ie " project in archived (comp ..... . ed) form in

Tfyou ,,"ant 10 fetch back thc projcctda ... SIOred


on Ihe CPU without ereatinK a projecl on the

storc$ the selected object (the project or library dire<:tory wilh all subdirectories and tiles) in compTl:ued fonn ;n an =biv" file.

From STEP 7 VS.4 SPJ, Ih e archive prolP"am PKZip VS.6 CLI is supplied for arch ivin8 and dearcb iving proj~"CtS ~nd libraries (the archive

hard d isk, <ekel the n:lcvam CPU with PLC .... DISPLAY A=SS!9lE NODi'S . If the memory canl i, plugged imo the module rttt..-ptacle of the pro wamming device . .-.c lcct tb" memory card wilh Fn.[ ..... S7 Mf.MORY CARD ..... OPIlN before tran.ferring.

2.2 Editing Pmjo:<:l$


2.2.3 Proj eCf Version s Up to STEP 7 Ven;ion 5.3 you can comCTt a V I proj.ct to II V2 project with FlU, -+ OrEN \11::11.510N I PROJI:CT . With fILE

Since STEP 7 VS has become availabk. Iberc are three diffc['l:ru "ersiolt5 of SL\fAT1C pmjetts. STEP 7 VI creales version 1 projO"Cts. ST EP 7 V2 creal ~s version 2 projects, and STEP 7 V3!V4IVS.O can be used to create and edit both v.... ion 2 and '~I'$ion 3 projects. Wilb STEP 7 (rom venion VS .I . you C~n create and ed it V3 projectS and V3 libraries.
If you IuIvc a vcrsion I project. you can couvert it into a """,ion 2 projett with F1L -+ OI'D> VliRS10'l I I'ROJECf. Thc project StruCture ...ith th e programs, Ihe comp iled version I bloch , the STL soun::c programs. Ihe symbol tabl e and tIM> hard"llrc c<miiauralion remain unchanged.

-+ OPEN. you can

open a V2 project and oonvert il iO a V3 project. I! is DOL possible to ereate a V2 project OT save

a project as a V2 project.
2.1..1

C fi!ltlng a nd cd ll ing m u l1iproj ...... "

u.ing Fn.E -+ NIoW you can crente a new mulliproj....,t in Ibe SIMAT1C Manager in which
you <elect
~Muhiproj....,f'

Os the t)'1X' in the dia.

YOll Clln create and edit venion 2 pmjects wilh STEP 7 versions V2, V3, V4 and V5,O (Figure 1.3). STEP 7 V5.1 works only with "crsion 3 proj""lS .

101100". With the multiproj....,t Klectoo. you can then gcnc1"Btc a new project or a DCW library in the mulLiproject noing Fn.E -+ Ml:U1 PROlt:CT -+ CREATE IN ~1ULTU'ROIECT. You Can pmSII the OC\\ Iy crealed project or libnlry a. described in the previous ~haplen , Using FILIo -+ MU1.TI_ PROJECT -+ INSEII.T INfO MULTIPROJECI' you can incorponlle exiSlin~ projecl~ Ind libniries
into the mUhiprojccl.

"

2 STEP 7 I'rogrammini:C Software


wheth~ your <:limes well' free of e lTOrs. STAllOS ..... SAVE stores t~ configuration "'bl.-.; with all parameter lWIignm~nl data in yoor project on the hard diu.

You can a l$O chminate projecl' and libnLri;:s agam from the mulliprojccl: marl: I~ projeclS; library. 8f1d !It'lect Fn.1i ---.. hluLnPROffiCT-+ Rl:.MOVI! fROM MUlll1'ROJECT. The project ot library is nOI deleted in Ihis process. Usi n.: f lU: -+ M UlT1PRO]ECl -+ ADm~T PROJECTS you can stan a wizard which .Iupfl<ln$ you in the matching of CTO""proj ect CO r1ll eClions and when comb ining s"bnets (Chapler 2.4 .6 'M alching Pr"j CC15 in a M ulliproject"). You can identifY One "fth;: libraries in u multiprojcct as the "ma.lter dala library' \Ising FlU: -+ MUl1U'ROJ~l"T -+ DF.rn-"EASMASTHt DATA 1 .IlIRARY. Tbi:i contains., fot example, the commoo blockll of the pmjects in this mul[iproj"t. This libnory must th~n only tOlltain one singJ;:
S7pro~.

STATION --> SAVE o\l'o"D CO~II'Iu! I\Ot only saves hut al<o compi le [he oonfiguratiOn tables and store~ thc ~ompikd data in the $y.'u,m dma object ill the ottline conta iner 8/(>ck.<, Aficr compilinl!, you can tr;msfer the config\\ralion data to 8 CPU with PLC -+ L>oWr-LOAl.l. The r>bje~t Sy~rem dam in th~ online contaiocl 81ucks n:presents the current confi.:unllion dala otI thc CPU. You can '"return th~"SC rJ~tH [0 the hard diu with PLC __ UPLOAtI. You uport the data oftbe h.ardW8I"C cunfiguralion ....ith STATION .... t:.xI'ORT. STEP 7 then creates a file in ASCII format that contains the configuration dala and parameterization data of tl1.e modules. You can cl1.OOlSC between a texl fonnat that conta;'l. Ihe daLII in 'readable' English. charncters, Or a comp8l'1 format with hexadecim al data. You can also impon Ii cOlTespondingly structured ASCII filc. Ch N:k sum Hardware Configuration g~"fICT'\Itu Ii ch~lcl;um via a cOlTCCtly compiled ~tat'otI and ~to~s it in the ~ySlem data. Identical system ~"Onfigurations have the samc checksum so that you can. for example, easily cumpare an online conJigUllition ".'!h an offline configuration.
The
obj~(.

The mCflU cOlIlllllllllls FILE __ SAVt:AS. FILE-+ Rr.oRClA).,'flF, FR.b -+ k iANAGE and FILE -+ ARCHIVIl can also be u>ed on a muhiproject. and runction as wilh a sing:le project (~cc t:huptcr 2.2.2 "Managing, Reorganizing: and Mhiving'). In the same manner. archived mult iprojl~tJ can be transferred to the load m~mory ofa ~orrcspond ingly desigocd CPU, Then: ar~ limitalions when archiving a multiprojecl whose comPQII;:ln~ are di stributed among nelwort drives.

2.3

Cunfiguring Stations

You UiIC the Hardwatt ConfigumfJon 1001 to plan your programmabl~ controllers configuralion. Configurin.: is carried out umine without connection 1 the CPU. You can also use th is 0 1001 to addrc~~ and param~teri~~ the modules. You can Cl'eale Lhe hardware oonfigurntion at the planning stagc or you can wait umil the hardware has already ret.'Il installed. You stan the hardwlll'e confill"f8.tion by sdectiug lhe ~tat;on and then EDIT ..... 01'9' OIlJ~CT or by oouhle-clicking 0fI the HanlHv~ ubi"" in the opened container SIMA TIC JO(M()() Sta lion. You make t~ basic sening.< of Ib\; Iw'tlware configuration wiLh OPTIONS -+ CUSTOM\.L1l.

The checksum i. a property of the S,"SIcm daln To read the ch~"<:ksllm. Opel'lthe Blocks

cuntain~r in the S7 proa:ram. IOelect the Sy.otem dara objcct and open it with EL:lIT -+ OPE.. "I OWlCT.

The user program also has an appropriate checbum , You can fi nd thi~ alons with the checbum of the system data in Ib.t properti~~ o f Bloch: select the BlQCb container and then EDJT -+ ORJECT PR01>F.ltTII:.S on the "Check~um5"mb.

St illon ... indow When oproed. the Hardwa~ Configuration displays Iht .tation window and the hardware call1iog (Figure 2.4). F.n1"'l!e or maximizc the .1ation wimlow 10 facilitate editing. In t~ "'PIX'r section, it displays thc 57 slati ons in Ihc

Whrm configuring has berm completed, ST .... nON -+ CONSJSTer-'t"Y CHECK will show you

2.3 Confil/Uring Stations

Hi" ....

l.~

Example of. Sta';<ln Window in the Hanh, ..... ConfiI\Jra,ion InSlalllnl b udwan <lpd.tn
\\1m Omo'~ -+ ISS'fAll II W UPDA"ffiS you con update components for the hanlwan: callllog. In the followinJl: dialog.~. Klcct whether }Oll wish to download the update from the Internet or copy it from a CD , Enter the Tntemct address 8nd the save path , By clicking the Inslall" bunon, the Hardware Confi gurntion transfers me data into the hardwan: catalog.

form of tables (one 1"" mOUntinll rack) that are <:onnected together via iOlcnace modules when severnl mounting rach are uS! Wben distrib. uted UO is conne<:ted, tbe confillur"t.ion of the Dr master system or the PROFINET TO sy'" te'n ;s specified. with Ihe OP ~lation' and TO devices represented in Ihe fonn of symbols. The lower section of the station window sho",~ Ihe configuration table that gives a d~tailed view of th<: rack or OP slave selected in the upper "",ction.
H a rdWlI rt u tal"g

Product SU ppOM inform ation


TlON

You can faue the hardware catalog in and out with VllW ----jo CATA1.OO. 11 conta ins all avail_ able mO<lnting rach, modules and intm"ce ~uhmodulcs known 10 STEP 7. With OPTIU~S -+ EDIT CATALOG PRO~tlE, you CKn compile your ow'o hardware catalog that sllows only the modules you waDI to ",or\< wilh - in the stJUC:tun: you select. Ry double-clicking on the lille bar, you can "dock" the hardware catalog onto the right edge of the station window or release it again,

With HELP -+ PRODUCT !';VPI'OIlT u,"FORM.<.you can display infonnat;on from the [mernet for tbe sckctcd module. You muSI fint enllblc this function with OPTIO"S -+ CUSTOMII I and set a valid Intcrnet addre8s. Thc selected module can be in the hardwan: catalog Of already in the configun:d rack. Co nn gur.tloD t.ble
The Hardware Confilllll'lllion 10Ql works with tables that tach represent an S7 station (a mounting r~ck), a DP stalion o r an 10 device. A

2 5TF:P 1 Proll",mming Soft"......, C(lnfigurafion tahle shows Ibc: slots with tbe modules ammg<:d in the slotJ; or the propeT1ie~ of the modul" such as Ibc:ir addn:ss<:s Ind ordcrnumbcrs. A double-click on a module hne opens the properties window oethe module and allows Jnl1Imeter1zation of the module. properties for \bf; n::le'"lInt rnQdules in the tab. If )'<IU deselect the option ~Sysu:m default" in \his lab for S1-300 modules. you can ehanKe the module liddTCllscs. When dning so, pl.,ase ob$crve the add\"C!lsing rules for S7-300 ami S7-400 syStems as well as the addressing capacity of the indi~idua\ mod~Addn::s>cs~ u\ c~.

2.J. I

Arrlnglng Mod ules

You begin configurin g by s<; lcctinii and "holding" the rail from the module catalog. for instanc~ under "S!MATIC 300" and "RACK 300". wit h the mouse, dragging it 10 the upper half of the 'fation window, and dropping i1 anywhen:: in that window (drag & drop), An empty eontigun.tion table is screened for \bf; central rack. NCOICI, 5Clce1 the required module! !Tom the module eafalog and, in the manner o:k:seribed above, drag and drop them in the appropriate ,10\5. The perrni>sih!e slolll have _ g~n background. A "No Parking" symbol te ll s you cannot drop the sdcc\cd modu le at the intcnded ,lot. You can abo mark the slot to be equ ipped. and sclt(:t IN5~Il.T -+ INSERT OBJECT. In a popup window, !he Hardware Configuration then shows you a ll modules penni.sihle for thi, slot. from which you can selC'Ct otIC. In the case of!ingle-tler S7-300 stations, slot 3 remains empty; it is reserved for the immaee module 10 the expansion mck, You can generate the eonfigunt.tion table for another nck hy dragging the scle<:ted raclr:: from the e8talo& and dropping it in the sumon ,,'indow. In S1-400 systems, a non- int~onflCeted nick (or more precisely: the relevant rei"e interfnce module) is assigned an interface via the "Link" tab in the Pro!>"rt;" s window of a Send 1M (select module and EDIT -+ OS/ECT
PROPERTlI:S).

Then:: are modu les that have both inputs "nd outpUtS for which you enn (thwn.:t ically) reserve different start addresses. Howc~cr. ple~ note carefully the spec ial information pro~idcd in the product manuals; the large majority offunct:ion and communications modules n::quin:: tbc same start address for inputs and outputs. When assigning the module Still address on the 57-400, you can also make the USii"TnCDt \0 a subsidiary process image. If there i. more than nne CPU in Ihe central I'llck. multiprocessor mode i. automati cally ~et and you must assign the module to a CPU . With VTEw -+ ADDRr.SS OV IlIl.VtllW. you get a window containing all the module ~ddres,cs currently in us., fOT the CPU !eleeted. Modules on the MP[ bus or eommunicalions bus ha"e anMPI addn:s~. You may also change this address. Note. howe,.,r, that the neW MP! addre .. bornes effective as $OOTI as the oonfiguration data are transf=ed to the CPU.
Symbols for USCr d ata add F"flSCS
[0 the Hardw,.,-e Cnnfigul'llllon 1001, you o;:a.n ItSsign to the input. and outputS symools (name.) th.t an:: transferred to the Symbol Table.

The llmonscment of distributed 1,0 stations is ckseribed in Chapter 20.4 "Communication ~ia Distributed 110".

After you have arranged and addressed the digitsl and analog modulu, you save the station data. Then you >clect th~ module (line) and EDIT -+ SYMBOLS. In tlte window that !hen OpenS, you <:an assign a symbol. a data type ami a OOmm=t to the absolute address for each channel (bit-by-hil foc digital modules and word-by-woo-d for analog modules). The "Add Symbol"" button enten the absolute addresses as symbols in piKe of the &Iolute address" without symbols. The MApply" bu!ton trans fers the .ymools inlO the Symbol Tablc . "OK"' also closes the dialo& box.

2.J.2

AddTf'Mlne. Module.

When ammging modules. the Hardware Configuration tool automatically assips a module ~tart address. You can view this addn::ss in the lower half of the stalion window in the object

2.3 Configuring Stauon.


2.3.3
I'n. m ~terldnlt

Modul""

When you p8!"lUTlCCleritt a module. you define ilS propen;H. It is necc"",ry to parnmeleriu a module only whcn you Want to change Ihe default parameters. A requirement for parametcriution is thatlhe module is I<)<;at...:! in a configumtioo t.able. Double-did; on the module in the <,;onfigl.lTlllion table or !le1ccttbc module Bnd then EDlT-+ OIlJECT PROPERTIES. Several tabs with tht ~pecifiable parameters for this module are displayed in the dialog box. W~n you use Ihis metbod 10 paramCleri7.e a CPU. you arc ,pecitying lite run characteristics of )'Our uSet" pro-

their MPI addtnscs. If you do nol want to assiJl11 a name yourself. you can, for <o~ample, ebange the d~faul( identifier from ''CPU :ux(l)"" 10 "C PU:ux(n)" where "n" is equ"lto the MP! address When uliigning the MI'l address. please also take inlo accounl me possibility of connecting a programminll device or openttor panel (O r) to the MPI n"""oB at a later date for seTvice or mainteMn~c put"f'OSCs. You ~hould connect pcrmanently iru;talled prollrnnuninll devices or OPs direCT 10 the MI'l networK; for plugi n dC"icn via a spur line. there is an M P! connector with a heavygaullc threaded-joint soekeL Tip: reser.. c addTess 0 for a scrvicc prognmtming dcvice, address I for a serviee 01' and address 2 for a replacement CPU (COTTespo nd. to the dcfault addr~S5eli).

,= .

Some modules allow)'ou to liet their parameters at runtime da tile U5Cr prolj:nuJ1 with the system functions (5 Chapter 22.S.2 "System Blocks f.,.. Module Parametcri:vmon").

!.3.~

i\l c mitorinlil and Modifying

l\tudul~

2.3.4

Networking Mndules wllhMPI

You define the nodes for the MP! snbsidiary


(su.lmcl) with the Module Propenics. Selectlhe

CPU. or the MPI interlace card if the CPU il equipped wilh nne. in Ihe confIguration table and open it wi!h EDIT -+ OIlJECT PROrERTlF~. The dialog box thai then appc= containli the "Propenics" button in the "Interfacc" box orthe "General" \.lib. If you dicit 00 Ih .. button yoo arc I8k~n to another dialog bo~ with a "PPrtlmt ter" tab where you can find Ihe suitable ~ubnet . Th is i$ al so an opponunity to ,et the MPI address lhal you have provided for this CPU. Please nole that on older S7-300 CPUs. FMs or CPs wilh MP! eOOrICCllOO automatically receivc an MI'l addres. derived from the CPU. The highest MPI address mUSt be grealer than or <.-qualto Ille highest hlP! address usignc<.l in the subnel (take accounl of automatic as .. ,n ment ofF~b and CPs!). II must have the same value for all nodes in the subm1. Tip: if you hav<o se veral stal;ons with the same !ypC of CPUs. assign different names (identifi e.... ) to Ille crus in the d,iferem ,talions. They aU ban Ihe name ~CPU:ux( I )~ as default iIO in the subnel they can only be differentialcd by

Wilh the Hardware ConfigUntlion , you Can carry o ut a wiring checK of the macbine or 1'1"", ,,';thOUI the u,er progntm. A fC"qum.mcnt for this is that the programming device is con"ecl...:! (0 st.alion (mime) and Ihe configuration h~~ be~n saved. ~ompiled and loaded inlo the CPU. Now you can nddrcss every digilal and analog module. Select a module Rnd then plC -+ MONITOR/MODIfY. andsetlhe Monitor and Modify opentting modes and Ihe trigger eondll;ons. Wilh Ihe "'Status Value" bUllon . the Hardware Configura!iQII shows you the signal stales or the values o f the module channels. The "Modify Value" buttoo ",ritcs the value specified ;n the Modify V.lue column 10 tlH: module. If t~e "'110 Display" chl'CKbox is active, the peripheral inputs/output. (modu le memory) are disp layed instead ofthe i"puts/outputs (process image). "The "Enable p~Tlph. Outputs" chl'Ckbox revoke. !he OUtpUl d..able of the outpul modules If tbe CPU !I in STOP mode (see Chapter 2.7.5 "Enablinl! P""";pheral Outputs"). You can find olher methods of monitorinl! and modifying inputs and Qutpuli in Chapters 2.7.3 'l\.1Q11iloring "nd Modifying Variables" and 2.7.4 "Forcing Variables".

"

2 STEP 1

Pro~1IlIIlinB

Software

2.4
The

Confil:urlng Ihe :'Iiet".-ork


ba~it

ror ~onununicalion, ,,';!h S1MAT1C is the nc:tw9r1<ina of t~ 57 stiuions, The Il'qui~ objccts are the subnets and the modules with communications capability in the sta(ions. You can create new subnc15 and stalionJ

NETWORK --> SAVE "''<'5 an incomplete Net""ork Configuration. You can cheek the con!isteney of a Network Configun.tion with NET WORK --> CONSISTE..'-JCY CUECK, You c1~ the Network Configuratioo with NETWORK --> SA VI! A."D COMPIlE. !'Jdwor k window To start the Network COnfiaUrtllion, you must have create d a project. Toa;etber with Ihe project, the 51l\IATIC Manlger automatically creates an MPI .subncl.
A double-click on thi5 or anyOlher subnet staru th.e Network Configunlion. You can also reach the Net,,'Ork Configuration ir you open the Connectioru object in the C I' U container.

wit h the S IMAT tC Manager within the project biuBrc hy. You (hen add the modules with communications capability (CPU. and CPs) USing the Hardwa~ Configuration 1001; at the same lime. you I15sign the communication, interfaces of these modules to a subnet. You Ihen define the communications relatioRJIbips bnwo these module, theconnedions - wilh the Network Configuration 1001 in the connection lable.
The Network Configuration tool allows graphical representation and documentation of lhe CQn fiillrcd networks and \heir nooe" You can

also croate all !I(X;cssary ,ubnets and stalions wi lh the Network Configuration tool; then you nS3 ign th e stati ons to the subncts and pdr~mc' teri7C Lhe node propenies of Ibe modules with communications capability,
You can proceed as folio.,...,. to define the com nllmications relationships via Ihe networkina confi&uration tool:
f>

In the upper section, the NetwoO: Con figun.. tlon window shows all previously Cfated ~ub nets and stations (nodes) in the project with the configur~d connections (Figure 2.5) , The cOIU'e<: !ion table is displayed ;n the lower sec tion oflhe window if n module with "communicalionscapabilityH, e.g. an 57-400 CPU, i5 selected in the upper section of the window.
A second window displays the network object ca"log with a selection of the available S!)-lATiC lations, subnets and DP stations. You can rade the catalog in and out with Vlf'w -+ CATALOG and you can "dock'" it onlO the ri&ht edge of tbe network wLOOow(doubledick on the title bar). With VIEw _ ZOOM II", VII,,,, ..... ZooM O UT and VlliW _ ZOO:.t f ACTOR .... you ca'l adjust the clarity of tile graphical representat;on,

Open the M I'l subnet created 11$ scandard in the projCCt cootaincr (ifit is DO Innaer IvailIble, 8imply create a ne'" suhnet willI 1l"5ERT _ SUII:>CIET).
Use the :-"elwo"" Configuration 1001 to C~ ate the necessary . talions and - if required funher sl.lbnets. Open the station. and provide them with Ihe modules with commun icalion! capability. Connect the modules with the relevanl subnelS.
Adapt the ne\Work parame1C1"!1. if DeIBry.

c>

po po

2.4.1

Configuring th e ,,",f two rk lind


arran glnlllh~

VI~w

StI~cIIO I:

(omponentl

I>

c>

Oefine the commuoication connections in Ihe connection lable, ifrequiTed.

You can .lso configure global data communications wilhin the Net ....ork Configu"'tion: $Clect the MPI liubnet and then r.ele<:t Opno:-;s ... O~ft:-'I! Gl.olIAl DATA (see Chpter 20,j"Global Data Communication").

You begin the ~etwork Configuration by nlectina; I suboel that you selftl in the cataloa; ,,;tb the mouse, hold and draa; to the network window. The suboel is represented in the win dow as II bnrizontal line. Impermissible polIi_ tions are mdicatcd wilb II "prohibitcd" sign on Ibe moUse pointer. You proceed in the !>ame way fOf th~ d~sireG stat ions. at fi !"$1 without connect.on to the sub-

.,
lor ... .. .,. m ",-

,-

r:=0i-:. i ;;;;;;'
.....
. .J _

- '" ..... . ... ...... -0

...-

-\""

.. . . .............
-';;' ''. ._ 1

..l _~ "

. "' ."

......

. . .1 -""''''' . >'0 J _

" :::11'_ " --''' ...1<'_ -, -",,,,,,,

>-

is=-

--

net. Tbe stations arc ,till "empty" , A doubl~ elicit un a stallOD opens the Hardware Configu ratinn tool allowinll you to configure 1lI0 SIIUon or a1 least the module(s) with nelwurk conn~c lioD. Save the station and rerum In the Net ..... ork
Configuration_

S.-n ina; cO nlrnllniu lion. propenies


A nOT C"'3.;n8 th~ graphic~1 view. you parame terize the 'lIbnel>: select the subne~ and then
EDIT ..... OBJECT PROPERTIES . The properties

Th e interface of a module .... ith communi.:a[;Olu; ~apabil;!y is represemed in the Nem'orl< Confiaur;r.lion as a small box undcr the module vicw, Click on this box, hold and dlllg ill<) the ...,!evaot subneL The conncction In the saboel is

-.

represemcd as ... ,erticall ine.


p~

in exactly the s.ame way wilh aU other

window that then appcan; indudes Ihe S7 ~ub net 10 in the "GenenoJ" tab. The !D consislS of IwO hexadedllllli numbers. the project number and Ihe ,ubn~1 number. You n:quin: th is S7 ~ub net 10 if YOIl Want \0 go online wnh the pro~rnmmmg device" "hout suitable projecl in omer to reach other nodes via the subne!. You set the netv.'orlr; propct1;C$ in the "Network Set linlfl"lab. e.g. the data transfer m lc Or the high est node addr<."is. When y"u s"I<:<:1 Ibe network connection of a tlo<k. you Can define the network. propcnies o f the node "';Ih EDIT ..... OI!JEC"T PROPI:RTIES. e,g. , Ihe node address MId the subnet it is connected to. Dr YOII can create a new SlIhnc!. On Ihe "lnll:-rlaces" tab o f lhc station propcnies, you can sec an overview of all modules with

You Can move cnated subnels and S!arions in


the network window. Tn this way, >'00 ean al..,

represent your hardware cun figu!'\Ition visually_


Under cenain cin:wrutances. you itl a clea ...... and ~ con.paCl ImmgC11l<'nt If you t't'duce reprosc me<l subnet lenaths with VIEW .....
REDUCW SU II:'>"ET tl:.....Gnts.

2 STEP 7 prognomming Softw.,.., You can only connect an intelligent OP ,lave to a suboct if you bav~ previously en::nled it (see Cllapler 20.4.2 "Configuring PROFlHUS OP"). In Ihe n~...rk object catalog. you can find the type of imel1iilcnt 01' IiIn,"C under "A lready created slations; drug it. with the OP master sclcct~d. to the network window and fill out the properties windOW that then uppcnl"'l (as in the Hardware Configuratiol1toolj. Wi!h VIEW ..... 111G11I. JOIlT ..... YfA~Tr.R SYS"nM. you emphasize the assignment of the node. ofa Df' master system; l1rst, you ulcel the master or II slave o[this master system. With VltW ..... REJ\RR~""GE, the OP slavcs life a!<5igned optically to their OP mast~..... I-'ROHNl:T 10 In order to configure a PROF INET 10 ~YMcm. yuu reqUIre :
I>

communications capability. wilh Ihc nodc addresses and the subnel types US4..t You define !he moduk properties of the node!o in I similar way (with the same operalor inputs D.S in the I r ard"'~re Configuratiun 1001).

2.4.2

ConfigurIng alli>clribu led 110 wltll fhe Network ConfiguratIon

You can aloo use the Network Conligur~lion to) configun: the distributed 1/0 with PROF"rRUS OP or PROFNET 10. Sclcrt VlEw ..... WITH DP SLJ\vLVl O D vrclOs 10 display or Iilde 01.11 Oi> slaves and 1 devicC"S in the neN"Ork view. 0

PROF'IBUS OP
You require the follow,ng in ullier to configure a OP maRter ~y.tem :
I>

i\ PROFIBUS subnel (i f not already avuil-

Kblc, drug th~ PROFlBUS subn~t frotn Ihe nelwurk ubjed ~atalog to the network window),
I>

An Industrial Ethernet subnet (i f not already available. drag Ihe Industri al Ethcrnet subnct from the network object catalog to Ihe nctwork window) An [0 controller in a sllItion (if not already available, drag the stalion from the netwOTk obj~"Ct catalog to the network window. opctl the station. and .'II~t lID 10 controller with Ihe Hardware ConCigurnlion 1001. either intcgrated in the CPl: or liS nn autonomous module) The connC<:tion from thc 10 controller to the Industrial Fth~=et subncI (either already selccl the 'UbnCI in the lIardware Configuration 1001. or click un the nerv.'or\( eonnec_ lion 10 the 10 contruller in the Network Configuralion, "hold" und drag 10 the Indus_ tria l Ethernet network

A Dj> m"stcr in a stalion (if nOI aJrclldy available. drag thc stalion from Ihc nctwork object ealalog 10 the network window. open the 51ation and select a DP master wilb the HardWllre Configuration 1001, either inlegr.lled in the CPU or 8.. an autonomous mooule). from the OP mastcr to the PROFmuS suhnet (~ithcr select the subnct in Ihe Hardwan:: Configuratiun 1001 or ehek on the network connection lU!he OP ma.<ter in rhe Network ContigUflltion, "hold" nnd drng to the PROFm"L-S nClv.ork).

I>

The:

<;OfIn~"Ction

I>

In Ihe network window, seleC1 the Dr ma!Oter 10 whicll Ihe dave is 10 ~ assigned. find the OP sllOve in the network object calalog under "P ROFmUS UP" and the relevant suiH>lItlilog. d!":lg it to the network window and fill 01.11 the propcnies window thaI "ppea",. Yo u panuneteru:e the 01' slave by ~~I~C1iDg it and then !lel~cting J:;J)fT ..... OrEN OBJECT. Th~ Hardwanl Configunuion is started. Now you can ~et the user data addresses or. in the case of modular lilaves. select the lIO modules (~e Chnpter 2.3 "Contiguring Stat ions).

In the nClwurk window, SCkct the J() controller


10 which the 10 device ;$ to be assigned. Find Ihe 10 de,'ice in !he network obje<.:t catalog under PROFi}.'ET 10" and the relennl .ub-

catalog. drag it to the network window and fi ll out the properties window that appears. You parameterizc the 10 device by selecting it

and then selecting EDIT ..... Opo; OIlJECT. The HndwlU"C Configuratiun ;$ staned. Now you
can ""I the user data tt<.ldresse~ or the 1 0 mod/ ules (sec Chapter 2.3 "Confi guring Station.").

"

2.4 Configuring the Network With VIEW ---> Hl(.ID.1GHT ---> PROFiNET 10 5\'STL\1. you emphasize the assignment of the nodes of a PROFINET 10 system; rUSt, you select the 10 controller or an 10 devic~, \Vith VlliW ---> REARRA:-';C,E, the 10 devices are assigned optically to their 10 controller.

tion in the Same way as a double-click on a subnet;n the project con~,incr , To configure the conncction" select e .g. an S7400 CP U in the Nem'ork Contigurm ion , In thc \0"('1' section of the nem'ork w indow, you get the connection table (Table 2, I: ifit is not visi ble, place the mouSe pointer on the lowcr cdge of the "'i ndow until it changos sbapc and then drag the w indow edge up), You enter a new communication connection with \r-;SERT ---> KI\\' CON"E.'IO:-'; or by double -clicking on an empty line . You cre3l~ a connection for each "active CPU. Please note that you cannot creatc a connection table for an S7-300 CPU; 57-.100 CPUs can otlly be "passive" panncrs in an 57 connection, In the "'New Cotlllection" window, you selcct tbe eommunkation~ partner ;tl 'he "Station" and "Modulc"' dialog boxcs (Figure 2.6); the .Italion and th e module mu~t already exist. You also detennine the connection type in tbis window. If you want to Set more connection properties, activate the cheek 00" "Before inserting' disp lay propenies". The connection table contains all data of the configured connections, To be able to display this clearly, usc V IEW ---> 0l'TlMT F COLlJM"I 7 WIDTII and VIEW ---> DISPLAY COl=S and select the information you arc interested in. ConnectIon
[l)

2.4.3

Co nti,"u ring Connecnons

Connections describe the communicati(ms rdation,hips between m'o devices . Connection.' must be configured if "' you wam to establish S7 communkations bem'een two SIMATlC S7 d~v i ccs ("Com munication via configur~d connections'') or
t>

the communications SI"'lATlC 57 device ,

panner

i,

not

Note: you do not require a configured connection for di",ct online conncc tion of a programming device to the MPI network for program ming Or debugging. Jf you wam to reach oth", nodcs arranged in O!her conne<:ted subnet' w ith the programming device, you mu~t configure th e cotlllcction of the programming device: in the Network Object Catalog. sdcct the PGIPC object undcr Stations by double cl icki ng, open PGIPC in the network window by double clicking. and ,eleclthe intcrface and assign it 10 a .ubnet,
Conn~"t lon tabl~

The commnnications connUlioru; arC config ured in the cotlllection tahle. Requin:mcnt : you have creat~d a project with all ,lations thai are to exchange dam with each other, and YOll have ,"s igned Ihe module. with commun ications capability 10 a ,ubtlet, Thc object Connecrio",,' in the CPU containcr repre,ents the connection lable. A doubleclick on Connections starts the Nem'ork Configura-

The nnmber of possiblc connections is CPU 'pecific, STEP 7 define, a connection 10 for every eOtlllection and for every partner. You require this ~pecificatioll when you u,c communications b locks in your program. You ean modify the 10CQIID (the connection ID of the currently opencd module). This is nece,-

Tabt e 2.1 Conneclion Table Example


P~rtners

2 STEP 7 progralDming Sofu... rc

Ii

j ,

"""'~ I

,1
,co< "".

L>o4~f"'_ ~--~~

r
r
;C'

,,,,,,p,,-,
l_",toI

f -

I'
Sont _ _ _ _
~~~

""";11

,,

r,-'",-rawo;;:."

..

.r

~ '~obI"'~~_

~d

TI :
'I

,I

I
3
1

1 1
- -- --

-~
~

t"iRu 2.6 ConfL guriog CommWlicatioru Connoclioru

.. IJ

.ary if you have a lready programmed commu n icali on < blocks and you want to u<e lhe local [D ,;pecified there for the ~onnection You enter the new local 10 as a hexadecimal number. it must be within the following value ranges, depending on (he connection type . nd m ust not already be assigned,
t>

Partne,.,. lbis column disp lays the connection partner. If you want to re>crvc a connection resource without naming a panncr device . ~"Ilter "nspedfied" in the dialog box u nder Station In a on e-way connectlun. "ornmunkation can only be initiated from one partner; ~x ,unple : S7 conmmnication. between an S7-400 and S7300 CPU. Even without S7 communications function, 1n the S7-300-CPU, data can be exchanged by an S7_400 CPU with SFB 14 GET and SPB 15 PUT. In the S7_300, no user program run. for this communication but the data c.~chan;;e is handled by th. operati ng <;ys-

Value

rang~

for S7 connections:

00011><, to OFPP h<.,


t>

Value rang~ for S7 connections with load able S7 communications (S7-300) : 0001"". to 008F hex Valuc range for PIP connection>: 10rxlt,., to 1400 he ,

f>

"m

You cbange the partner II) by going to the ~on nection table of the partner CPU and changing (what is then) the local 10: sel~""t lhe conne ction line and then EDIT ..... OBJECT PROP 5RTlIS If STEP 7 does nOl enter a partner TO, it is a one-way connection (sec below) .

A one-way connection is configured in the connection table of the "active'" CPU Only the n does STEP 7 a.;;ign a "Lo~allD . You also loa d this c0nne~tion only in the local station. Wi th a two_way cunn~ction, both partners Can asS lmle communicat ion actively: e.g. two S7400 CPU s with the comnmnication,; functions SFB 8 SE:'>ID and SFB 9 BRCV.

2.4 Confi!! .... ring the Networi< Vou configure a TWo-way connection only once for one of the IWO panners. STEP 7 then assigns a "LocaIIO" and a "Panner 10" and vcncno1c.l the conneetion data for both staUon~. You mu~t load each ""nncr " ';Ih ils own cOMection table. Co"n lion lype The ST EP 7 BlI!l;c Package provides you "'ilh the following connc.:t;on f)-pcs;n Ihe Net"ork Configuration:
PIP connc.:! lu n. approved for Ihe ~ubnel PTP (J964(R) and RK 512 procedures) with S7 communicalion~. A PIP (poinl-to-point) eODneclion i. a $Crial conneclion belween IWO I"'nne"'_ These can be IWO S IMATIC 57 device~ wilh Ihe relevllnt lDleTface! or CPs. or a SIMATI C 57 device Imd a non-Siemens devicc. e.g. It printer or a barcode rcadCT.

S"ndlnlil operu!n!: n. l"

me~.a lilrs

ConnlXlion ""nne", wilh a configured twOw"Y cOMterion can exclumge operating ~Iate messages. Iflhe local nO<ic is to send il5 operaling stal~ m~<;;ages. aClivate the ,levanl ehc:ck bo", in me propenics wiodow oflhe cOMeclion. In the uSCr program of me panncr C PU. Ihese messalil"s can be receIVed wilh SFB 23 USTA-

TUS.
Con ne ctio n pa lh
As th~ connecl;on palh hc propenie~ window

57 connectlon , approved for Ihe s. . bne\s MPI. PROFIB U5 and Industrin l Etllenlel Wilh S7 communic ation. All 57 conneClion is the connIXlioll between SIMAT IC S7 dcvices and call include pro!;l"'lmming devices and human machine inlerface devices, Datil arc exchallged via Ihe S7 "ollllection, or progl1lmming amI control functions arc ex....:uted. F.ult_tol .. ranl 57 ~on n eellon . approved for the subn~1s PRO Fl J:jUS and Industrial Ethernet wilh 57 communication s. A fault-toleTant 57 eOM IXtion ;$ mllde betwn fauh-Ioleram S IMATIC 57 devices and il can also be utablishM 10 an appropriately equ.pped PC. The software componenl "51MATIC NC~l", which is pari of STEP 7. ;5 a\,II;I.ble for p .... m<'le riz[n C Ps. Vou have conneclion types available for selection: fMS eonn"":lion. FOL eonllection. ISO Inln~pon eonneClion, ISO-on- Tel' "oMection. TCP eonneclion_ UO P connection and I'-maii "onn"":lion. AClive
con n~e!ion

COMIXlion displays the end points oflhe connection and me subnets ov~r which Ihe oonnect;on runS. If mere are sevet1l1 5ubnet~ for Sdeclion. 5TEP 7 selects Ihem in Ihe o rder Industrial Ethernel belo' Indust,;al Ethernet! TCP-ll' before MPI before I'ROFJllUS.

ofm~

The stalion and the CPU ovCr which the con


nCClion runs are displayed as the e tld points of Ih e connlXlion T he modules wilh communica_ lions capability are listed under Interface. specifying Ihe rack number ""d the sIN. lfboth CPUs are located ill the same rnck (e.g. 57-400 CPU. in multiprocessor mode), Ihc display box shows "PLC-intemal". Vou will Ih~n sec the MPI add,u or PROF Inus address of the node: ullder "SubnCI" and ,\ddrcss. Cu nn t loo5
b~tween

proj e<:u

For dina c"(change belween tWO 57 modul..,~ belonging 10 difTCTCIlI 5IMATIC projects. you enlC" ,m~peeified" for connection panner in Ihe conneclion table (in me local stalion in both projects). I' lea"" ensure Ihal Ihc eonneclion data ag'c in bolh projects (STEP 7 docs not (:heck .his). After ""ving and (:ompiling. you luad Ihe COnnection dina inlo Ihe local stalion in el1l; h project.

bu il du p

I'rior 10 the actual data transfer. Ih" eonneclion m LlS' be buill up (initialized). Iflhc con nection pann~rs have thi~ capability. you specifY here w hich device is 10 eSlabl;~ h th" conneclion. Vou do this wilh the check box "E~.abl; sh an aCI;ve conneclion" in Ih" properties window o f Ihe conn~""lioll (select the connection and thcll EDIT ~ Gilmer PROPIlRTlFS).

If a project is 10 subsequently become pan ofa mulliprojeCI. snd if .he connection panncr is also within a projecl oflhe multiprojcct. select "In unl<1lown proj ect"' as the c,,"nectio" panncr. and enter an ullambiguous eom' cel;OIl name (reference) ill the propeni"5 window.

"

2 STEP 7 Progranuning Software

Connection to n on-S1 st ations


Within a project, you can also speeiry stati ons other than S 7 stations as connection partners:
I>

Oth~,. Slation, (non-Siemens device, and also S7 stati ons in anom ...,. project)

ASSIGN PG/PC. This aJarlS the interfaces of the programming device to the conftgured set1ing thc tings for the subne!. Before disconne c programm ing device again from the subncl, select PLC --. CA"S"CEL l'G/PC AsslU~"

I> I>

Programmi ng devices/PC. SIMATIC S5 station,

A rt:qtrircm<:m for configuring the conne ction i, that the non-S 7 station exists as an obje~t in the proj ect container an d you have connectcd the non-S7 station to the ",levant subnet in the ,tarion properties (e ,g. select the station in the Network Con figuration, sdect Eun --. O!lJElT PROPIiRTlFS and COtlllect the station with the desircd subnet on the "Interfaces" tab)

If you go online with a programming device th"t doe s nO! contain the right project. you require the S7 ,ubnet ID for network acee". The S7 subnet IV ~()mprises "'m numbers: Ihc pT<>ject nllm lK'T an d the subnetnllmber. Y,m can ohtain th e <uhnel 10 in thc nctwoTk conftgura_ tion by ,electing the <uhncr an d thcn EDIT ---> OIlJECT PROPERTIES on I he "Gencra1" tah.

1.4.5

Loading th~ Connection Data

2.4.4

G8tew.y~

If the programmmg dcvi~c is ~onnected 10 a

To activate the c"nncctions, you must load the conncction lable into the PLC following saving and compiling (all connection ta bles into all 'active'" CPUs) , Requiremelll: Yon are in Ihc network wi ndow and Ihe connection table is visible , The prograrruning device is a t\Ode or the s uhnet over which the connection data arc 10 be loaded into Ihc modu les with conununication. capability, All subnct nodes have been assigned unique node addr~sscs. The modules to which connection data are to be transrem.:d arc in thc STOP mode. With PLC ---> Oov.'}.'LOAVTOCURRENT PROJECT ---> . ,, ' you transfer the <:onncction and configuralion data 10 thc accessible modules. Depen ding on which ohjeci is sc1~ctcd and which m enu conunand is selted. you ~an ~hoosc between the following ---> SIoLIClloU STATIONS

<ubnet. it can reach all othcr nlxlos on this subnet. t"or example, [rom one connection poinl, you can progmm and debug all S7 stations ~on nectcd 10 an MJ'I ncnvork If anoth~r subncI such as a PROFIBUS subnet is connected 10 an S7 station, thc programm ing d~vicc can also rea<:h thc Slations on the other subnet . The requiremcnt fm thi, is tha t the station with the subnct trans ition h as routing capab ility. th at is, it will channel the transf~m.:d message frame.. When the network configuralion is compiled, routing tables containing all the necessary in fornmtion arc automat ically gcncrat~d for the stations with .uhnel lransitions . Al l acc ess ih le cOlIUllunications partner< mmt ~ configured in a piant n~lwork wilhin an S7 rmjecl and must ~ supplied with th~ "knowledge" of wh ich .tatioru; can bcrcached via which suhnets an d subnel transilions.

---> --->

SELIoCTED AND PART'<ER STA TIONS S TATIONS 01\- TI lE SUH" "ET

If you want to re"ch allnodcs in a subnet with a programming dcvice from One connection point . you must configun.: the comlection point, You etller a '-placeholder", a PG/PC station rrom the Network Objc~t Catalog in th e network contiguration at the relevant subne!. YOl< contigu", a PG/PC station on every subn~.., to whi ch you want to ~onnCCI a programming devic e.
During operation , you connect the programming d~vice to the subn~1 and .dect PLC --.

--. S ElECTED CO"'N"lTTIONS


--. CONNECTIONS AND

GATEWAYS

In order to delete all connections of a programmahle module. load an empty connection lab le into Ihe as<ociated module. TI, e compiled connection data ar~ also a component part of the System d<Jla in th~ Blocks contain~L Transfer of Ihe systcm dala and the subsequem slartup of the CPUs clTcctively al<o

2.4 O m figuring the Network

tmnsf<.-n th .... Cf>nnecti on data to the mod ules ",ith communica tions capability_ F or online operation via iYfP L a programm"'g dtwi~c r~ql1lre~ no additional h ardware . If you ~onneet a PC to a network Or if you connec t a p rogramming device to an Ethernet o r PROFl_ B U S network, you require th .... relevant int.... rFace module. You parameterize the module w ilh the appli cation " Sening the PGIPC Interfa~c" in th e \Vindows Control Panel.

p rojects present in the mu lti p roject and thc cro,-,-projcct subnets which have a lr.... ady ~n combined , Select a project for flmher pr<><:essing by double d ick in., (Fig"rc 2,7) _ Proj ects usually contain communications con nec tions between thc in dividual statio ns. If projects are combined into " muJtiproj~et, or if Hn e.~ istiI\g prujcd is indudtd inUl the mult i~ proj ect . these connections c all be combincd a nd matched If you ,eket VlloW ----> CROSS-PROJECT NETWORK VIEW in an opened project that belongs 10 a multiprojcet, you will see an overview of a ll stations ofthe mu ltiproject and the current connections. In th e cross-project network view. yon cannot make any change, to the projec ts. Sckcting VIEW ----t CROSS-PROJECT NETWOR K VIEW " g a in exits the multi proj ect vicw.

2 .4.6

-"la t ching ['roj ect . In a l\ l ultlprojec t

Wben opening a multiproject with the Network Conligurat ion tool, a window is displayed with the projec15 present in the muJt iprojcct. You a l,o o btain this window i f you open a projec t included in a multiprojcct and select VlE\\ ----> MIILTlPROJE<:'"T. The window d i"play< the

~~p-

... ::!iiI'"'" """"-, , ...., l:..bo<b =~ 0'0 '-"'-' '; if ~"" - c_"
t""", ...... ,,_~""

:..:l'""'""'''''' """'" ... _ , .- ,",,-,, '""I "' . ,......""a" ....""


'"~tAO

'"

,,", eo~

L _'..M_""" "",-, _
cv..... ""'~".

c.""",,,, ,..."-"",,

8'""""""""_

,i '''---'''' .. '"
!fu. _ _
{_

II CP>J"<C-lQr' '; III s,.... 'OC3X(.l) SC ""'"' ~A" '_OC""

,I M_
~

tw ,,,e, Of'

"It:m:\)

.r-.

1" __

F ig u c. 2. 7 Mu l1 iproje<ot in the Network Con fig uration tooJ

3 -1
I

...:.~.J. __ t,

2 STEP 7 PToiramming Software Com bining


5 uhne t~

The MPI. PROFIRUS and IndusniBI Ethernet subnelSarc combined togelhcr first. A p=<'qui.ilc ill that the subnel8 10 be combino:d ha,'e the same subnel 10. Wim the subtlel seleclo:d. you can set thcse in the Network Configuration tool using EmT ~ OllmCT PKOPERT!S. With F ILl; ~ MUU1 PROJECT ~ ADJUST PROJECTS you CDn ClIlI 8 wi""ro fDr mn open multiproject in the S IMATIC Ma".ger which supporn you wMn matcbing. In the N~'1,.-ork Configurntion fool. you obtain the dialoi win_ dow with EDIT ~ MERGF.Jut.,'MERGJ; SLfJ"ETWORKS
~

ners. Select EDtT ~ M ~RGE CONNECftONS to oblB;n a dialog box with all configured eonnections. SelecI One connection in each oftbc Window$ "Connections .....11hout conne<:lion part_ ner" and "Possible connection partners" and cltck "Assign". The aMigned coonections a~ li.lted in the bonum window "Assigned conncelions" . Use "MCl"ic" 10 then combine the Con_ nections. The cOOllections arc assigned the properties of the I<)<:al mooule of the current ly opened project. You ean mooity thc connection properties wben combintng. Con ngu rl ng croS5- projt<:t eonnectio ns Followi ng the combinalion o f ",bnet~. crossproject conn~-Clions can be confi gured . The proeo:durc ;s the SIIITIe PS for project_inlernal con_ n.,.,.-tion$" extcndo:d by specification of tbe: project atllie connection panner. You can tcst a nct ..... ork configurati on in the
m~ltiprojec l for comrn<Jictions with N ETW'ORK ~ CHEC K CROSS-pII.OJl:cr (:O;';SISTK'!CV.

...

You ,elect the type of subnet. ~\ick the Exe cutc" bulton. and obtain the suOOe" of the selected l)lpe "",:>ent in the multiproje.:t. You can now select indIvidual suOOe!' of~ projects. and combine in U CTOIIs-pmject suboet. You CIIlI use tbe same dialog 10 eliminate sublWts from the ero&~-pmje<.. sub""l. '1 Several cross-project .ubnc13 of the same type can be created in ~ multiproject. The properties of the cro-project sulme! arc ru.'1ennined by the fint .u~t added or by thc subnet sdecto:d wilh the "Select" bullon. Use ~OK" or-Applyto acknow'tcdie the ""nings_ Subnct$ ..... h,ch are pan ofa cross-projCCt .ubne! B~ idenlifie<J by a different symbol in the SIMATIC Manager. C o n,bln lng
~unn~~tlon .

2.S
2.5.1

C r ealing th e S 7 P rogram
IntrOdu ctin n

The connC<'tions configurt"<J in slOal", proj~cts which lead to a partner in another proj1 ean be combined 10 a muiliprojccl. If you select the pann~r "In unknown project"" when configuring conneclionl in II smgl'" proje~t in Ihe win_ do ..... "Insert new conn""'ti",," . you can subsequently enter a conneclion nam", (reference) in the window "Propenies - S7 connection". Con_ nections in diffen:nt projO"Cts with the same connO"Clioo names CIUl be comhined autom,,,i. cally_ In Ihe SIMATI C MBltagcr, Ibis is cMmed out by the w izard for project malch ing if you cl ick "Combine connO"Ctions" and E~ecule. Connections a~ Ihen combined which have identi cal connO"Ction names (reference). In the Ne","-ork Configuration 1001. you ean also combine conne<:lion' willt "unspecified" part_

The U.'ICt program is crealed under the object S7 Progrom_ You ean flS.!:ii" this ohjecl in lhe

projecl blerarchy ofa CPU or you CBlt c~atc it iDltcpendently of a CPU. It conlllins the object S)""'/><)/5 and Ih~ containcrs SOI<Ifi'.l" and BloclcJ (Figure 2.8) .

With Ine ri'm ental program crealion, you ~nt~r th c program d ir~et block-by-block. t:nnies are checked im tncdimely fOT synta;>t. At the same time. the block is compiled as ;t is saved and lhen slo~d in the containCT Blocks. With incrcmenta! programming. you can alS() ~dit blocks online in the CPU. even during operation. I IlC~mCl1tal programming is P<lssibl~ in all the balIie languagC"'l. In tnc caSC of sou" ~ .... ri cnfcd pro&fBlll ere ulion. you wme one or mor~ prolP"lUJl sooree" a nd store these in the container Suurces . Progmtn ,o ...rees are ASC U text tiles that contain Inc program .lat~mcnts for on~ oT more bloch, po~sibly eVCD for the emire program . Yoo compile these sources and you gCi the compiled blockll in the contai ...... Blocks. SOUrce-ori(111ed prugnltn creation is used in STL and SCL: you cannot use soun:c-ori(11led PTOlPl'mming wi,h LAD or f 13 D. but programs created with LAD OT fB I) can ~ stored as KlUree l11es. T ho .~i gnal Slatcs or th e values of nddresses arc I'roc:..o:t.~d '" th~ ~t()~a",. i\n ~~.. ,~. ,<:>' e:<ampl<:, the input 11.0 (ab,wluw "'Jdrcsy;ng). Wilh the help of the Syn.bo l T. b k under the object Symbols. you can alisip a symbol (an alphanumeric name. e.g. "Swilch motor on") to an ISddrc$S and then access it wilh this nam., ("y",bollc addT"C.Jsing). In Ih~ properties of th~ omine ohjcct container Bladt_f. you .<l"'C"ity whether in the event of a chanac in the Symbol Tu blc the absolute addre~~ or the ~ymbol is to be defioitive for the already compi led blocks when next s.. >'oo (address priority) ,

out Ihe enlin; progrtlm and has the Same ",,"an_ ing in.11 blocks. You deline global symbols in the symbol table (obj ~cl Sy",I,,,I. in the contain<''1"S7 Program).
A gloNI symbol starts with an alpha chm"cte, and can be up to 24 characters lona:. A global symbol cBn also comain splICes. spcci.d chame_ ICTII and narional characters such as the umlaut. Exce ptioru; to this an: the characters oo...,A. FF""Aand the inverted commas ("). You must enclose symbols w ith special charaete", in invened commas when proafa1l1ming , In Ihe compiled block, the program edilor d isplays all global ~ymbols in inverted commas. The symbol cOmment can ~ up to 80 churnetcrs long ,

In the symbol table you can assign RPm"" to the following a<kJn,,;ses and objeclS:
po

lnplns I, OUtpUIS Q, pcnpheral inpulll PI and pcriphCT1l1 outpulS PQ

to to to
;>

Memory hits M. t,mef funclio"" T and coumer functions C Code blocks OU~, FBs. FCs. SfCs. SFTh and dam blocks DBs User data types UDn Vanable table VAT

DaT addresses in the data blocks are included a amonll the local " ddresse~: the 8ti.1OCi",ed symbols are defined in the dcelHrolion $<.."<:tion of the data block in 'he case of 1I1obat dnm blocks Hnd in thc declaration sec lion of tile function block in the case of instance datil btoc~$. When creating an S7 ProflUll, the SIMATIC Manager also cr.;:alCS an empty symbol table 5)71,bols, YOll open this and can then deline the atobal symbols and assign them 10 absolute addresses (t'igure 2.9). Tho:n: e~n be only one singl~ symbol table in an 57 program. The dUla type i8 part of the deli <l ilion of a symbol. II defines 'pific propcnie! of Ihe d ata ~hind the symbol. essc",i~JI)' the represenlat;o n of the dala con!ent~. For example, the darn Type BOOL identifies. bmary ~'ariab\c and the dat. type Th;, designates a digital variable who~ COntents represent ~ l6-bit imeger. Please R!f~'1" to Cbapter 3.S "Variable.., Constants lind Data Types". it comains a detailed deS(ripl ion o f the data Iypes,

2.5.2 S)' mbol'h ble


In Ihe control program, you work with addresses; Ih<: ., ....e inputs, outpUIS. limcrs, bl ocks. You cao assign absolUle addresses (e.g. 11.0) or symbolic addr~,scs (e,g. Start signal). Symbolic adJn; , sinl! usc. nameS instead of the ftbsolutc address. You c.n mmke your program euier to n:ad by using meaninaful names In symbolic addressing. a dIstinction is made between local symbols and Jlluhul ~ymbo1<. A local symbol i. known only in the block in which it bas been d.,fined. Youcan u.-.c the same local .ymbol' in different block . for different purposcs . A global symbol is known through_

"

2 ST IiJ> 1 J>rogrammi.ng Soil ...."""

" " " " "

, ", ..
" , , "
0 0 ; 0 0 0

"N "N 0

" " " " ""

.,,
'.J
' .1

" " ., " ,


~,

" " "

"

EOII'

0, ....,,, on ~ "",,,0,, ." .. """'''l' ... ". po~',," , .". , t 1ft ."" .. E.JIO """''!Y '"' '" "" ... " .o ," ~ .. ''''''or ,! ~, .. '"JO d "",,,", ,, .o, .... '"II' "'""1."1 ..
~'''' """""" .. Io, PO_

' dol' . 0 -So..


,_,od

... ....,,.., .... """'''''1[


;

"" ....,.""l

'00. r.. " ....... ,at .,...",


... , ' ...

II.-

~ ..

'...- ..

La ....... " " ".... t ..

~ ~
~
~

""0- , ... """ ... ... """,... "'" 1 boO! mo'" 2 ,.." '"" ,.,.,..,.,. "",
C. "...., .... "'''' '0' "",., ...

.....".<t_.'
N....... .,1 .. "

R...... ,.10 '''''' ....

Swc<. c. bel" """,arlo; ""'.,......, .

.. n

;W"''' ''' """ ... '0< ""''''J'' .,"

With incremental programming. you ~f~ale the 1<)'mbol lable b~fo", .,m.,ring th~ prugrum; you call D ,dd or COlT<:<:t individual symbols dur IS!) illg rrovam illput, III the ca.,. of source-ori <,:med programm ing, th ~ complete .ymbol table ",u~1 be IVlilable w h..., th~ prognun &OlIree IS ,"""opi lcd.

Sprd a l obj <'t'l propertie.


Wilh ~DlT ..... SI'ECIAL ORl~T PROl'fRTtES .....

.. you ,..,t atlributcs for each symbol in the symbol cabl.,. The<c "tuibutes Or properties are u.cd 'n the follnwing:

Impu rtlni,:, Hportlng Symbc l t"bles can be imported and cX",,"cd. " Export ed' m~all!< a file is ~reated wi III th~ con 1ent~ o f your symbollab le. You can ""I~~t here either the ~ntire symbcl table. a rub ..."! hmit~ by filters or only selected line,_ For the dma for m it you cau ehno~ be-iwtttl pun: ASC II 161 (exumtton ' .88C), $C'quc-nlial a>..ignmenl lisl (*.S4"<1), SYbll;m 1l1"~ Fomtat ( .~f for Mierowft AC(:Css) ~n<l Data Interchange Format (,dif tOr Mi<--rosoft Excel). You can edit m e exportw file with a suitable editor_ Yuu~..n " Iso impurt a s),n bol table available in oDe of the fOmlb\S named above.

I>

Httman mach in ~ inlerface monitoring wilh WinCe


Configuring-me"agc~

fuTlclion~

for

I>

po

Configuring commun;ClI.ti<>TI~ NCM software

usin.:

lhe

po

Control al contact ",-ith inputs aDd bit memori~s in the program ed,tOr

\lrf:n' -+ COLUl-INS R , 0, M. C, CC males lhc settU:lI.' ,!sible_ Witb OntONS -+ CI:l'OmMrl.!;, you can ,.-pecity ,..heth<-"!" ()(" nut the special object properties are to be copied und you ean define heh"v;orwbcn importing ~ymbol~.

72

1.5.3

r ......gnun

t ltor ~d

For ~"'Rtjng the user pro&"Pnl. the SHoP 7 I3nsic P""kagecontains a progmm ed itor tor the LAD. FA D and STL pmgrammin& language . You program incrementally wuh LIID and FDD . Wt i~, you eoter an e~ecutable block di ........,t; Figure 2.10 shows Ihe possihle "Clions ror this. If you usc .ymbolie add~sing foc global .ddreS1e~. the symbol' ,mill already Ix: .. ~si8ned to "n absolute address io the case of

iO<,.....,lJ1ental programming; however, you can enter new symbo ls or change symbols during pn>!lnlm input.

LAD 'FBD bloch can be decompih,d, Le. a relldable block can be c""at~'U again from the Me7 code without an oftlioc database (you can read any block from a CPU using a prognommina device without the asso.:;ated project). In ...!diuon. an STL proglllm sou",,, ~&n be ereal~d from any compiled block .

I ~. ------------',,,,"",,,,'"""",,. '",
Source Import "x,-mal SOuroo

O1fttne

" r ----""'''''".':)

."'

..

~
InBlocI<s the PO

programming

Ontlne

L__

'~!.=~) ::o:

BlodCs

FI~ur~

1.10 Writing rftlirorn! " t!h the I-A[)fHl[) Ed",.>,.

2 STEP 1 t>rogramming Software


SCMr1lng t he program editor y"" reach ,he program ~ditor whom Y"" open a block in the SIMATIC Manag~r, ~ .&. byoouble clickin!! un the Mutomatically generated symbol orth~ Oraaoi7.8tioo block OR I, Ot via tbe Will dows 'Dskbar with START --> STM"'l"IC - I STEP
7 --> LAD. STL. FBD - PROGRAMMINU S7
BLOCKS.

The block window is automatically displayed wben openillg a block and contains me block interface at the fOp. i.e. the bluck pllrumeleno as well a~ Ihe sUllic and dynamic local dllla. You can program the bluck in the bottom program area. The block window aod the contcl\lS arc dellCribed in Chapter 3.3.2 '"Illock Window". The Ol'<"vi<'",s winduw Shows the pro~ ..,.am ele. ments and Ihe call structure. If;1 is nOI visible. display il on the screen u.ing VIEW --> OVER.
VIEWS.

You can customi:z~ th~ prol"'nje~ or the program editor with OJ'nONS --> CUSTOMl7F.. On th ~ "&ii,or" lah. >!CicCI thc prupcnies with which a new block is 10 be g~neratl and di .... played. ~...,h liS the ~"T<:ation langullge. pres<:lcction for commeots, aod symbols. Prog r am whor window Funher window~ can be di""layed within the window of the program editor: the bluck win dow, lbo: Vcrails and Overviews window~, and the window with Ihe AS regislct!< ( f igure 2.11).

The Details window can be displayed or sup' pressed usmg VIEw --> D t:.TA.lLS. It contains Ihe follo,,';ng \.abs:
Do

I: error ConUIlm; the errol'S foun<l in the bloclt:bylhe pmgram c<litor, e.g. fol1owilli <;olnpilmioll. With OPTIONS - I (''uSTOMI7.1l in tbe "Sources" tab you can SCI whethe r warning. arc also \0 be displayed.

. . ..
'"'' ' ,

- .--. -- ._... ......


-.~.,

.-.... __ .. .- ~....,..
~

_-

Ft~urc

2.' I Furnp]. of e<i i(or window ..

2: Info Contains information on the currently .~electcd ad<lress. 3: Cross-references Contains the references ofaddresscs present in the current network (see Chapter 1.~6 ~Refcratce Data").
4: Address info Contams the symbol mfonnation of the !Oddresses present in the current network (see Chap.er 1.~.2 "Symbol Table"). You can edit e"istinl! symbols hcre. an d nC\'. ones, and oh<erve the addre status. 5: Modify Conlains an empty table of variables in "'hich you can enterlheaddrcssc5 10 be: con1r01led (sec Chapter 2.7.3 "Moniloring and Modifying Variables''). 6: Diaanoslies Cnntain~" list with lite exis''''iI moni.orinil functions for process dialilnOSlics using .he S7-?O[A G option , package. 7: Comparison Contains the re.ults of a previously implemenn:d block comparison (sec Chapler "Comparing blocks").

SIMATl C Maoager provides an omine and an online Win dow: the one is d i.l;nguishcd from the olhel by Ihe labeling in Ihe litle bar. In the omine window, you edit the blocks righT in Ih~ PO database. lfyou are in Ihe edilor. you can SIO .... a modified block Tn Ihe OmiDe database with FILE -+ SAVe and " 'lnsfCT it 10 !he CPL with PLC -+ lJOWNLOAD. [f you ....'alI1 10 Ia"C the opened block undeT another numbcror in R diffc .... nt project. or if you want 10 lransfcr il 10 II library or to another CPU, use the menu command flU: -> SAVE AS. With the menu conunbnd FILE -+ STUIili REA.!). Ot-.L L. in the program edilor. you can save a "T1leprotecle<l CDpy of the currently opened (arid saved) block in anOlher block cODIlliner. To edtl " block in the CPU. open Iltat block in the onlinc window. This I.... nsfen the block from Ihe C PU to the Proiramming device so Ihal II C$n be ediled. You Can wrile the edilcd block back 10 the CPU with PLC -> DOWNLOAD. If the CPU is in RUN mode . the CP U will process Ihe edited block in the nc,,1 program SCan eyc1e . If you want 10 .ave a block that you edited onlil"\C in Ihe ominc database as ",ell. you ean do so with FI1.1i ...... SAVE. \Vilh incremental prognrnmina. you cao exc~ cUle all proaramming functions wilh one c.~cepTion: i f you want 10 provide block protection (KNOW_HOW_PROTI!CT). you can only do Ihis via a program Source file (soc Chapler 24 . 1 "Slock Prolection ror more detailed information on this \<>pic). ChaPler 2.6.4 Loadinll the U!;Cr Pro~..-am into Ihe CPU' lind Cbaptc!" 2.6.5 ~I:llock Handling' COOIBm fuTther information on onlil"\C programmmi. Chapler 3.3 "Programming Code Blocks" and Chapler 3.4 "Programming Data 8lo<"ks" show you how 10 enlcr a LADlFBD block.
D~~Qmpliation

I>

po

po

You can dock or undock the Oveni"...... and Dewil... windows at Ihe edge of lite edi.or win_ dow by double cliclcing the respee.ive .itle bar. The PLC ,...giner comem... window shows the content. of the CPU rCiliSlcrs (accumulators. address regislers and Oil reaislers). IneNmeDI. ] programmln ~ Wilh inc .... mental programming. you edil the blocks both in the offiine Ind online 8/ocb COIllainer. The editor ehecks your entries in the incremental mode as $OOn as you have terminaTed a network When the block is closed iT is immediaTely compiled. so thai only error-fTce block s ca n be saved. On Ihe "Block" lab under OI'TlONS -> Cusl'OMt;,:!', you .el automatic updaling of Ih~ .... f~ erence data wben saving a block. The bl~ks can he edlled bolh offline in the programming device', dallbase and online in the CPU. generally referred 10 as lhe "programmable Conlrolle ... . or PLC. For Ibis purpose. the

When Ihe program edilor opens a compilod block, il carries oUl a "de~ompilalion" into the LAO'FBO .... prescntanon. It uscs Ihe program components nOt .... I""amlo c)(eculion in lhe PO dala management in order to d isplay e.3- sym~ bois. comments and jump labels.lflhe information from Ihe PG data m~nag~ment is missing

2 STEI' 7 Prot!:ramming Softw,"", durina 1M de<.-ompilation. the ednor uses replacement symbols. Nelwort<.s which cannoI be dccompiled in LAD Of' FB D are displayed in STL UpdMtlo g vr .:e n c rMllng Soure., fli es On the "Sow-ces" tab under OPTION S -+ CUSTOMt7.E. you ,,~n sek"t the option "Gener.te souree alltomatically" SO that when you save an (incrementally c reated) block, the proiJ1llrl souree file is updated or creat~d. if it does !lOt already e~i~l. You can derive the name of a IlCw source tile from the absolute address or the symbolic address. The addn!'sscs can be tnln~fCl'T'Cd in absolule or symbolic fonn to the SOW"Ce file. With the "E:<ec;ute" button. you selcct. III the subsequenl dialog bo:<. the bloch fn)n1 ",hich you want to generate a program source file. With FILl! -+ GIlNfRATE SOURCE you can p ro duce ASCII source files from compiled blocks, First insert a Sow"es comaincr under the object S7 progmnt , Whcn generating the sou""c, 1 1t'S1 enter the stnrage location an,! the name of the source in the dispL ayed dialog box, ~nd subsequently SCICCllhe blocks. You can cxport SO~ files from the project by sdectina EOIT -+ ExPORT SoURCE in the SIMATIC Manager. You ca.o then fllnher pro cess these ASCII files with another tUt editor. for example. Source files can also be imported back into the Sow'Ces container witb I:o.:SCRT-+ EXn,IlNAL SOOKCI!. If you generate a source file from a blocklhat yOU have ~Teatcd wilh LAD or fl3D. you can generale a LAD or Fl3D block agkin from this sou",e file , You ~ompile the sou",c file by opening it in the SIMATIC Manager "'ilh II double.dick allll by then selecting Fit I> .... COMrtU! in the program edilor. An STL block is created in the Blocks container. You opc'n thi~ block and switch to your usual repre~nl&lion wilh Vt\lW -+ LAD or VIEw -+ fBD. After5lv. ing. the block n!'tlIins this propeny. If you sele<:ted tbe selling "Addresses - Symbolic" when creating the 50urce file. you require a complete symbol table for compiling the sourec file. In this w~y, you can specify dif ferent absolute addresses in the symbol table and. after compilation. you end up with a proiI'lII with. for example. different inputs and outputs. This allows you 10 adapl the program 10 a diffeI'O'nt hardware configuralion. For this purpo;;e, it is best to "lore tbcse JOUI"CC files (which are independent of the hardware addressing) in II library, for example. C ompMrlng hlock s The block comparison cnables you to find the differences between twO blocks. -[be block$ c an be pr<:~cnt in different projects. in different target systems (CPUs). or in one pffljcci and One I&!el .ystem. Use Ihe program editor to compar<: the OJ>CIled block witb the same block in the CPU or in tile project by using OPTIONS -+ COMPAKB ON-I OFFUl'.'E 1'A1lTNER. The resolt is displayed in the detail ar<:3 of the editor window in the tab "..,: Comparison". Mark tMe Blocks object in the SIMATIC Man _ ager. or only the b locks to be compared. and selecl OPTIONS -+ COMPARF. flLOCKS , The comparison is carried out either between the online and omine data managcment (ONUNFJ omine) Or hetv,-een two proj~-.;:ts (Path I/ Path2). \Vhen comparing the complele prog",m .... hicb can also includc tables of variable!! and user dala types (UDTs) - you can inoorponlle the system data. Wh-en using "ExC'Cute oodc comparison ~, tbe prog ...m code of the bloc"," is ~ompll1ed in addition. even orblock~ wilh dif. fercm generation language!!, The ~omparison includes all dala of ~ block. \lven its time stamp for progmm code and imerface. If you wish to know whcth~r the progT'Jrn code is identical independem of the block prop cnies, eomp ar<: lh~ ehcrksurn of the block. To do this. select the "Details" button in the re5UllS window ofthc b luck comparison.

2.5.4

Rewiring

The R""'iring function allows you to r<:1'1""" addres.<cs in individually compiled blocks or in the emire user flIViTaIlI. For example. you can replace input bilS I 0.0 10 I 0,7 with input bits I 16.0 to I 16.7. Permissible addrcsscs are inpulS, outputS, memory bits. timers and counters as well as functions fC. and function block!; FBs ,

76

In the SL\tATIC Manag(:r, you scle<:t the objects in ",hich ynu wish lD carry OUI !he ",wmng: seleel " smgle block, a group of blocks by holdina: Ctrl and c1kldna: with the mouse, or the emire Blocks user prognn", O PTIONS -jo R..t,wuu take. you 10 II table III which you cun ~'l1 t"r the o ld addresses to ~ replaced lind tbe new addresses, When you confirm wilb "OK", Ih c SIMATTC Manager Ihen exchnn!!cS the add resses. When "re"iring" bloch, change .he numbe .. ",f the bL ocks fif5t and then execute rewiring that changes lhe calb c~spondingl y. If you "rewire" I function block. its instance da\.ll block iI automatically assigned lD me rewired funclion block: the dala block number " 00. changed. Following n;wirina, an info file shows you in wbich block changes were made, and IIow many. The refer~nce dala arc no lon gcr LIp-to-date 1'01lowinl,l rewiring. and mu,l be regenerated. Please notc that "rewiring" only takes place in the compiled block.: a pWgraIn wurce. if present, is not m<.><lificd. Funher pOSsible meth<.>ds ",f rewiring are:
eo-

s)'mOOI changes accordingly. If "Symbol bas priority" i. set. the absolute address ebanges and the symbol is retained. Example:
The symbol table contains the fo1l0 .... inll:

I 1.D
I 1. 1

'Lt mit _a~ttth_up'

'Limit_switCh_down"

In the program of an already compiled bl<:x: k, input I 1.0 i, """nned:


I 1 . 0 "LUnie_ _ itdo_up"

!lOW

Tflhe Il!isignments fQr inputs I 1.0 and I 1.1 are changed in the symbol table to:

1 1. 0 '!..imit_a.dtch_doown" 1 1 . 1 'Ltmdt_cwitch_ up' and the already c"'mpil~d block is rtad OUl, then Ihe progmm e",ma;M

11.1 " LUni t __itc"_up'

if "S)-mbol has priori ty"' is ~et . and if" i\ Mo lute value has priority";s ~et . the proil's," contaius
I 1.0 "Limit_ awitch_down"

With compiled block.., Y"'u can also usc the Addren prioriry function. lflh,m: is a pmgntm source file with symbolic addre.~siog. you change the absolute addresses in the symbol mble. F"'llowing the compilation. you get aD "unwired" program.

I>

If. as a result of a change in 'he symbol labk, then: is nQ longer any assignment t>o:twcen an ab>.<.>lute address and a symbol, Ihe 5tntemeot ... il1 c",main the absolute addrcss ,f ,. Absol ute value has pri",rity- i. set (even with symbolic display bc<:ause the symbol would, of course. be missiog); if"Symool has priority" i~ 5<:t. the Statemem i. rejected as ~'1TQT"Cd (beca use Ihe mandat<.>ry absolute address is missing).
If "Symbol has pri"'rity" is set. increm~... ta lly programmed b!a<: ks with ~ymbol;~ addressing WIll retain {heir symbols in {he even! of a ~han8c to the <ymbol table . [n this way. all already programmed block can be "rewin:d" by changing 1he address "ssianmen!.

2.~.~

Addrc~.

Priority

In the prop4T1ies wind",w ",f the ominc object CODminer Blad:.: on lh~ '"Address priority'" tab, you can .~t whcthcr lhe Ilhs<.>luI~ Itdd"'S$ or the ~y,"bol i, 10 bave pri",ricy for already saved blockJ ....ben they are displayed and saved again follo"'II1g a change I", tbe symbollable Qr 1 tbe 0 declarati",n o r .s~;gnmCflI Qf global data block . The def~ult i, "AbwlulC value has prionty" (the s~me behavior as in the previ"'U5 STEP 7 wMlions). This dd~ult means thm when a cban!!~ is milk in the symbol table. Ihe absolu te address i~ remined ;0 the prograll1 ulld the

Pleaoe nme that this "rcwirina" does nm occur Ilutumatically bc<:all,<e the already compiled blocks confaio [he executable MC7 code of lbc Statements .... ith abwlute addresses. The "baoge is QnJy madc in the rele'"l1nt bl<.>ek - following 11K- "'\c''3.0t messagc- after it bas been opened and ~yed agaio. W order to carry outlhe change in thC complete block folder. select EOIT -jo CIIECK BLOCl( CONSISTENCY with the Blocks object mark .. d.

"

2 STEP 7 I'fn&nn\ming Sotl~

2.5.6

Reference

0.,.

As ~ supplement '0 Ihe program itself. 'he SIMATIC Manager 5hows you Ihe refcn:nee data. ,,hieh you "lUI usc the hasis for 'oncelions or lests. Thew refc-rence data mdude Ihe following:

compiling a program source file or when 5IIving an in,rememally WTiIl\!"I1 block. Please note thaI the refcl"e11cc data are only avail able .... hen the dala are managed omine; tb<e offline n;fereoce dala ~ displayed e'C"II if tbe function is called m a block opened online. C r oss r t fc ....'IIce. The cross-reference list shows the Uj.C of the ad~. and blocks in Ihe user program. II inclU<k, lhe absolute addR"Ss, Ihe symbol (if any). the block in .....hich the addn-ss was used, how it wu used (read or write) and th~ posi_ tions of usc of the addre.s. Click On a ~ol umn header 10 sort the table by ~olumn comenl~.

Cross referencc~ po Assignment (Tnpul. Oulput, Bit Memory. Timers, Counle~) po Program structure po Unused symbol. I> AddresSd without symbols
po

To generale n;f<;11;nce dam. sclect the Block< object a nd Ihc menu command OPTIONS -+ REfERDlCE DATA ~ DISPLAY. The representa lion of the ref=~"" data can be chlllliCd .pe,itieally for each worl:: window with VlFW --> FILTER; you can save the scningo for IllIer editing by selecting WINOOW --> SA VE ARRANGIOME"". You can di.play and view several h,ti at the same time (Figure 2.12).
With OPTIONS _ CUSTOMIZE ill Ihe pmj,'J1Im editor. specify on the Blo,,".s" tab whethc-r or nOl the referen<:e data are 10 be updaled when

Eon _ Go To -> LOCl<TION wilh the position marked or. double click On the position starts
the pTOifam editor and displays the addmr5 in the programmed enVlTOnment.

The tross-reference list shows the addresses


you s~le<:ted with VIEW _l'n,TER (for inSlance bit memory). STEP 7 thtu u.es the filter saved 8. "Standard" e~ny time it opens the cross.reference hSI.

-. -. -

"

2 .5 Creating ' he S7 Program prob'lam. The list shows ilic ~ymbol, th e address. the <lata type. an d th e COnm1~"IIt [rom the s y"Il1bol table . Advantage: were the addre sses in the list inadver1ently fOIgonen when the p rogra m was being wriuen? Or are they perhaps superfluo us . and not real ly necded? Add,'esse s "I tho u l sy mbol Thi, list shows all the addresses u sed in the program to which no symbols were allo<: ated. The list iliows these a ddresses and how ollen they were us~d. Advantag e: were addresses u sed inadverte ntly (by a~cidcnt. or ~c a u,e of a typin g "rror)? 2.5 .7 Langua ;;: .. St'tti ng

Advantage." the cross re ferences show you whether thc rcf<:renccd addre.ses were also s ~anncd or re,et. They also show you in which h locks addresses are used (possibly more than o nce). A s.]gnmen n T he I1Q/ M reference list shows which b ilS in address arC", I, Q and M arC assigned in the program . One byte, hroken down into bits. appears on e ach linc. Also shown is whether access is by byte. word. or doublcword . Th<: TI C reference list shows the timers and counter. "sed in the program . Ten timers or counters are d ispJaye<:l on a line. Advantage: the Ii" ,hows you whether certain a ddress areas were (improperly) assigned or where there aTe still addresses ava ilable. Program
. tru ct ur~

STEP 7 otTers sev.,.-a\ mcthod, of working with dilTerentlanguages:


<> The langua ge or the opC1"aling syslem (character set) <> The STEP 7 language <> The language for comments and di'play rex t

T he progr"'n stn,cnlre shows the call hierarchy of the b lo<:ks in " user program. You can determ ine Ihe >t3rt object for the cal1 hierarchy from "selection list . 'Vith VU;w ---> FIT.TfR you have a choice belWeenlWo dilt'e rent views in the prog ram structure ; The Call sfn,etur-e ,hows all nesting levels of the b lock calls. You control the display ofnes!ing le,-"I, w ith the "+.. and "- '. boxes. T he requiremenls fo, Icmpomry loca l data are shown for one block or for the emire path up 10 the assoc iated b lock. W ilh the block selected. change m ing E DIT -) 00 TO -. Loc~no:-: to the block c all, or open the b lock using EDIT -) Go TO ---> BLOCK ADDRESS. The display 'IS Dependency 5tn,erllre shows two ca ll levels. The blo<:k:; are shown (indented) in which the block poit,on on the left is called. Advantage: Which blocks '"ere used~ \\'e re all p rogramme d blo<:ks c alled"! What are the blocks ' temporary Io<:al dma requirements? 1;; the specified local data rcquir~mcnt per priority d ass (pcr organizat ion h Inc k) .ufflcicnt?
Unu. ~d S ~'mbol s

The se"ings ofrhe different languagcs are indep~ndent o f each other. l .a ngu a ge ' cl1lng s In rhc nperat in;;: .y.t em You use tile Windows ~ontrol pane l to se lect thc characler set with wh ich you want to w ork under \"indow,. You can find thc ehamct"r selS le'ted with the mult i- language ve rsion ( M UI "ersion) and the restriction. wbcn operatin g with S TF I' 7 in the currt:nt Readme tile or in ilie STEP 7 11elp under Seni"g up ami cditing th e project"".
Proj~ct

lan gua;;:e

This li,t shows all addresses which have symbol table allocations but wc.,-e not used in the

The project language is the lan g ll3ge that is set in the W indows eontro l panel w he n the projecl is created. T he SIMATIC Manag er ind icates the language in which the selected project or the sclected Iibrllry has been erealcd in E D IT ---> O n JECT PROpeRTIES. "Not yer de tl ned" means you can me the project or the library lan guage- neu trally, e .g. in multiproj e~ts. These are alw ay s language-neutral. In language- neutral proj eclS or libraries . only characters of the ASCIJ chara cter set can ~ used (2Ahc, to 7F hox )' You can

2 S'I'EP 7 Programming Software mation on the e~ported types of t""t, and any ~rrors whkh ba ve occufT~d , Open the export tjle(.) w ith th e FILE ...,. OPFN dialog box in Mi~mwfl Ex cel (not by doo.h\eclicking) , The e~p<Jned tc~ts arc di<played in the flr.ll ~Ollllllll and yo\: can translate the te~l' in the second co lum", You ~an t<:tch tbe trans lated texts baek '" lhe project with Ol'lIONS ...,. MANA{",E MULTlLlNGliAL TEXTS ...,. TMJ'OKT. A log file provides information about the imponed te~t. and any error; that may have occurred. Please note that the name of the import fik m o" not b~ ehanged ' ince there is a direct relation between ,hi, and the text type. conto ined in the fi!~.

find additional informalion in th~ STEP 7 Kelp lIn der "Settin g LIp and editing the project".
STf~P

7 langu 3\:c

Thc S<.'Ssion language of tht: SlMATlC M"nag~r that \kfines. for e~,~np l c, til, m~IllJ "ames "",I the error mes""gc,;, is called the STEP 7 language. Y01..l ""t this language in the SIJ\1ATIC Man;'g~' on the "Langu ag~" !:ob with OI'TIO~S ...,. C usTOMJ/.I-~ 'The languages installed w ith STEP 7 are offered for ",Ie",tion llndt.-r "Nationall"nguag<:" . On this mb you also set the programming Illllemoolcs, that is, the language in whi~h STI' 7 uses th~ op<.="d, and operation<. e.g,"to. I" (II!'.') input for Engliili), or " U E"' (for German). j\-'I ultllingual Commcnn a nd Di.play Texn Comments and display texts can be multilingual. You hav~ entered the lext> in tbe original laJlb",age, rueh as English, and you "'an ( (0 generate a German ve"ion of your program. To do so , ~xpon tb~ desired texts or text type,. Thc e~p<Jrt I1le" a .c.v tile that you can edh ",ilh Microsoft E~ecl, for example. You can elller the tran,lation for each texl. You ;mpon \h~ fin_ ished tran,lation table back into your proj ect , Now you can ,w itch belween the language" Yo" can do this with several1anguages Wilh OPTtONS ----> LAl':GUAGE FOR DISPLAY DJ::_ VTr:E~ in the SThtAI1C Manager, you ,elect the languagc" available i~ your projc~1.. and Y"'" ""t the standard language tor the di.play tenn inal, .

Sdecling and ddel;Jlg a language


You Can change to all ; mj)Ort~d languages in lhe SIMAnC Manager w ith OPTlOKS ----> MANAC[ MULTlLlNCUAL TVx rs ...,. CHA~'G LANGUAGI': . The language ohange is ~xeeuted for the objec," (blocks, ,ymbol tab le) tor which the relevant text< have b.-en imported . Thi. information i, contained in the log file , Y"u Can make funher .etlings. e.g. tbe --taking over" of multi lin gua l comments when copying a b lock, Il.,ing OV t'IONS ...,. MAI"AGE MULTiLINGUAL TExTS"'" SJOTTINGS I'OR CO),L"-ti:Nl M"NAGJ:"""'T. You can delete the illlp<Jned language again with O PTTONS ----> -"1ANAGl' MLIl.m.lNGUAl TEXIS --,> DELETE LANGUAGI'. 'fable 2.2
Tnt type, uf tho rran,1ated tens (se lection)

Exporting mId impmti,,!; /exls


Select the obj c~t in the STMATIC Managercon mining the comment. you wamto translate, c .g. the symbol wblc, the blvd; ~ontainer, . e ,eml blocb or a 8ing1c block. S~IC<:t OPTIONS ----> MANAGE M{;LTllt~GU AL TEXTS ----> EXPORT. In the dialog window ,hI (hcn appears, emer th~ storage location oflhe ~xport fik and thc "'rg~t bngunge, Sclect the text types that you want to translate (Table 2 ,2) , A separa te file is generated for every t..xt type, e.g. th~ fiJc SymbolCommcnl.CSv for the com ment. from the symbol table. E~i"t in g e~port tiles can be expand~(L A log file provide s infor-

titl

itt

2.6 Online Mode

2.6

O nline Mnde

If "" prQj~ct has be~n . et up , you establish Ihe

You creme the hardware confill"notion and the "ser prugr6m Olllhe proarammina device. generally IVf"."..,d to as the engineering system (ES). rhe S7 program is stored offiine on the hard disk here. also in compiled fOOTI. To transfer the progrdUl to the CPU. yo" must connect tbe prognunminll devicc '0 thc CPU. You establish an onlinc' connection. You cM uSe this eotUlection to det~nnjnc the operaling ItHtC of tbe CPU and the ~ssiiln\X1 modules . t.e., you can CHrty out diagnostics func!iolts .

~onneclion to the CPU with PLC -+ DISPLAY AC'C[SSJDLE NODES. This seree!!s a project

window with the structure Ac{)t!fslble Node.. _ \.ladule (MPI=nf" _ Online User Program (Sloehr. When you sde<:t the /If,xl"le objecl. you may utili,..c the online functions, ~uc b "" dunging the optr,uional ~Iarus and checking the m<XIulc Status. Selecting the BIQCh object dtsplays tbe blocks in the CPU's "set" mem"ry. You Can then edit (modify. delete. insert) individual blO<.:ks. You can fetch back the ~y.(cm da t~ from a con nected CPU for the purpo~c of, say. cominuing 10 WoR: On th~ basis of the e~i~ting configu"" lion. without having the relcv"'" project in the proinunming device daUl !IllInaaernem 5)'8lCm. Cn:atc. new projeet in the SIMATIC :\1l1nager, .elCCl the projeet and then PLC -+ U I'LOAD S"rATlO __ TO Pc. After spe~ifying the desired CPt; in the dialog box Ihat Lhen appear><, the online system data are louded O!\lO the hard disk. lflhere i~ II CP1:_i nd~prnd~nl pTOKram in the project window. create lhe as.tociated online project window. l!several CI'lJI arc connected to the MPI ""d actessible, .' el""'t EDIT -+ OElJFCT PRoPJ:RTlES with the online S7 pr0gram IICleeted and ""t the number of the mountinll rack and the CPU's slol on the "Addre,"n Module mb. If you scle<;t the S7 Program in the online win dow .. U the online functions 1<> the cotmect<.-d CPU..,... ""allable lO you. Bloefu show. the bloch located in the CPU's u5Cfmemory_ lfthe blocks in the offiine pro8fllm agn.;c with lh" blocks in the online program you can edit the blocu in the user memury with 100 infonnation from the data manag~ment ~y5tem of the pro. i1rnmming devic e (symb<:>lie address, com menrs). \Vh",n you switch II CI'U-.SJjKn~d p rogram inlo online mode using VIEw -+ OSLlNl:, you Clm carry OuL program modifielllions just as you would in a CPU-independent program. In addilion. it it now "",""ible for you to e<mfigure th" SIMATIC station. Lhat io. 10 sel C PU parame_ ICI"lI and address and paramelerize modules.

2.6.1

C onn.,.,tinga FI.C

Thc eQnf>C"Ction between the progmmmiog doviee, MPI in!~.,.faee Il!Id Ihc CPU's MPI interface is the mechanical requtrement for an online connection. The conncc1ion is unique when B CPU is the only progu.mmahle module c()l!nt~d. !ftllere arc severa! CPUs in th~ M1'l subncl. each CPU mu,t be assigoed a unique nadc Ilumber (\1PI addreSll). You set the -"11'1 addlV~ when you initiHlizc Ihe CPU. Rcfore linkmg all the CPUs to One netwon:. connect the pru$1"&mming device 10 only one CPU 8 time .nd trnnsfer the Syslem f)Qlo object from Ihe oftline US<."T pmgram Blacks Or direct with Ihe Hardware Configuration e;litor using the menu command PLC -+ IX)w.'LOAl> . Thi. "ssigns a CP U its own special MP I addres s ("uaming) along with the other prop~rties.

The MI'l address of a C PU in tl:e MPI network can be chMged at any lime by mmsferri;g a new paramet~ dala record conlllit"l1nl! the no'w MPI add",,,,, to the C PU. Note carefully: the new MPI ~ddres s takes effect immediately. While the progranuning device adju.l. immediately tothe new address. you mu." adapt other arrliea(hm~. such as global d~ta communicalions. to the !!ew MPI addrc5S .
The MI'I parameters are retained in Ihe CPU eVen .ncr a memory rescl. The CPU can thus be 1OddreS5ed evcn al\cr a memory reset.
A programming devicc Can alway~ be opernted o nline on a CPU. even with a module-indcpcn"'~nt program and even thoullh nu project has been Set up.

2.6.2

I'rottctl 0l:

th~ (;.~r

P rogra m

f'1"tK~ elion

lenl 3: rfl"3dl .. rite protec tion

Wilt. aPl'ropriatc/y equipped CPUs. access to


the U1t\:r progrnm ean he protected with II pllh' word. Evcry<>nc in pooSCl'sion of the password has unresUicted access to the userpl'<J~:rnm. for tho ..... who do not know the pas,word, ~(". can defi ne J p ....ll~tion levels. You set th. ~rr>tec t;on level' with the "ProteClioo" l" b of the Hllrdwur~ COllfigllmti(}ll tool when pannnctCT_ ,,,,;nll: Ihe C PU, The acc eS!l ~r ivilege using the ~"".word applln "",,llhe S IMAT IC Manager has hem exite" or the password p'<>''''''ion cancdod again us,nj Pl e -+ At"('fS!> IlI{;HTS -+ CA."ICEL.
"rot~lion

1\"0 access to the """program, regardl""", orthe keylocl: .witch posi lion. Exception' reading <>f diagnostics bttifer and moniloring of va nab Ie. in tabl ... i.< pos>ible in every prolection level.
I'a~'word

p r ntettiun

If you ,elect protection [cH I 2 or 3 or protec_ t ion 1.".c1 2 with "RemovlIble with pas~w"rd", you will be prompted to defmc ~ pa ssword. The l"'s~word can be up 10 II characIC1"$ 10011". Tfyou try to access a u><:t: program thai is protled "~th a pas'<Word, ),ou will be prompled to enter the pass"ord. Befon; ~ct'Ssmg a pro1~"Ct"" CP U, you can ~t..o enter ,he pII~~word via PlC --jo Aross RlGlITS ..... Snup. F irst, sdt th .. relevant CPU or lhe S7 program. Tn Ihe "Rr)[~T P ~5'WOrd. diulog 0011, you can sel"<'f the o~tion -Use p,u~wnrd b defa"lt for nil pro""" ",, modules" to gCI Deee~~ to /III modu l.. ~ ~mlCClcd with the ~m~ password.
I '''s~word "eee,s authorizatioll n:m uins ;n fOTCe u~ti l the lasl S7 a~~l i"al;On ha~ been t.. nni_

le,'e l , : mode sd.,.,ror s .. itch

TIli' protection level i~ sel HI def~u!! (WJ!l::out "".sword). With CPt). with a keylock ~wil~h, prol~tion level 1 i. used tn set protection of th. usc, l"'lIlTK'" by the mode selector switch on die fro tH of the CPU. Tn the }{UKP and STOP "",itions, you have unrestrictcd acceSS to the uSCT program; in th e RUN position , only n:!ld lIecen via th~ programming device is possible. IJllhis po:lilion, you can also rernO\-c the keylock 6witell,." , h.at the mode c..., nO longer be ctlangl.'d via the ~wi'eb.

'Ulled.

Every'm<: in posses"on of Ihe password has lInreltricted 3ecc~s 10 the U$C1" proP"' in the CPl; "'!I...-dJes. of the protection le\"el ~ and ~gardlt'Ss of Ihe keylock pOlo;"""'
2.6 ..1 C P U inform a l ;"n

You can bypass prmection via the I:eylock switch RUN ~irion by selecting the OptiOn Iot cmovallic with Jl'I.~swonr. e.g. if the Cl'U, and with il the I:eylocl: switch, are nO! easIly """,",nible Of "'" located lit a di.tanee.
lflhe mode ~el ee'or ,wi,eh is d.:.igned as B toggl e sw ilCll, protection level 1 m ean5 &0 limiTati on in aetCi! to the user pn>gram. With th~ system function SFC 109 PROTECT, Ihe wri te prol~""lion (pn,tcetion level 2) Cion be switched on pnd off via the pmgr~m in protection level I (Sfi: Chapter 20.3 .8 "Chan;:in propm protl,dion'"). ProTection Icvd 2:
1\";t~ prol~tlloD

In online tnO<, Ihe CPU infomuuion listed below is availabl e to you. The menu command.. ~ re screened when you have ""I~...,t~"" a modu le (in on line mode and without a project) {" $7 prollrum (;n the online project window).
~

PLC -+ DlA(j"uSTIC/S~lTl!<.Q
--jo H..... RDWARE DlAo:.;orncs (Ott Chapter 2 .7 . 1 "l)iagnOlling the Hard_

WII!"C"')
--jo

MOOULr; INFo\t.\(A not.!

At thi~ prutection level, the user proiO'IT! ~1ltI o nly he read, reganlle of Ihe position of the kcy lo>ek swilch.

Gene<1l1 information (such as ~rsion), diag_ no"ic~ huffer, memory (CU"""I map of work mC"lllOry and load m emory, ""m pres~ion), cycle time (length of lhe last, longut, Bod shonesl program cycle). timing ,y~lem IJ)< 0pi!rtie s of the CPU clock. dock syn _ chronization, run-time mctcr), perfOnrulllCe

2.6 Onl ine Mode dala (available organi:~.n ion bJ(X;kli aDd sy.Icm blocks. sizes orlb" address arcu), communicat ivn (data lransfer rnt~ nnd CO mmnnical10n links). ,lack, in STOr stat ~ (B stack. I Slack, and L sTack) In the CIS(: ofa RAM load memory (integnlcd in the CPU, a. a memory card o r micro mcmo'Y card). you transfer a compl et e user program by "WilChlllltl: thc CPU to Ihe STOI' Slate, performing memory ..."ct and trnnsferrin\!lhe user prognorn. Tbe configuration dala are aJ.o U-dUBferred. If you only WaDI to cbange the eonfigur.llion dalill (CPU propc!1ies, the cOllfigured connlX'tion~, GD cOnuDunicaTions, module parameTers. and 50 on). you n~ed only load Ihc System Data obi ""t into the CPU (sclect thC objeCT and transfer it with menu command I'LC -+ DOWl>!I.OAV). The parameters for tho CPU go imo cireci immediately; The CPU lransfers Ihe parllmCTcrs for the remaining ,nodule. 10 those modules during "tartup. Plo:asc nOle thaT The enlire: L"Onfigurdtion i. loaded ooto the PLC witll the Sys/I'''' data object . If )'ou I.\l'O: PLC -+ DOWN r.oAD in an application. e.g. in global daTU communications. only (hc data ediTed Ily the Hpp l icaTion an: transfcm:d. NOIe: ~r:lect PLC --;. SAvt: TO MIS..I,tQRY CAKl) to 10Hd lhe compressed arohive Ii Ir: (s.ee Chapt.c1 2.2.2 "Managing, R.eorxanizi nll and AIl::lliving-). The project in Tbe archive file cannot be ediled direct either "ith the programming d evice or "om thr: CPU.
2. 6 .~

-+ OrEIl.ATI:'G MODE
[), ~play of the eUlTl:D1 operallng mode (foc instance RUt>. o C STOP). mooific;aTion of the oP='ting mode

-+ CLf.ARlRES ET
Rcs.clting oflhe CPU in STOP mode

-+

S ~r

Tn'lE Of DAY

Setting of the internal CPU doc k and . 1n Ihe enhanced dialolt - me diffetcnce from a lime ZOne
~

PLC -+ CPU MF_'i.~AC.F _~ Rrporllng of asynchronous system crTOT!i and or user-defined mCSSl.lgel GenCf9ted in the program will SFC '2 WR t.:S/I.tSG, SFC 18 AJ.ARM s. src 17 ALAFU.I_SQ, SFC 108 ALARM D and SFC 107 ALARM DQ.
PLC -+ iJlSI'l.AY FOR.CF VAL1ffi~, PLC MO:-fTOR./Momry VAR.IABlES

:>

-+

(see Chaplers 2.7.3 "Monitoring aDd ~odi fyinK Variable." and 2.7.4 ~Fordna Vari_ a ble$")

2.6.4

Lnadlng Ihe (JStr Pro!:rilm Into the C P U

Bl ock Han dlin jt

When you U"lIn,fer your user progrnm (compiled blocks IUld configuralion dUla) to the CPU. il is loaded into the CPU'S load 111<':1110ry. r hy"i<,:alLy, load memory Can be I memory inTeinlled in the CPU. a memory card. or a micro memory card (set' Cbapler 1.1.6 "CPU M ~mo'Y
Area~ ).

1"rllMfcrrhl K bl".,k.
In the eil."" of a R.AJ>.t IODd memory. yol.\ can HI$O modIfY. delete o r reload indi vidual bL ocks in adduio" to =ferring Ihe entire program online.
You transfer individual blocks to the CPU b y selectin\! them in the omine window and selecting PLC -+ Do"'NJ.OA" With Ihc offline and online windows C>pCned al the ~ame lime. you can also drag the block! wilh Ihe mouse from one window and drop them in tile otb~"1".

Wilh a micro memory card or 8 flaSh EPROM mcmo'Y cord you can wrile die card ill th .. programm in g device and usc il as d3ta m~dium . You plug the can! into the CPI) in the off-circuit STale: 00 power up follow ina memory re'<'I. the rcle\"8n l dala of the card a~ transferred to the work mcn>O'Y of{b~ CPt.:. With Ipproprialely equ,pped CPUs. you can also OVCTWnle a fln.>h EPRO\1 memory carn or a miero memory card if il il plugged inlo!.he C PU. but only wiTh The entire program.

Special ~an:: is needed whcn transferring ind i vidulll bloch during opr:ralion. I f blocks thai Bre: OOt avaiLable in Thr: C PU memory arc called w;lhin a block.. you mUSI firsl load the "I",,'crle,"er' blocu. This also applies ror data bl(X;ks whose au dr\;sscs Hrc used in the loaded block".

2 STEP 1 Prujlrlln,m;ng Suftwate: You load Ihe highesl le,er block last. Then. prov;d~-d it is ",,1100. it will be ex ecuted immediately in Ihe ne"{ program cyele. Modlfyln!,:: or delellng blocks online Ynu can edit bloch incrementally wilh STL in the online u~er program (on the CPU) in ~xa cI Jy the 8ante way as in the offline mer proW.. ,n. With a pro:,:rammint: dc,icc connected online to the CPU. you can read. modify or d~lele blocks in Ihe load memory. If the RAM eomp<mcnl of the load m~mO\)' is I~e Cfl()u~ II) acoommodate the C<lmplCie IW'I" program and also the modified blocks. you can edit bloch ""ithoUllimilation. Iflhe user program i. sa,ed on II nll.5b. EPROM memory ""rd, you Can cdil the blocks asll)na as the RAM eom('>Onem of the load memory i~ !Drge enough 10 accommodate the modiliod blod.s. Dwino; rumime, the modified blocks in the RAM nrc ~a]jd. Ih ose in the FEPROM IS invalid. rlea.e nOlO Ihat you must I""d Ihe original blook.s again from the FEPROM into Ihe work mcmory following an overa!1 reset 0.'''.on-burrered ~wilchin8 on. If you U'"' II micro memory card such ... C.Il. wi lh the compact CPUs. all bl""ks in the load memory are oon_volatile. You can modify indiv idwd blocl<s online. nnd tbese hlock:l Mall! tbtti r ehl<ngClr e,cn fo llo"<IDg an 0........... 11 re~ct or non-buffered $witehing on. Dckted block. are then no longer e xi"ent. In Lm.,rmuental prollnlIIllIling mod~, )lvu ~Hn mooify bloch< independent of one another in th~ oillinc data management on the programming devioe and in tbe online data manugement on \~e CPU. However, [fonline MId omin~ uHla man-asconent divcrge, it may n:sol! in t~e ed,tM being unablc to di~play the additional informatio n of the omine database: !bese dina can thom be lusl (~ymboJje idenlifiers.ju.:np labcl~, ~om tn~'ltS. uwr dllllt lypcti). Blocks thaI have been modified online are I>e.<t stored oftline o n the hard disk to avoid dma iIl<.'Oll~i>lell<.'y (c.t:. a time ,tamp conflict when the i"teTraee of the called block is later than the program in the calling block).

The following ,till applies CVo:tl if you "or:k online: with FlLE ---+ SAVE you $ave the eUf'"l"Cnt block in the offline uscrprogrnm in the PO data manaw:ement; with PLC _ DOW/,>WAV yOlJ v,..rite the block back into the user memory ROO the CPU. Comp .... soing
W~om you load a new or modified block into the CPU. the cru plac~ the block in load memory and IransfcnI the relevanl data to worl< memory. If tbere is already a block with the same number, this "old b lock" is dedared invalid (following a prompt for confirmation) and the new block "added on at the end' in memory. Even a deleted block i8 only" declared invalid. not actually ~mo"ed from memory-

This result, in &Ilf>" in user mcmO!")' whi ch increasinw:ly r.-duee the amount of memory still availahle. Th~se gap' Can be filled on ly by the CompreH function. When you eompre$s in RUN mode. the blo<;b currently heini c"ecUled are not relocated; only in STOP mode can you truly achk~c compres.'ion withoul g"p". The eurrctJt memory allocation ~an be di s_ plnyed in percenl with the menu eommand PLC
_ DIAG:<osnclS[;1"1l1'oG ..... MOPULIl Jl'."1'OR-

\.tATIO". On the -Memory \.lib. The dialog 00" "",eh then appean also ha.ii a bunon for pre\"enti~e

eompressiOD.

You can initiate ",-'ent_driven compre~ing p<.'r pmgram wilh th~ c a ll SFC 25 COMl'RESS.
0018

b locks olTIineiulIllnc

I)urino:: programming. you ~~sign tile dam addrc,"cs in a data b lock wilh I' default value and an initial ~alue (see a lso Chapter 3.4 .. f'ro.grnmming Data Blocks'). If a datM block is loaded into the CPU. the imtial valUe!! ftre traM_ r=cd to load memory and subsequentlY to work memory, ... here they become ....'ua1 values. Every value change made to a <!alii address p<.:r program corrcspond~ 10 a change to the aClual ,a.lue in the work memO\)' (Figure 2.13). You ean upload thc actual val ues gl'nCrlltCd in lhe ... ork memory from a programmed (loaded) data bluck into the offlinc d" ln management by opening thc dnta block On 1in~ ""d transferring it

2.6 Online Mode

If a spoci.1 .",n ".lue


.. "'" p"'f-rammod. !he del...... " is usN

""we

IMiaI value
When dnwnk"dWjj; '"
mrnl ... 1<>&4
lh~

rpu.

lhe .an v.luo f\, ' ","" f< "",~ from !he .>11]'''0 data manall"-

""""Dry.

!l_d . .
~
rl

mory

If ''''' do..

bluc~ _ ...-.r h...., UNlJ"Kl:.D zrrrib"",. !he ...... vahle is .....~ '"

WRIT .DDL -~ WW;O',".C~;;;;'m'o;;;;.;------- / ' i1 (

I '1 ' ' ' ; I

Who" tra"'f=;~8 til<

""I".e bIo<t ,,., rho omi ....


dar.~,

'.

"aj"" ;.

~"'...,. Tho >tart , . ,,,,, '"

""""

,.".,ao:rUaJ

rbo: ""'"

Initial vaIu ..

the ~ m<:m<><)' i, 1101' inn' .... <'Od by !lr..

:"~2l"~~..:'~~
... ilEAl) DRr _ SIT 5<

~[t..;.. .... ,

Adua/ ~ a lu"

'1"110: O\UI , ~tu. bt<;"",,,. 'he ""uol ,' atll~ in rho: work mo"w'~. The actual ,.~""
;"11>< ""I ... madiO..l by <hoc (1Jtt _",n.

..

in the

pro~m editor 10 the oftline data management using FILE ---} SAVE. TIK: nameS of lhe vari~bles and !.he data tyPCs sa~ed in the offline dala manaijcment are 'hen rers ined. If yo" upload Ibe onl ine dma b lock in the SIMATI C Manager n.ing I' LC ---} UPI .OAD TO PO or by dragging Ihe d~la block from Ihe online win. dow to the omine ""i ndow in the offline dalD onanagemem. 'he descriptiotl of Ihc addresoes. such as c.g. the Mme of the variables or the dala Iypc, i. 1000t .

lfyou upload a data block from the CPU back iOI<> the omine data management . the actual ~alucs pre".;nl in the work me mory are imported mta tbe omine data management as inil ial ~a lues . This does not change Ihe initial values in the load m~mory. Following an ovcra ll r~sel or nUD-buff,,-rcd switching on, and " ' hen nsinll a nuh EP ROM memory card or a m icro memory card, the (old) initial valu~s PTCScnl in the load memory are import~..J ;",0 Ihe work mCDlOry as (new) actual valuc~.

If you wish to import the Bernal ~"lue.~ into the load memory when nsmg a RAM load memOf'Y or a mi~'TO rmmory eard. l<>ad lhe data b lock from the CPU into the prolll1'mminll d cvice alld then haek again into thc CPU. CPUs wilh mi~ro mem ory <.:fiTd provi de the syst~'1n functiun ~FC 84 WRIT_ DilL with which you clln directly write actual w lues in\{) the load memory. Wilh correspondingly d~;gned c ruS, you can InInsfer the complele eonlems <>f t~ work memory into the ROM comp<:>nenl of Ihe load memory using PLC ~ COpy RAM TO ROM.
A wna b lock gel]enltcd with tbe property

Unlinked is Dot IJaIIllfcrTed 10 "..or!< memory; il remains in load memory. A data hlock wit h Ih is property can only be read with SFC 20 BL KMaYor - with corrCSp<)nd in8l y des igned CPUs-with SFC 83 READ_OB L.
III incrementa] programming mode, you ean create dala block'l direClly;n the work ~mory of the CPU. It is recommerldable to a lso ..,ve

2 STEP 7 Programm inl! S()i'tv"are

Ihe.e blocks been ~rcalcd.

oftlin~

immediately Ihey have

With the system f\ln~li()ns SFC 22 CR.AT_ DB. SI'C 85 CREA DB and SFC 82 CRT'A_ DB L you can genemtc dara b locks during runtime where Ihe d escriplion of lhe addre",~ s, 5uch a.s the "am~ of the v ariah le and Ihe type of da la, arc missing. When re ading with the pm_ gramming device , a I:IYTE field with" name and in dex assigned by the program editor is th ercfore d i,playe d.Ifyou tr~nsfer such a dam block to Ihe om ine data management, this duelaral io n is imponcd . If the data b lock has Ihe property Un/inked, th ~ ini ti~l valu~8 from Ihe lo~d memo ry are imponed into th~ oftline data manag~ment as neW ,m lial valu~s . otherwis e th~ aelual "alllC' from the work m <:ruory. Wh~"I1 tran sferring to the offiine daw managemenL Ih e e hed,,;um of thc (offiine) pmgram is ch anged ,

thc h elp of Ihe function "'Diagnose Hardware ". Yon co nnec t the pml.""mming device t() th~ MPI bu s and stan the SIMATlC :\1anagcr. !fthc project as socia led w ith the plan! configu_ ra tion i s a vailable in the progra.tmniT1S device databa_e. open th c online project w in dow with , V IEW ..... O'NLrnT. Olh~rwisc , ,e lect P LC ---> D ISPL .... y A CCfSSlllLE NODES in the SLvlAT IC M a nager, and s ~k~\ the CPU . Now you can gel a q ui~k overview of the fauity modu les w ith PLC --> DIAGNOST Ic/SETTI NG ..... HAlW WARE DIAGNOSTICS (default In the SIMATIC Manager lInrl .,,- O J'nONS ----> ClJsTO)'flZE in Ih~ tab "Vie,,~'). If the quick overview i. dc.elcc led, you are provided with the detailed d iagnostics in fonnation of all nl{>d"I~s , l fyuu ar~ in the lIard"'arc Configu ration tool , 8e1ect Ihe onl i n ~ vicw u,ing VlLW -lo ON LL E, , You ~'lll now d isplay the existing di agno"ties information for the sele cted module ""ing PLC -lo MODIiLr. Jl','FOR.'I,fATlO,,.

2_7

Testing th e P rogram

After e "lablishing a conneclion t() a CI'U and loading the user progr"m, you can lest (debug) the program as a whole or in pan, such as ind ividu al b loch _ You initialize the varia bles w ith <i g nals an d v alucs, c.g. with thc h elp of s imula tor module, and evaluate Ihe infoffilat ion rel 11med b y your program. If Ihe CPU goes 10 the STOP state a, a r ~ su l l of an error. you can get sUPP<lf"\ in finding the cau,e of th~ error from the CP U information mnoug othcr th ings_ Extcnshe p rograms are debugged in sc~t io=. ff, for e xample, you only want to debug one h lock, load this block into the CPU and call it in OB I. t fOH 1 is organized is in s ueh a w ay Ihat the program can b e debugged sec tion hy 8cClion "'hOln beginning to e nd". y ou can select the bl ock s or program section;; for debugginl! by u sing ju m p fu nctions to s kip those calls or progI"" lII ,~~ tions thaI arc not to bc deb ugged , d W ith the S7 PLCSL\1 optiona l softwa re . yon can simulate a CPU on the p ro ..:nmuning device a nd so debug your program w ithout ad d itional hardw"rc_ 2. 7.1 D iagn os ing
t h~

2. 7_2

D ctcnninlnR t h e Ca u se of a STOP

If the CPU gCK""S 10 STO P because of an CfTor, th e liThI m ~a.sure to tak e in order In d etermine the re~son for the STOP is to ou tput the d iag nosti~s buffer. TIle CPU enters all m essages in Ihe di agnostic buITer, including the rea s on for a STO P and the e rrol";<; w hich led to iI, To OUlpUl the d iagnostic buffer, switch th e PO to onlin ~, select an S7 program, and choo8e the "D ia gnostics BulT~r'- tab with the menu commami PLC --> D IAGNOSnc/S FTTDIG ..... MODULE INFORMATION. The last event (Ihe one with the number I) is the Cause of the STOP. for instanc e '"STOP because programming efror OB not lo ad~d - . n , e error which led to the STOP is described in the pre ce d ing me"~ge , for c .... amplc "FC not Inaded" , By ~licki " g on the me~sagc n umber, you can screen an add it iona l com m e n! in Ihe ne.~ t lower display field . lftbe message re lates to a programming error in a block, yo" Can opcn and edit that b lock with th e "Open Bl ock" button.
If the cause

H a rdwa "e

In the event of a r""It , yo" ean fetch the diagnostics informalinn nf th c fanlty modu les with

STOP is. for exa m ple. ~ p rogramming eITor. you Can asecna in the surround ing ,: ,n:umst ance s with the " Stacks" lab_ \\'hen yo u open "Slach"". you will ,ee the B sl a~ k ( b lock stack) , w hiCh s hows you Ihe call

ofth~

2.7 TOI-tinathePrognm path ()f ..U n()n_t~nnillated blocks up to the block contain in g t~e interrupt point. U.e th,, '] ~ I ack' button to 8creClI the interrupt stack, which ~how. you the COntentS of the CPU regist~T!l (accumulators. address r.:ais:er. data block "'ii'ler, stalUs word) at thc in'"Tnlpt point at the inst.ant the error occurred. Tbc L s\.IIck (local data stack) shows block's temporary local data. which YOII sclC<.'t in the 11 slack by clic king with the molls.:. Plellse note tha\ YOll can only modify d.!ta "ddre es iI tbe wrile protection for the data hlock i~ switched off, i. e. the block l' rop"ny Dfl Is ""t"II~_"ml~ckd in Ihe AS ill n01 nClivatcJ.
Opcl"\I.nds in data hlod..:s with Ihe block propert y Unlmked cannot be monitored since the." data blocks are located in the load memory on the micro memory card. A one-off updale takes plan who:n lh" data block is opcIled online.

me

Caution. Y"u mus'


s'al~.1

etW'", '/lUi no dongerou.. Can ",sullfrom mmlifjj/lk mrl"b/e.. !

2.7.3
gr.tm~

,\lonllorinl: and

/ll o d lf~ ln l:

VarIab le.

Cru tltl]:t a va rl a hle rabk For monitoriog and modifyinll variable.., you mu~t C~a!e a VAT variable table containing the unables and the as.<ocll'llCd data fOflT1alS. You can gmtra!e up 10 2SS variable u.bl~. (VAT 1 10 VAT 2SS) and ...,sign them names. Toc m.ax imum !ize of a ,ariable table is 1024 lines wilh up to 2~S characters (Figure 2.14).

One exceUc[}\ resource fordebugging user prc>i, the monitoring and modif)"ing ofvari_ Bble~ with VAT ~"ariable table". Sigm" Slates or values of "ariabl~ of dementllI)" data types can be displayed. !fyou have aeees. to the uscrprc>pm. you can also modify variables, i.c. cllilnge the .igllal state or usign new values .

FI Ku r" l.U Variable Tahl. Eumpl"

You can g~ncnll" a VAT oftline by $"le~linl:: Ihe US/,,-r p"'lP""m Hh..ks ...,<1 Ihen l.>'SCRT ..... S7 BLOCK ..... VI\IUNlU! TtillLL. and you cltn ,en~-r~IC Iln unn..mcd VAT online by selecl ing S' Program and 5<'1ec1illg PLC ..... MO~tTOpJ M oolI'Y VI\!UI\IlLeS.
YO LI Can ~ t">ee i fy the va riahl"" with e ith er nbsoIm e or symbolic addresse s and cl,,><>se tbe dUTU type (di~play lonnal) wilh which a varigbl~ is 10 be disp lltyed and mod ifi ed (wilh ViI::" ..... Sr:L[CT DlSnAY FORMAT or by clicking the ri,hl muu~ bUlion dircclly on the Disp lay fl'rmat"). Usc COmnlenl lines 10 b";\,C specIfic sce,ion~ l'f the table _ header. You may also stipula'e which columns are to be displayed.. You can c hange variable ordi~pby rommt or add or ddele line~ al any tilllC. You ~\'e Ihe variable table in Ihe HIOl"b object con"'iner wilh TAB!..!; ..... SI\V.
E~tllbU5 hl nlt

\ Ion;turi nx ,a rt. h le... SelC<."t fhe :\Ionilor funetioD wilh Ihe menu con,mand V-'lUAlIUl ..... M OKITOI(. The vari_ abl .... in the VAT"", updated in accordancc wilb the specified triS8C1" condition.. Pcnnanenl mor.ilofill g a llows you to follow change . in Ihe values on the """,cn. The v ..1ue. lire disp layed in Ihe daTa fon n at which YOLl .et in the 'D i'play formal" column. The ESC key temlinales n p~r ",~nent mo.::lllor fWlctinn.
VAlUABLE ... ACTIV ... re M OD tr:v Vi\LU':S the monitor values on",c only and immediutely w;lhout regard '0 'he specified trigger ~"OIldition8.
update~

) Iod if)ina; , .. rlab l...


Use VAIUABL(' ''' MODifY \0 ,ransfcrthc ~pcc ir.~d "aluc~ 10 the CPU ,kpendent on the trigg~r conditions . Enl~"T v alues only in Ihe Ih,e. eonI" inin, the variab les you want In ,,.,od if'y. You can c ~pand th e commentary for a ,-a1u, .... ith 'Ir or w id , V>UUAlII.Il ..... MOllifY VAI.UIO AS COM-'lL"'; th~,c values arc nOl laiL"TI iuto accounl for modificat ion. YOII must define Ihe \"alu~s in the da la fOlTlllll which you sci in ,he Display rurmat" column. Only Ihe value5 visible on 'taning ,ilc modifY fU'lOtion BTl: modified. The t:SC key t~rrninate~ a permanent mod_ If)' function.
VAaIABLI: ..... Al.11V... MODtFY VI\LL~ ttnn.sfen Ihe modifY values <lnly on<'e and IIIIIDCdiatcly. withom ~\,;ard to thc ~pcdfied trigger condi ,;uru;.

a u oulin e eon n ectiun

To operate a va ri able table th'" has been ~rcatcd otUine, switch ilouliue wilh PLC...., CONl<o1::CT To ........ online. Yuu must switch each individ_ WI.! VAT o n linc and you can clear down Ihe coonection "gain with PLC --} DlsaJ'>."NF.CI.

,l:.

In Ihe variable table .elect V... IUAlILE ..... TlI.Klou to " tthe Trigg:~r point and the tri;:;:cr CODd1tiQn~ $Cpamlciy for mon itoring and modify_ in g. The trigger point is the poiot "t which the CP U rends vu lLles from th e system memory or wri lC$ values II) Inc system memory. You 'P""'if)' w h ethcr read ing and writing is to lake plnce ODCC or pt:riodically. If monitoring and modifying hav~ tbe 5IIme triggcr Condit;01l~, monitoring is carried OUI bc r(l1"C modifying. If you selecl the uigser f"l'Omt "Sta" o f cycle' for modifYing, Ihe variables are modified afl~r updaling of the procCi. inPUt image itOO heron: eallin!,:: O F! I. If you selccII"e trigger point "End of cycle for In<>D..itoring. the ~lal US vMill"" MTC displayed after lerminalion of 013 I a nd before OUlPUI of 'he proces~ OUtllUI

2 .7.4

Forci ng VwrlllbJ u

Wilh appropriately e<juippt:d crus. you can specify tixed value. for certain variable . 1bc uscr prol7"'ll can no lon,er change the,,", value. ("[ordng). Forcing is pe"n;~s;ble in any CP U openlling 'lat~ and i~ exenned imnledi .. lely.

Call1ton: yt1U must eTUurt! Ihul no dang~'TOu" ..fOft:.S can result from fOlrmg l"Oriuhl.,.,,!
The starting point fur forcing i< a "ariJ.bJc table (VAT). Create II VAT, cDtcr the addfa<c~ (0 be forc~d and establish II. conne~liun 10 the CPU. You can open a window containing the fOl\:" ,'ailles by sel ~cting VAltJ..'\DL[ ..... DlsPI .... y
FOR.ce V ... L1WS.

Lm:,;:c .

2.7 Tesrillll the Pl'Oj:Jtw If there are aLre-.ody force "alu~s active in the CPU. these "'"" indkated in the force window in bold type. You can nOw transfer some or aU ad dTC5!<es from the variable table to th" for.::e window or enter new add",,,ses. You foa'"C 'he e()nten1~ of a toree wind ow ,n II VAT with TABLE -+ SAVIi AS . The followina address area. ca n he provided with II fOTCe value :
t>

Fcm:ioll is also deleled by memory n:$et Or by a P""'CT failure if the CPU is not battery-backed. When forcing is tenninated. the lIdd rdlsc. retllin the forcc vlIlues until o,"crwritten by ~itbcr the user program Of the ~y~tem program .
Forcing;' dYcdivc only on 110 lIssigncd to a CPU. If. following TCstan. forced peri ph... ral inp"ts and outputs a re no longer "SlJ igned (c.g. a~ a resu lt of r~pa mmetcri:Ging). eh ... relevant peripheral inputs and outputs an.: no lODger for.::ed. E rro r h andling Tfth... aeCCS5 width when reading is greae~"T than Ille force width (c.g. forced byte in a wOt"d), the unforced component of the address value ill read as usual. If a synchroni~al1oo error ""'CUIS here (pc,",c"" <.>T arca lcogth CITOJ") tt.c "'error substitllle valuc" specified by th~ user progr..m o r by th~ CPU is read or the CPU goe!l CO STOP. rf, when writing. the access wideh is gre"tcr Ihan Ihe force width (c.g . forced byte in a word). the =forced comp'".,e,,! of tlte udd rcss vuhl~ is "'ritten to as u<un1. An ~""mlred w rite acc~ss leave. the toreed componem of the address urrchanged. i.e. ~he wrice prutcction is DOl reVOked by ,lte ~ynchmni:allion crror. Loading forced pcripheml inpul.>l yields 11K force value. Ifthe acc::ess width D(:TC-e!I w ith ehe forc::e width. input mooulcs that have fniled u r hD'... not (yet) been plugged in can be ""rqllll(;ed" by .. fOTCe value.
T hc inpor I in <be pr.....,,,,,,, imag.: belo"ging ro,. fOr<:~d peripheral input PI is not forced; it i~ not preas~i l>Dcd and can sti ll he overwTitl~n. \Vhen updating lhe process 'mnge. the i'l["Iul receives !.hc for.::~ value of the peripheral innut.

Inputll (preens image) [S7-300 ami S7-4001 OutputS Q (proces5 image) [S7300 nnd S7-400] ,''''';phernl inputs PI [57-400] Peripheral outputs PQ [S7-400) Memory hi t ~ M )S7-400]

t>

t>

t>

:>

You stan Ihe for~c job with VARlABU! -+ FOR.CIi. The CPU accepts the force valL.lC' and p"'mut~ no mo,e changes to the lorc<:d

addrcs!<eS.
While the foree function u. aclive, the foUo,," ina """liel:
t>

All read acce.~ to a forced addre,,~ via the user T'rogram (e.g. load) and via the systcm T'rogrwn ("11. vpdatmg of the prace". image) always yield the force value.

'" On tIrcS7-400, alJ ...rit"It(X'"";;~ 10 II ~ IKIdres5 viu the US~"T progmm (c.g . Iransfer) a nd via thc syst~'" program (c.g. via SrCI) re ,uain w ithout effec t O n the S7300. the uscr program Cnn ovelWrite the force val_ UC$. Forcing on eh~ S7-300 corresponds co cydic modifying: aftcr the process input image ha~ been updated, th ... CPU o,..,rwrites the inpuUl with the force value: before the pr<>ees, outpul image is OUtput, th~ C P U oWf'nites the oucputs wieh ehe force valuc. NUl,,: lorclng is '101 lerminaled by du.,inK III... lorce w;nuowor Ihl! , ... rlab/e /able. or by b1V'Qkinc tit", ccmnrfcm 10 tit.. CPU! Yo" "m, only ddele olorr:ejvb w;th VA'ITARtE -+ STOP FOJi;C",,0.

When forcing peripheral outputs PQ. the c;"ted Output Q in the pf""'CS~ imag~ is not updaled and n<ll forced (fon:ing is only cITe<:the "cxternally" to 'he mooule oulpuL~). The outputS Q are rctained and can be overwritten; reading the outputs yields Ihc wri"~n vlllue (no, the forc~ value). If an output module is forccc.l and if Ibis module fails or is "'moved. it will recei,"e Ibe force value again immediately on ",connection. Thc Output modules OUtpUI tii!!na! STate "'Q'" or th~ substitute valu e with thc OD signa l (uisaltle

"so-

89

2 STEP 7 Programming: Sofuvare

output module, at STOP, HOLD o r REST>\RT) - even if the peripheral outputs are forced (excc~ption: analog module, wilham 00 evalu_ ation continuc [0 output [he forcc value). If the 00 5ignal i. deactivated, thc force va lue becomes effective again.

tion to REST ART and deactivated again at the transition to RUN.

2 .7.6

Test and process operation

If, in STOP mod~, the function En"blc PQ is activated, the force value s a l,o become effective in STOP mode (due 10 deactivation of the 00 signal). When Enable PQ is term inatcd, [hc modules are set back to the "safe" state (_;gnal ,tat~ "0" or ~ub.ti lutc v alue): th e force valuc becomes eff""tiv~ again at the transition to

RUN.
2.7.5

Enabling Peripheral Output.,

Itl STOP mode, the oUlpm modllks are normally disabled by the 00 s ignal; Wi lh th e Enable peripheral oUlputs [unct ion . you can d~act;vate the on signal 00 lhat you can modify the outpm module. ev." at CPU STOP. Modi_ fying i. earried am via a variable mhle. Only the peripheral ompms ass ign ed to a CPU are modified. Pos,ihle apr>lic3Iion : wiring test of the oUlr>m lit STOP and without US~r program.

The rceording Df the program ,tarns infmmation re quircs additional cxecmion time in the proo:r.un cycle. For this reason, you can choose two opcrating modes for debugging purposes: tes[ mode and process mode . In test ",odi!, all dchugging functions can be uscd Wilhout nostricllOll. You wo"ld selcct thi" for examp le, 10 deblJll blocks w ithout conn~ction to the system, b~~ao,e this can s ignificantly increase the cy_ clic cxe~ution time . 1n pmces.< mode, care is tak~n 10 keep the inercase in eycle time 10 a minimum and th i< usults in debugging re'tric_ lion" e.g. Ihe starns display with progranlloops i, aborted at the return po int. n~bul':;:ing :,nd ,tep-by-~{ep program execmiC>ll cannot be per_ fonned in process operat ion. Test mode is set in lh~ factory on the 57-300 C PUs . You can sct lest or p race .. mooe 0" these CPU s with thc Hardware Connguration on the "I'rotcction"tah . Following thi . the configurlltion mu,t be compiled again and downl()aded to the C P U. The process mode is set in the factory on the S7-400 CPu s. You ean change the operating mode online w ith th e "Pwb'l'anl E-ditor. DEBUG -.> OPERATION .. displays the set operating modc and offers the facil ity of changing this on line.

Camion: you mil'" e'".,m' that no daflRcmu.< stales am re~u/l jr"m e""bling the paiphera/ oulp",,.'
Create a variable table and enter th~ peripheral outpul<, (l'Q) ami the modify value, . Swi tch thc variable table online with PLC -.> CONl-.'ECT 10 -.> ... and stop Ihe CPU ifne~essary, e.g . with PLC -.> OPEItATlNG MO DE and "STOP" You deactivate tho OD signal V"'-PlARL E -.> E~ABLE PERII'HEKAL OUTP\JTS: the module output" now have 'ignal state "0" or the substinne value or force value . You mod ify the JX'Iipheral ootputs with VAlUAll L E -.> ACT!VATE MODIFY VALUES. Yo" ~"" chan ge the modify value and modify again . You can ,witch the fun~tion off agai{l by "clceting VARlAlILt: -.> NAilLE PERIPHERAL O UTPUTS again, or by pressing the ESC key. The 00 "ignal is then active again. the modu le ou tputs au set to "0" ,md the substitute v al"" Or Ihe foree value i, re,c!. If STOP is exited while "enah le peripheral outputs' is 5till active , all p"ripheral inputs arc deleted, the 00 signal is activllled at ilie transi-

2.7.7

LADfFBO Progrum

St atu~

\\,ith the Pmgram status function, Ihe progrllm edito r provick:s an additional tcst melhod [or the u,er program. The editor shows you th~ binary signal flow and digim l value, w ith in a network.

The block whose rrogram you want to de bug is in thc CPU's u,er memory and is called and ed ited th ~r~. Open this block, for example by dOllb le -cl icking on it in lhe SIMATlC M,mager" onlmc w indow. Thc editor is stancd and shows the' program in the block .
SeieClth e network you want to debug. Activate the Program Statl," function with DEBUG -.> _\1UNlTUR. '-low you ~an see the binary . ignal

'2 .7 Tcstin& Ihe Program

E . . .
......... .........
......... . ,......
" --"

"

..-...... .-......
. -- ~.

" --" "--'


>

....
.j

.,

".--0'

." . .. '.. ..
0

"._......

.,

.,.,'

" ' lU..., 2. 15 LADfFBD prtrif1l'" StUUt

now ,n the bl"",k window and you can follow the changes in it (Figure 2 .! ~). You de tine the reprcscntnlion (e.g . color) in the proiram editor with OPTtONS -> CUSTOMIZE on the "LADI FBD" tab. You can de acliv"e the PrOiram Sla tuS function again by selectinlil: D EBUG -. MON lTOR agai n.
You SCI Ihe trigger conditions With D EBt.:G -> CALL ENVlRO)<MENT with debug mode switched on (see chapler 2.7.6 "Test and pmcess ope-ration"). You requir<: thil sc ning if me block 10 be debogged ;s cu lled mOre Ihan once in your program. You can inil iute statl.,s record. ing eilher by specifying the caU pa th (deter n"ned from Ihe: reference dala or manually) or b y milki ng il dependem on Ihe opened data bloc:ks w~n calling the bloc:k 10 ~ debugged. [f you do not set the call env'ronment. you monilor the bloc:k when it is cailed for Ibc tirst time.

l\ l odl~'[ng

addressfi

YOll can modify addre.~es in the program 8,ams function. If the address is of dala type BOaL. mark il and selec! DEBuq -+ MODIFY ADDRESS TO 0 o r DEB UG -+ MODIFY AOUM.(SS TO I. With a different data iyp<". ..,leet Dr.sUG -+ MODifY ADDRESS, and = t .... the modified va luc for the marked address in the dia log box displaycd_

Opera tio ns on Ihe

~onta~1

In Ihe Prollram Starns function, you cDn directly mo-d ify b in..f"y input. and bit me mories in the user prOjp"llm by mcan~ ofa button. The fo!lowin" prerequi.ites exist for thi S funClion;
~

In Ihe symbol table. yo u 115silln Ihe inputs and bi t memorieJ with the B"ribute CC (Control at Contact, $ee "Spo..-cial object propenie. in C hapter 2.5.2 "Symbol Tnble).

2 STEP 7 Programming SoftW2lJe .. You have enabled operatioJ\!S on the contact in the program editor using OPTIo!'S -+ CUSTOMIZE on the MG<:11CTaZ" tab. .. YOI,I arc online in the program 51al1,l5 with OF.Il UG -+ MONffOR and additionally sele<:t OfJIUa -+ CONTROL AT co:-"rACT. The symbols and addresses of the binal)' inpuIJ and bit memories arc d isp layed n hl,lnons which you Can acc ~ss using Ihe mouse. Addresses programmed "" NO conta(:U or addresses with scanning for signalstarus 'Z Ihen delivCT lhe address status 'T'; addrt"s~s projrBmn ... lOS NC contacts or a.dd~sses with "d scanning for signaZ status '11' deli"er the slarus .1)'. when accessed_ You can I,Ise lhe CtrllSIrJI key and the mou"," to selcct several add~sscs and 10 access them simultaneously when oper. ating on the COntacl. You deselC'Ct the operands in the .same manner.
2.7.11

_Mo=R.

YOI,I Can now

VICW

the .~Iual val-

u"" in tbe wor!< memory. and alS(! SC1 (modify) them if =iuired. U.ing PLC -+ DOWNLOAD.
download Ibe modified BoCI\1aI values into the work m~mol)'. or usc FILE -+ SAVE to impon Ihe modified values into the omine data management (first switched off OBBUO -+ MON ITOR).

Using Parameter assiillment for dnt~ blocks' you Can directly view and modify Ihc actual values in the work memory of the C PU. You Can also view the actual values here lIlling DEIlIJO -+ MONITOR. and you Can also adjllllt them. U'illg PlC -+ DOWNLOAD PARAMETER SETlTh'G DATA you have lhe possibility for only wriling the actual values into the work memOf}', and nOithe complete data block. Uling DATA BLOCK -+ SAVE you can impon Ihe data block into the omine data management. The advantag e of Ihe appli,ation Parameter assignment for data blocks' i5 to be fOl,lnd in the poSSibility for displaying and panunetcri>:ing data bloch in the pllr1lmeterization vlew_ Prerequisite : the sy.t"," 8t1ribute $7_t""'},parum (1lInologica\ functions) ;5 SC1. Mnd a parame_ terizatIon desktop is avai lahle, e.g. from an option package_ Figure 2.16 $hOWl! compari. SOD hetween panuneterizalion vicw and data view Wling an example of the iMta...:c data block for the controller function block FB 58 TCONT_CP from lite standard library PID Comrol Blocks_ Its para meterization desktop is supplied together with STI,P 7.

Monitoring and Modlfyln!: Addrcnes

I)~ t.

If the vHriHblcs to be debugged are present in data hlocks, you can also view and modify them di re<:tly. Se1ectthe data block in the SfMATrc Manag<cr and selC'Ct EOIT -+ OPE!" OBJECT. With STE P 7 V5.2 and later. you will be uked in the default sctting whether you wish to open the data bLock using the program editor or lISing the application Parameter assignment for data bLocks
M

Switch lhe data vicw on in the program editor using VIEW -+ DATA VIEW. and ...,lcct DEBI,O

92

2.7 Tdtina the Proj.rarn

-'.I

..--,.,..
......... v_.

,J

--. -. ,... -- . ---


,III

-"''-

, ,

"

3 SlMATIC S1 Program

SIMATIC S7 Program

This chapu:r ~hows you the srrucrur~ of lhe u~cr proJIT~"' (or th~ SIMATIC &7 -300/400 CPU, starring from lhe diflb-cnl priority c1a~~s (pro8111m ucculioll types) via lhe eo"'ron ....! part. of & user prowam (hlockll) right up lu the ,,.rif\hlcs atld dat~ lyp"". The focu.< of this chapter is the descriplion of block prugrammins .",.iLb LAD and r RO. Following lhi.:I i, a dCliCripuUll uf the dalll IYJICS.

3.1. 1

P rollr am

l'roc.~ssj n lll\ftlhods

You dcfine lhe structure of the us .... prorm


ri&ht bad:: al lhe de8ign phase when y()u .11.;op1 the teclmological and fWl~tiunal C(lndiliOn:.; it ;~ deci~ivc for program creation . program test and ~l"rtup. To achieve eflect ive prugramming. it is therefore nece~sary to d"'Ole '~;al &ll.ent;on to Ihe pmgr:am stTU<.'turc.

The o.1.'ieT pTUgram may be comj>Of;Cd of 1'1"0gram sections which Ih~ CI'U processt'S in dCpol'ndet1ce OIl cmain e""TIts. Such an event might be the Starl of the .ulomal;on sys1em, an tnlerrupl, ot detection ofa program errot (Figure 3.\). Thc programs .\located to the e venu arc divi ded into priority clllllses. which determine the program p~iDg ortkr (mulUIII inlerrupubility) ",hCll ""venl.l "',.. nI5 oc"ur.
Tbe !owc<I_priority prognun is the main pm~ which is proce~~cd cyclicall y hy the CPU. All other event, can interrupt Ihe main program al any I""mion. the CP U then execute, tl:e as",ciatcd interrupt .~rvi~e routine or errnr

3.1

Program Processin!::

Tile ovendl program for a CPU consists ()f the operating system and Ihe user progfll.m.
Tho operating .ystem is the totality of all imtrucHon! ond declaralion' wh ich comrol the 5y~tem re,nUTCe' and the processes u,;nQthc sc rc,wurc.::s, and includes ,uch thi ngs as dala b>l<:kup in tne C,"""l1t ufa power tailur". the actio ~ .. liou of priority daSS<.'s. and . , on. The orer " at;ug system is a ~omponenl of the CPU I() ",.hich you, a~ u~er, have no wme access. HOw ever, yOll can rclOild the OJ><"I31ing sy.tem from a m<.TOOty card. for instance in the event of a pmgt1lm update. The Us('T program is thc total ity o f all instn1Ction~ Hnd ded,Il<llioru; for sigllal proce.~sing, through .. lIich a plant (process) is affect~d in accordance with Inc <icfined contmlt,"s!..

A specific organi~ation block (OB) is allocaled 10 each even\. The urgani1.&liOl1 bhxk.s rcprcseal the priority classes in Ihe Ui .... prognom. When an e,...,1t uceutS. the CPU invukc the aWilloo UIg!ll1i7.alion block. An UIW"lizalion block i~ a part of a u.er pTOjlnil.m ",hicb yUIJ your<el rm.aY"Tite. Before Ihe CPU begin. procH,;ng IN: ",ain progrdm, it ~xecutcs a .tarrup rom;Tle. Tlli< routine Can be trigg.red by .wiTching On tile !llni,,~ power. by actuating the mode ~w itch illl the CPU's front punel. or vi~ the programm ing device. Prognm p,uce..iug following exu_ lion nf the Slartup routine .lWDYS slart! al Ihe heginnina: of the main prullfUm in the case of a cold resrart or wann restan; in S1-1-OO S)'lIem . it is abo pnssiblc tu resume the program Kan at the point al ",hich it was inu:nupted (hOI
reslart).

-.

hand ling routine and rer~n\s 10 the muin pm-

The main program is in orgamzat,on block OR I. u'h ich the CPU alway. procH.oe~. The Sill" ofthe u~er progrnm i, identical 10 Ihe first nCI,,"orlc ill OIl l. Airer 08 I ha been proce<sed (end of program). the CPU r(turns to the oper-

Pow. on

1
0

L /

I
""""m
SI~nup

I C,.. I I

~ ~
M al ...

<lnletTUpt>-

'""""'"
p ro_ in(ellupl

I
IntorrupturoAee

~
~

~-

I
Error ha ndllnq
routine

<Faull>

g,am

OperaUng

,
.~"'m

)
,

FIlM .. 3. 1 Mnhod. or Prnct.-.<ing the U-= PToi<"J"

atinj system on.! , "fter calling fOT Ihe execution of v ariou~ operating 'Y'icrn function., ,uell as th e t,pd a!i ng of the proc"" images, il once ~gai n calls OU I.
Evcntl wbich can intervene in the program om: inl('ffilptS and elTOrs. [nferrupu can come from the pn)Cus (bardware interrupti) Of from the C PU (watchdog ;nt",",,-plS.. timcof-day inl~"T' ruplS. CI"',). A. far ...-ron are concemed. I d istinction ;s made bctwe= synchronou~ and

inlcrrupl tim! was

I!~ncrated

\)eCltU:IC a module

was bdng replaced.


A
~ynchronou.

error is a n error C(I llSI'd by pro-

gram pnxcssin g, such as acceuing a non"")I;sI~nl address or a data type: eonversioll error. The
rype ami number of r<:rorded evcms and the

asscx:;alo:-<i o'llanizalion blocks are CPU-specific; nol every C PU clUl handle all possib le STEP 7 ,,"enl'!.
J. I .2 P r] " r lly
Cla.~lfl

asynchronou. errors.
An asynchronous error is an error which ,g independent of the p rognun ..,an, for eKamplc

failure of Ih~ p<lwcr to an cxpan.ion unil or an

Table 3.1Ii.l. Ihe availab le SIMAT IC S 7 organization blocks, cach wilh il~ priority. In Solne

3 SIMATIC S7 Program

priority classes, you can change the assigned priority when you parameterize the CPU. The Table shows the lowest and highest possible priority classes; each CPU has a different low! high range; a specific CPU occupies a section of this overview. Organization block OB 90 (background processing) executes alternately with organization block OB I , and can. like OB I. be interrupted by all o ther interrupts and errors. The startup routine may be in organization block OS 100 (wann restan), OB 101 (hot reslan) or OB 102 (cold reslart), and has priority 27. Asynchronous errors occurring in the startup routine have priority class 28. Diagnostic interrupts arc regarded as asynchronous e rrors. You detenni ne wh ich of the available priority classes you want to use when you parameterize the CPU. Unu,ed priority classes (organi2ation blocks) must be assigned priority 0

warm restart, hot restart); monitoring of Ready signals or modu le parameterization: maximum amount oftime which may elarsc before a warm restart
f>

Cycle/Clock ~femory Enable/disable cyclic updating of the process image: spec ification of the cycle monitoring time and minimum cycle time : amount of cycle lime, in percent, for communication: numbt."f of the clock memory byte: size ofthc process images Numb-er of relent;ye memory bytes. timers and counters; spec ification of retentive areaS for data blocks

> Retenti"e Memory

(>

Memory max . nwnber of lemporary local data in the priority dasses (organ ization blocks): max size Oflhe L stack and numberofconununi cations jobs Interrupts Specification of the priOrily for bardwarc interrupts. time-delay interrupts. a.<yn chronous errors and D?VI interrupts; assignment ofpanial process images with process and time dclay interrupts Time-of- Day Interrupts Specification of the priority and assignmems of partial process images: spec ification of tbe start time and periodic ity Cyclic Interrupts Specification of the priority, tlte lime cycle and the phase offset: assignment of pania] process images cycle interrupl< Specification of the priority: a.signmcnt of DP maSler system and partial process images Diagnostics/Clock Spec ification of the system diagnost ics; type and interval for clock synchronization, correction factor Prolection Spec ification of the protection level; defining a pa<sword; setting o f process or debug mode MU]licomputing Specification o f the CPU number
Synehl"(lnoi.l~

f>

The relevant organizalion blocks must be programmed for all priority classes used; otherwisc the CPU will invoke OB 85 "Program Proce,sing Error" or go to STOP. For each priority class sclcrled, temporary local data (L stack) must be available in sumcient volumcs (sec Chapler 18.1 .5 ""Temporary Local Data" for more details).
3.1.3 Spccificatiotu for Progra m Processing
f>

f>

The CPU's operating system normally uses default parameters . You can change these defaults when you parameterize the CPU (in the Hardware object) to customize the system to suit your particular requirement<. You can change the pa .... metcrs at any time . Every CPU has its own specific number of parameter settings. The following list provides an overview of311 STEP 7 parameters and their mo,t important settings.
f>

I>

c>

Geneml Name of CPU, plant identifier, location 10. scllings for MPI interface (if the interface is not combined with DP). comment Startup Speci!ies the type o f <lartup (cold restart .

(>

f>

(>

96

3.\ PmgramProcessing

T~bl~ 3.1

SJMATJC S7

O,gan i z.tiOI~, :::"''-------------T---';;;;;;;;'--' "'~

,
,
0"

Modifiable .

,.
modulos
Wi th ... tu>. update

16 to 2J

PROFlBVS DrY I
,or mOOe

"

tech no1_

In the c""" "f lo., of redundar>ey "'"'",.,

"Co,. ' ~ I

1n th e C05e

ORRI
OB
~5

toOB ~4, g6.g7

:~~c c. c
failure,

Sloer",' .

OB

~8

26 2) 2 5 2) 25 ) '

'" " '"

" "

2 to 26 2 to 28 2 to 26
No

2 <026 24 to 26
No

N"
the em::>'"

"

t>

integrate<! function Ac tivation and parameterization of the imegrated functions Communication, Definition of ~o"nection reSourceS

On startup. m~ CPU puts th e user parameters into effeet in p la<:e of the defaults , and they rem ai n in force until changed. Proll:rllm
len ~.'th,

t>

memory requi,-., menls

"" Web Activation of the Wcb 8crYer, language se_ lection

Th e memory requirements ofa compile<! block ar~ listed in the block properties . If you "elect the bh'>cK in the SIMATIC Manager, and then seleet the " ".neral _ Part T tab us ing E DIT -j.

3 SL\IATIC 57 Program

OIUEc r I'ROPERTII!S, you will Ix: pruvid;;d wilh the load and work memory n:'Iuiremcms for this block. The length of the uocr progrRm i.' li>ted in the propert;"" of tile offline BloeM conta in er (selecl Bloch and EnlT ~ OBll'CT PROPERCIES). On the "Blocks~ lab you will find the data " Size in ..."OJk memory" anod "Si7e in load memory". NOle that the configuralion data y<tcm data hlocks) arc missing in the value for th~ load memury. The SIMATIC Manug~'f shows you h l "c k~ in the demi\ vicw with the container open (displayed as table), and the memory TIuirements in \he staru~ line (bottom right in window) with the Sy.'lcm dOIQ object selectro_ With the progrnmming device switelxd online. the cunen l ottupation o f the CP U memory is sho"'-n by Ihe SI;\lATIC Managcr under PLC .....
DJAONOSTI,/SE'lTI-"O
~

tied by the systt= function DilL.


MOdule ill

S ~'C

84 \'lR1T_

Innov.I~...J S7-CPU" PROflBUS DPYI slaves and PROfL ET 10 de'~ces am :mppnn func'I lions for idenlifica.tion &. maimen= (I&M f\uu:uons). For example. you can provide a ~t.a tion wilh a higher.level itelll desillnatiou and ft 1(>(&lioll lD and evaluate it laler in the program. The higher.level ilem designalion ;s used to i.l entify parts of the plant un i 'lU~ Iy a~~ording 1 0 their function . The locati on 10 is part o/' tlte it em designation and de~Titx:s, rur cxample, the precise localion of. S IMATIC ocvicc with_ iII pruc<:ss pl""t.

M ODUll

I-" fOK. "t~

noy.;, " Memory" tab.


Chccuum The progt1lDI editor grnerates a eheel<sum for all blocks of the u,;c,r program, and stores il in Iltc objc(:t properties of th" B/oc/rs comaincr. l\knlical program~ have !he sarno:; ch~"Cksum, ",ach change in the program al so changes the ch<x:ksum. A checksum i.~ al~o g~e"'ted trnm Ihe system d"ta. You can view the cheeksu"" in the SIMATIC Manager with the Bloch con ta iner .ckeK-d and EOIT - t OUIECT PRonR

To emer the 1&1,,1 data, ~elecl the module in the Hardware Configunuion, Ilten select EDIT ..... QnJECT PROPERnF.S, and then - wi lh an appropriately design:d module yuu can enter the higher-level ilem dc~il:lnU liun lind the location lOon !h~ "General" lab or tbe "Identification" lab, In online modi:, you se lect the module and C~n then exchange the I&M dau. oclween of fline dloa managemCIlI anoJ th~ module with PLC ..... DoWNLOAD I-IOI)I.:U' IDB'Tlf1CAnO"l or J>LC ..... UPLOAD MOOt..LE IDE:YIlflU,nO:-l TOrG.
To anal)?e the r&M dala, us~ SFC 51 RD SVSST 10 read Ihe system st,ttu . lisl with the iy.t~m status list ID l6#OIIC Index 16#0003 for Ihe hiiher-leve! item <ksign~thm IUId Index 16li0009 for the location 10.

"\05.
The c1l<:cksu m oflhe uscr prugnun is genemlcd from the program code and Ih'" default and ini. lial vai u"'5 of the data blocks. The writing of dotta add",.,"" in the won memory ("ct~al \ 111ues) does not ch....nge the checksum. Th~ checksum i ~ only adapted when the data blocl.<. are uploaded to the "mine data management, when the actual va lues become the ini tial values. Th;~ al90 81'(llies to the data blocks aeneratcd by a ~ySlem function. If a data block gcnerRled by S}'Slem functions i~ "'"tlen or d eleled. Ihe "'hecksum ;s nol changed. The checksum is adapted i f a pro &mmm~-d (loaded) diIla block i. deleted. or if Ihe inilial values in the loud memory me modi

3.2

Blocks

You can d ivide your prQllntm inlo a:s many s~c


l iuno as yO\1 wanllO iu ortl~r tu m ilk" il easier to

read and u.ndersmnd. The STEP 7 prowamming laD!'U~g~ upport this by providing the neceSsary funetiuns. Each program seclion should be !<elf-<':oDlained. and should have a lechnological OT functional ~is. The<e program sections an: refcrred 10 as "mocks". A block is a section of n UMr proif\lm "hieh is ddhwd by it;! functi on. ~ lruCt U'" or intended purpose,

'"

3.2 Aloc ks

3.2.1

Rlo ck TYI'es

FunCiion.I' (Fe's)

STEP 7 provides d ifferent typt".' o f blocks for dilTe rent tasks:


>

Uoer blocks Bloch conta ining user program a nd u ser data Sy,tem block< Rlnch containi ng system program and sys tem data Standard blocks Turnk ey, off-the-melfblocks, such a, driv_ ers for FMs and CPS bloc k s

[>

Functions nre used w program freque ntl y recurring o r comp lex automati on functio"". They can be param~lcrizcd. and rctum a val"c (cal led the funct io n ,alue) to the calli n g blu"'::. Th e function value is optional, in addi tion to th e function value , f"nct ,ons m"y a lso have o ther output parameters . Functions do not store intor mation, and have no a ssig n ed data block.

I>

Us~r

In extensive an d complex program" <'struclllring" (dividing) of the program ink> bloch i, recoI!1Tl1cn dcd, and in part necessary. YOLl may choose among different typ~s of blocks. depending on your application:

Da ra blocks (DBs) These blocks contain your program's data. Fly programming the data b locks. you dctennine in whic h form ~he data w ill be savcd (;n which bl oc k. in what ortl~T, and in whm data type ). There are two way" ofu,i"g data block s: as global data bl o~ks and as instance d"ta blocks . A globa l data b lock is, so to sp~a k . a " frcc" data block in the user program. and is nO! allocated 10 a "ode block. An instance data block , how_ e,"er. is a,s igned to a func tion hlock. a nd ,tores part of that fun Clion block's local data .
The number of blocks per block type and the length of the hlocks is CPU_dependent. The nllITlber or o rganization block s, and their block number.,. are fixed ; they an.: assigned hy the CPU', openoting system . Within the specitl cd range. you can a"ign the b lock numbers of the other block typ~s yourse lf. You also have the option o f assigning cvcry block a name (a 'ymbol) vi" the symbo l table, then referencing each block by the mun e a>signed to it. Sy.tem h loeks System bloch arc compon cnt~ of the operating sy5lem . 1b ey can conta in programs (system functions (SFC,) or system fun~1:ion blocks (SFBs)) or dala (system dma blocks (SDFls)). System blocks make a ncmtbcr of important sy>lem fu nction s acces. ib le to y ou , such as man ipula~i ng the internal CPU dock, or various cotnmu" ' ~"tions f"n~'ti ons. You can call SFCs anti SF8s, bu~ you cannot mo dify them. nor can you program the m yourse lf. The blocks themselves do not reserve spaec in uSer mcmory; only the block: calls and (h" inSlance d ata blocks oftb e SFB . are in user memory. SDBs contain information on such thing' a s the configuration of the automat ion system or the

Orx""izar;oll Moe,,",' (OBs)


Thesc bloch serve as the interface between operatillg .yo>tem a nd user program. The CPU', op<-'nning systcm calls the organ i ~ation blo~b whcn spec ific events occur. for example in the eve nt of a hardware or timc-of-day interrupt. The ma in prOgrdm is in o rgan;7.ation blo~k 08 I. Thc other <ftganization b locks have petlnanen tly assigned nutnben; based on the event. they arc ~al1cd to handle.

FUllction blocks (FE .)

These b locks are parts of thc progrnm w hose


calls can be programmed v ia blo~k parameters . They have a v ariab le memory which is 10~atcd in a data b lock. This tlata block i, pemlanently a ll ocated to the functiol1 block. or, to be more precise to the function block call. it is even possible to a<sign a dirr~rent dma b loc k (w ith the same data 'inlCture but conta ining different v alues) 10 ea ch function b lo"k call. Such a p ermanently assigned data block is ca!letl an in stanc e data block. and the combination or fund ion hlock call ,md instanc e data b lock is referred to as a call in stance, or "inst ance" for short. Function bloc.ks Can ,,-Iso save th e ir variab les in thc instance data bloc k of lhe call ing f"nction b lock: tbi8 i8 referred to as a " local instance"

3 SI"tATlC S7 Program Table 3.2 Numher range, lOr sy" e m dat> bl,)(,k,

, overwrite.

ti

II

coofig-

"
"
"

e .g . a,., ign mont of logical

,
rOT HIf and

parameten""tio" of the modules. STE'P 7 itself and manages the., e block s. You. how~vcr, dClenni ue their contents, for instance when you configure the stations . As a ru le, SOBs are located in load memory. You cannot Ol"'n SDB" and ean only read them from your program u,ing speeialsy stcm bloch. e ,g. when rmramelerizing modules.
gencrat~.,;

Chapter 25 "Block Librarics" con tain s an over view of the ,tandard b lock s s"p phed in the Standard Library.

3.2.2

Block Structun.

Essentially, code blocks consisl of three pan, (F igure 3,2): ""


Th~ block header, wh ich contain, the block propcnie., such a s the block nam~

Double cl ick the System bloch ohject in the Blocks container to d isplay a list of current syslem data blocks generaled by the Hardware Configuralion to<J1 (in the offline container) Or present on the Cl'V (in the online contain~'T). Table 3.2 shows an ovcrvicw of the numbering ,}'Stem for ,ystcm <lata bloch.

;>

The declaration se<:tion, in which the block-local v:ariablcs arc d~darcd. tha t is, defined

t>

Standard blocks

The program <e<:tion, which contains the program and program COnll1lentaty n,e block header contains lhc b lock properti~s

A data b lock is similarly structured:

In addition to lhe functions and funClion blocks you crealC yourselt~ off-the -shelfhlocks (called "standard blocks" ) are a lso available. They can eilher be obtained on a .' torage medium or ~re contained in li braries deli,' ered ~s pan of the STEP 7 package (for example lEe function;;, or functions for (he S51S7 eotwcner).

1>

1>

The dedaration ,ecliotl cOlllains the dcfilli(ions of the block-local va ri ables, in this case lhc data addrcsse, Wilh data type specifi cation

""

3.2 Block!;.

;"", ,,,o,,:,,.," .. .,"", , OO~~"".,m,m""', ___~ ,,,,,-, , ,,,,,m, .. ",,

...

Logic b lock , sourc"-orl"nt ,,d p rogram ming

Blockfleader

Block type Address Block head9.

name, Data type:_ In~;aliz . ~on: name. Darn type'. In;!;alizatTon:

PrOfJrlIm

BEGIN
Program

END_Block Type

Data block. In"",m"ntal prog r8m ming

Data block, .ource-orlented prog ra m m'"g

Block I>c"dcr

I
''''
In itia l value

DATA_BLOCK Aadress BJock h9lJder S TRUCT "!!me , Data name: Data


t ype:~ tyP": ~

I
-

Decl6relion
Address

INama
J

-,..
.~

...

InrualizBtiQn: Initialization;

II
i
,

END STRUCT

I
I I

BEG IN

name

.~

Initializa tion;

END_DATA_BLOCK

II:

Fi ~n ,..,

3.2 StructUTC ofa Olock

l>

The initialization <""lion, in which initial values can be sp~cified for indi vidual data addresse"

3 .2 .3

Block Properties

Tn incremen tal programming. the declaration St:ction and the initia]'>alion ,ection are comh ined_ You de line the data addrc>ses and their data types in the declaration v;.ow" , anJ you ~an i1lilialize each data address ind ividually in the "data view".

The block properties. or attrib ules. an.: conta; "ed in the block header. You can view and moJify th,"" b lock pmrc1'1ics with the me tm command EDn --jo OWRT PROPERTIES ill the S I"'lATIC Manager when th~ bl()~k i~ selected. or w ith Fn.r. --jo PROPl'RTJES ill the l'rogram Editor (Figure 3.3).

w,

3 SIMATIC S7 Program

,-....-~

(RIO<

ji5;-'
Ifij .~ ..... _ ,"_. f~ ""' _"""

G"' od ~ '-""'

,,-p,",

' ~991(1lll " '''''

', I211l ... ""UW ....

~O_

,-

r ____ _ _ r 0 ' ~ ~"'"_ ~ "" ....c r


W " ",,", ",

"'""-""" w_ "'....
_

"General - Pftrt I" tab Under Nume. this tab con rain s the block '. absolute address with block type and number, as we ll as the symbolic name and symbol comment from the symbol1able. In the caSe of function blockJ;, an indicat ion next to the name shows whNher the block has a multi instance capability. lIthe m,dli_inS'(Jnce ""pilbili!y is switched on, '''hich is nonnally the cas~, you can call the block as a local instance. and can al", call further function blocks with multiinstance capability with in it as local instances . You can deselect the multi-inslu" ce capubility when creating the function block; with a .oure eoriented program input, Ihe keY"'ord for deselecting is CODE_VERSION I . The advantage of " function block "without multi-instance capa bility" is the unlimited application of instance data during indirect addressing, whieh is only of significance with STL progranuning. The tab also shows Ihe crearion language oftbe block (which you set wh~n crealing the block),

and the memory locations of the block and the proj ttt.
The program witor SaVeS the creation or modi fication date of the block in two time stamps: these are the block pararnC!ers and Ihe 'tatic local data for the progr.m code and Ihe interface. Note thaI Ih~ modification date of the interfac e must be equal 10 or smaller (ol der) than the mod ification date of the program code in the calling blo<:k. If thIS is not the case, the program editor si gnals a "time 'lamp conflict" d uring output oflhe calling block.

The ,ommen t d isplayed consists of th~ block title and the block COrruncnt wh ich you entered when programm ing Ihe block.
"General _ Parr 2" tab

Thc N am e (Header) displayed on this tab is Ihe block narnc; il is not idemical to the symbol address. Diff~n:m blocks can have the Same name. Us ing Family you Can assign a conunon feat ure (0 a group of block s. The block name

'"

3.2 Blocks program inpul for switching on the write prot"""lioo is READ_Ol'o."Ly' The block header of any staodl.rd block which comes from Sieme"" conluins the S/(Jndaro block anribute, Data blocks can be assigned the Unlinked attribute. Such dala block5 are only present in load memory, and are not relevanl 10 processing. Since their data are nOt locale<! in work memory. direct acccs~ is no longer possible_ Data in load memory can be read U$ing sY$tem functions and - if the load memory is a micro memory card - also written, DMit blocks with the Unlinked attribute are ~uitable for record ing data which arC only rarely Hec,,~sed. e.g. recipes or archi,,, . This attribule is switched off lIS standard. but Can be clumg! at any time u.ing the program editor_ The keyv.oord with .ou!'CConented program inpul for switching on this
ftltribu\~

and family an: displayed when insening blocks if you sc lecllhe block in the dialoll; window of the prollram element caTa log. u..e Author to cnt~r the namc ofthc block's crelltor, The namc, family and author may have up to dht chameICrs cach. commencing with a leller. The letters. d igits and the underline characler arc: permissible. The Venion is ente~ wllh N 'O 2-dig;t numbers from 0 to 15. The len~h dala slwwthe memory allocation for the block in byte~'
~

Loc1l1 dam: allocalion in the local data stack (temporary local data) Me 7: size of the block (code only) Load memory requi.rcment \Vork memory requirement

~ ~ ~

A block occupies InOI"I: space in the load memory 8ince the data 001 rc:levant 10 processing arc: oaved here in ~ddition.

is

UNL~KED.

The Klto",-how proleCli(m Huribute is used for block protection. If a block iH know-how.protected. the program in th at block can not be viewed, primed out or modified. The Editor shows only the block hcaderand the declaration table with Ihe block pammeters. You can assign \his aunbute during sourcc-oncrlled inpul orthc block with the key",oro K.,-':OW _HOW_PROTECT, When you do th is to a block, no onc can view the oompi\oo version of that hlock. not even you (make sure you keep the sou...:e file in n safe place!) , Th" att ribute DB is w.-ile-profeCfl'd in Ihl! PLC is an aUribute for data blockionly. II means that you ean only read that d ata block in your prog"un. Output of an error mcssalle pre"CTlts the overwnting of the data in that data block _The write protection applies (() lhe data re1C"llIIt to processinll (aclual values) in work memory; the dala in load memory (inilial "alues) can be o'-crwritten e"cn iflhe data block is write_prot~cted. Th is write protection fearure mu.t not be confused wilh block protection, A data block with block prote<,:tion can be read out and ..... ritlen 10 in the user program, bUI ils data ean no longer be ... ie .....e<.! wilh a programming or operalor monitoring device. The attribu:e DB is ..rill!' pro/eeIM;n Ihe PLC is switcbC<l off ..... standard. bUI Cilil be changoo 01 any time lIsi~ the pr0gram OOitor. The kC)word with wun::eoriented

The No" ,-,:tailt attribute means "nan-tctentive" and is assillned to CPUs dnigned for this for dat;! blocks. If Non reral" is s ..... itched 00 . Ihe d ahl block Ir.msfef!! the initial vBlun from load memory ro WorK m~mory in the ev~nt of a power ofton and with a RIY.-l-STOP transition (response as wilh a cold restart). If Non ",wi" is switched off. the corresponding data block th~rc:fore being ...:u:n!i~". il retains illl actual vRllIe$ ,n the Client ofa power oft7on Bnd with a RUN-STOP transition (response a~ w ith a wann reStllft). This attribute is switc hed off as .tandard. bUI ~an be changed at any timc using the program editor. Th~ hyword with .ou...:eonented program input for switc hing on this attribute is NON RETAtN . Blocks saved in the Program Edilor w ilh the menu oommand FILE -+ STORE READ-O"\"LY for reference purposes. for ell ample, receive the block property iJkJck read-on!),. These can be all eodc blocks. data blocks, and U!ICr-detlned data typcs , Tbis property can only be se t with thc Program Editor. and thcre i~ "0 keyv.'ord for source-oriented progT'll.mminS for this purpo.e.

"Calls" la b
This tab shows a list orall blocks called in this block with tbc lime stamp$ for the c;ode and the interfaee. With in.lance dala hloch, the basic function hloc k is shown here togeth~r wilb Ihe

.0)

3 Sl\lATlC S7

Jl'ro&nm
Howe,.. r, Ihe interface connict generally as a "time stamp conniet" caD alw have other caUSe'_ It aIM) occuu if a calll or referenced block is younger than the calling block. Example. of the OCCUT1"'CnCe of time stamp connim indude the followilli '
descri~

loc81 instances (function blocks) call"" in thi, in each case with the time stamp:; for code and interface_
in!tan~( ,
~ Atlrlb .. u.~

tab

Blocb may ha"e ~y~tem ~llributeS. System auribulell rontrol and coc:m:iirulte functions betw~n applications, for example in the SIM i\.TIC PCS 7 control s)'Sttm.

po

TIle inttTrace of a called block is younger Iban the code of the .alhng block.

po

The inl,rrfiJce inilialuation does not agrtt


,,;Ih the block internee.
A func:tion block ;5 younger Iban its instlnce data block (the in stance data block is generall from the interfuce d:scription of the function block and should thO'Iefore be }'ounger than orlhe ~me age as the function block).

3,1.4

Block In tufacc

I>

The declaration table cont.aiM the interFace of the block 10 the rest of the pman.rn_ It consim of the block paramCters (input. ou!pUt and in. OUI parametcn) and al", - in Ibe case of~ lion bInds - the .Ianc local dalll.. The temporary local data, wbich. do not baSically belong 10 the block interface, are also bandied at this point. The block interface is defined. in the intcrfa.e window when prognomming the block, and i. initiali~ed with variab les when the block i. called (~ce Chapter 19 "Block Par.uneIen;").
The Program Editor checks that the block

> A 1()C1I1 ;n.1III is younger than the calling


instance (affect. function blocb).

> A user data type UDT is )'OWIgCf than th. block who:se ">riables an declared with the UDT: Ihi~ can b<: any block including a data
block or OIlother UDT.

Con'Kling innlid block

<.II~

paramder initialization in the caUed block agrees with the interface of the <:&BI block. The Editor uS<:> the time stamp for ws: the interface of the caBed block must be oldtT than th e code i'l the caUina block, thilt is. lhe Lost interface modifi c~tion 1l1u!t h~\"e been made prior to integration of the bl..""k. The Program Editor updates the interface hme stamp when the 'lUmber of parameters chanlles GT ".hen a dlrta type or a default value changes. TIm", , la mp .,... met
A time stamp conflict tXC1.tR whnr. the interlac.

Tbc Program Editor ~uppons you in different rna Mers in fmding and CQJTtlng in~a1id block calls. Sc-e the next s<C"licm r(lt" how 10 check the bloc\' ronsistmey in a complete program ("Checking block eonsisten<:y'l
You can ch""k bloc>:: ,ails which ba\"~ b~come invalid witb the bl..""k opelt (wilh the Cllisor at ~hc invalid block nil) using the menu com !II&Ild Eon ...... BLOCK CALL ...... UPDATE. Block calls can berome iD\"lLtd follo"ini insertion,

dtlC1ioo or shifting of block paramelers, or

"'hen cbanglog the name and type.


With EDIT ...... BLOCK CAU. ...... CHAl<GE TO .\ !t:LT1~STAl'CL CAI~ and "orr ...... BtOCK CAI.t ...... CIIA:<GI TO FBIDB CALL you transfer calls from function blocks imo local inst~nce calls or inlO calls "'ith data block. following mO<i,fiCBl10fl of the block calls_ you m""l regeneraie the associate.:! instance data blocks.
A f.lJ\her p<.>S'iibility i. provided by the menu command FD...E ...... ClIECK AND UPDATh
ACCE~S."The

of the c .. lled block hal a later Ume jtamp than the code of the calling block. You "ill notice a time ~I ru.np conflict ifyOll open an alC<"ady ~om_ piled block again. The f'T()aram Editor then indicate:; the incorrect block call m red. A time ,;t.atnp conflict can be caused. for ""ample, if you modify the in!erU5 of blocks thaI ~ Ilready ealled in orh.,. blocks, (It" if you com_ bine blocks from different programs into a n"" program, or if you ~ompilc a !lion of tM nvcnt.ll program with ~ sourcc file.

in,-ahd block callI in an opened bhxk iICC thrn updated orpresCnted for modification.

""

Ch~cldng

hloek consistency

11'e Program Editor only itldi calC8 a ti me stamp


confli~t when you open a block containing a time 'tamp conflict , If y ou want 10 chcd:: an entire pmgram, you can u,e the function <'Check blod.:: consi stency'" in the SI.\1/ITIC 'vfanager an. This purges a majority o f interface conilic," and direct, you to the program loca. tion, thaI re<Juire editing,

I' lca,c note that after check ing the b lock ~on8is" t~n cy, the instance data bloch and thc dam bloch g~nemted from the UDT are assigned t he initial value, aga in in the compiled pro"

""m,

To earry out a con,isteney check, sdcct the


Blocks container in the SIMATIC Ivlanager and !h~n EOIT --> CIlLCK BLOCl< CO,SISTfSCY, lfa call tr~ e is not displayed in the " indo",- e .g.

The Program Editor displays the progre<s and resu lt of the consistency ch~",~ in the output w indow (VII, w --> ERRORS A'ill WARNINGS). "lbe e ons;s t~'ncy check CaJI]101 be nscd on progr~m s in li braries,

lhe pTogram ha, been compiled u ,ing version of STEP 7, .elecI PROGRAM --> COMP I ~E in this w indow,
an
earli~r

bec~l1SC

Thc dependencies in th~ case o f call ~d or referenced blo~b are displayed in the fonn ofa tree d i"gram (t'igure 3. 4) , You can choo, c bctw~en the following two representations:

. ."
'
~o
~,

....u ..... [1>1'_]

..'001 [ot """I '"",,''''L ' [DO ~l

_",",,' [M ' _J

"0"""""

(0'

"'I

... _ do',,- [<>0 """I


'(~["" -I

..... . "oj' [:0""'1

,'
'i'
- . """-" I'" '''",I "~;:~ [''''I

."

",

0 0., '" Q '""" :;c.

," [C<'-I ~'-I


:eo &t~ ]

o o "Ol '"," -"""..,. [""I C at l"'l .Q o COt ........... L>"'l "", _


_

a """ _1....""' .. _

... "-'""'"""' 1 ''''1 ...... :=1


.p". . . ' 'w[RO) .F" ......'

..

"."..,..' [1'' '....1


.,....,.,. I'" ' ''.-1

0 ""
0 "'"

COl'
( "' ~ l

o CO!

~o..o'r_'''''''''[MO)
_

.P". . . ' [nol

.".......""... ' :""']

ot'" ('" """'~l OI' !"I':

Fi~Dr~

3.4 Exomplc of!h< Repr< oon"'tic" of the 'Check Block Consistency" [kp<ndcnde,

]1)5

T10e reft;thcr lree vie w displaYllt~ e lJepe nden.


a similar wily !o the progn.m Slrutlure: Oft rM left are the tallin& bloch. funher 10 II>c rigtu an; the blocks tailed in the blocks on tl>c lel't Example: inSl:lncc DB 20iFB 20 ill tallffi in O B I and local in.'lIlnccs FB 21 and FE 22 are callffi in FB 20.
aa1 ...

vided with the propr;nles window o f the block. On me "Genenol _ Part I" tab. sclect the number of the block under Name and the language "LA!)" or "FRO". You can entCT rhe remaining anribulC1l11ler.
t>

1n the Edilor "'ith menu command FILE -+


NI:\\. which displays a dialog box in which

The dependency tree view di,'plays the depcndcn<:: ics starting from all called or rderencffi blnc b. Thcy arc located in the left_lIftrnl tol umn. and the calling blocks arc ilStffi 10 tne ri&ht or thi5. bample: FE 22 stores its data in instance DB 201FB 20 that is tallffi in 08 L It alo;o has its own DB 29 and it iscal1ffi a, a local inStancc in FB 20. The dC lcnnincd infonnation is displayed in compact form by symbols. An e~chllnation marl:, for example. indicates thaI the obj~"Ct cllused a time Slamp conflict. A whue cross on a red background Ind,cates that the ~SlXiated block must be recompiled. If you select a block in the tree diagram orin the ..,utpot window. you can edit it witn eDTT -+ O PEN oBJ!cr, e.g, COJ1"C'Ct an incorreCI call.

you can enter thc d~sirffi bloc k untler objecl nom". Aft~r clo.ing the dialog box you can program the comeDl~ ofthc block. The Pmgram Editor uses the language set on the '"Create BlocI<'" lab uDder Omoss -+ CusTO\fl7'F.

You can e!ltcr the in f<1rmntion for the block huder when yo" generate \he block or you can omtcr the block anributes later in the Editor by open,ng the block and selecting lhe menu com' mand FILE -+ PIUJl'ERTII:.'1.

3.3.2

m oc k Windo"

J,J

Programming Code Blocks

The progmm ed itor shows th e variab le decl am tion table (block param~!ers and local data) and Ihe program ....indow (code and comrmnts) for an opened code block.. The pro~ elemenls cannol be additionally dlsplayffi in lhe n"~..._ ,ie'" "indow (Figure l.S). Va rl.blr declaralion tahl e
The variable declaration table i~ in \ h<; wir.t.low abovc llle progrom window. If il is DOl visihlc. posilWn thc moll.'" poinlcr 10 the upper line of demarcalion for the prQgnIm window. dick on

Chapler 2.5 "Creating Ihe S7 Program" contains an introduClion lO program creation and I<> operating the program editor.

3.J.l

ap.,nln g Blocks

You begin block program'mnll by oflemng a bloc k. Open an exisling block either by doublecli cking on the block in the SIMATIC Man_ ager " project window or by ",lectinfj FU_E ..... OrEN in the program ffiitor.

Irroo open. compilffi block in the Rlocks contai...,.., e.g. by doubledocking. it i$ open for incremental programming. This is the case borh with omine and ol1line progmmming.
'f lhe ~Iock doc~ 110! yet exist. you can grnerale it ;11 the following ways:
t>

the left mou~c bunon wilen the mou.., poimer chnwc5 ils form. and pull down . You will sec Ihe over"iew of the types <.>fvariah1c on the !efl . and Ihe variable declaTll.ll..,n table on the right . which is wbere you define Ihe bloc k_lncal "Bri_ abks (see Table 3.3). the left area. and filJ in the uoblc on the righl. of variable can be programmffi in c\Cry kind of code block. If yo ,) do nol usc II variable Iype , Ihe cnrr<:~potlding line remain! emply.

In order to declare a "ariMbk, sekcl il5 type;n


,",01 ~"cry type

In the SI MATIC Manager by selecting the 81.,.,h ohJt to rhe left half of the project ",-indo,," and generating a ncW block with ll'o."SERl -+ S7 aLOCK -+ . You are pro-

The declaration for a variable consists of the name. the data type. a dt-fault >"alue, if any. and a "ariable commeDl (opIiorul). Notall variablC1 ~an be 85signffi a dcfuult value (for instance, il

'06

3.3 Progro.mming Code B loch

'jo"

_n'"" ,,,' __ ~.~ . ' '''' .... , ...".. .......

,~"

..

,.... ,-, . ,-,


,~

-.,......_. _. ...... ....,. .w._._


... h.' _
., ... _ . }

....--.0_,

,_.
"... . _ _ _ _ _ ... _ ___
. ~_.

M __

~- - " ......""

:3

t ]litu ....

3.~

l:JIampl" of .,. Op..ned I AD Block

is nOI possible fm t"mpomry local dam). The default values for funct;on~...,d funttion blocks are described in detail in Chapter 19 Block. Pllmmc1crs'".
The ard"r of the declarations ill tade b locks is fixed (u ~hawn in Ih" tnbl ... abo\"e). while the oruCT within n variable 1)'1'" is arbitrary. You can $8\'" rOOm in ~mory by bundlIng biruuy variables into blocks o r 16 and BYTE ,'ariabies inlO pairs. 111" Edilor S!O~ a (new)

BOOL Or BYTE variable at B byt" boundary and II variable o f anolhCT datB type at a word boundary (begi nning a1 a byte with an even address).

ors

uepcnding on thc Ednor'. dcfauh Serling' the fields for Ihe block li lk and the block commen! anu,

In the program window,)'Qu will see

Table 3 .3 Variable Type. in the


Vatl""l. Type Input pat:amete",

O~d.rarion S.~llO"

Oed. .... ti""

P" .. ibk io moo .. Typ<'


K K K

OutP"t peramet"'"'
In-aw parameters

St.l ic 1 1data <>Ca

OUT J.1'. _O UT STAT

"

,. ,. ,.
,. ,.

Temporary local da .. Fune<ion ~ alue

"""

08

RETUR..'1

,e ,e

'"'

3 SL \tATIC S1 Pr<)f'l'II

if il i, Ihe first I>('twork.


..
~ode

th~ fi~lds

for tbe nl:l-

wort: tide. the network cmnm~n:. and the fkld to.. the prognm entry. in the program SCCIion 01

block. you control the di'l'lay of comand ~ymbo ls with the tllffi ....-ommunds VI !!W ~ DISPLAY WrIll. You call chan~e the ~ ; ze of the display w ith \IJ.Iow ..... ZOO'l I);, V IEW - ) ZOOM on ,md VJ..Io'1 ~ ZOO\! r ",Cment~

automatically. brginning with 1. Each block can accommodate up 10 nL'1"ork$. Yo:! may gi"c each network a nelwori<. IIlle and a nelwon: cornmenl Durina ed,tina. you can KIr ea, b lI"twor~ drrcctly wil h the Illenu COJlUn~nd l:'DlT ~ Go To --; ....
,,~

'"'
JJ.3
The
O"frvl~"
ov~rvie\\'

Window

clement

~PtIllO

window contains :ho: program owd the call rnue=

If the ov~rv,eW window is nol visible.. feteb it onlO Ihe sclft'n with Vl:Ew ~ OVEIl\J..Io\\S or
w;lh INSI:.RT
~

To enler the prob'fam code. cI iCKoncc below Ihe window for the n<;!wllrk comment, or. if Y"u have <;(1 "Oi'play witb C"mments", click OnCe h<:Jo" the ,haded area ror nC '1work comment,. YOII ... ill SCe a framed emply ... indo.... You can begin C'IIlering yom PIDIlram 8n)"b= within thi~ ,,'indl.lw. The chapters heJo" sbow you "'hat a LAO e = t path or an FRD IOllie operation looks like.
You program a new
n~N..ori<

" 'ith L'SERT


,"~c-n, In

r J)(iR.\ M U.ME"oiS .

l"1:TI'oORK. Tbe Editor then

eml"ly

Tllc o~'cr\';ewlI arc p~senlcd in a S..-pal1lle window which you can ""dock- at the Mil" of the .-..I ilor window and also relea,., .eain (doubledick in nch c85e on the title bar of lhe oHTview window) .
Program dCmcn l$ catalog The prollnlm clemenl~ call1l,,,,!,' suppon s prog"""unini in LAD and FRO b} pro"idinllthc available graphic el~m~nl5 (Fign~ 3.$). You caD dnlg all program elnn=ts into the proJll1lm windOW u~inlllhc mou;;;:.
In addidon, ;I!;,;UI the block.> already loc.ted In

network behind the curremly selected network.

omine JJlocL conlain~'T. as well as the aln.:ady-programmed multi -iru.hmcc5 and the svail abl~ Jibrarie$. Dy dickina, with Ihe right rna U-le buttoo 00 n block or a bl<><;k I)pc. )'OU cao select wh~Iher the bloch are 10 be ""'rted aocording to Iype ~ntl numbct or accordini 1() Ih~ block family.
Callstru,lurr
'The call struclUre shm,", th~ block Ilicrnrcby ID the cumnt user prog:rnm. You are ,ho"'D the call .:t1V;ronIllI..'Ill of the currenliy ~ned block toge~r with the blocks used.

th~

JJ.4

Pro~rammln~

l\"crn'orkt
FI"u ~ 3.~

You can divide a LAOIFBO pmgram intO networks which each repres~nt a eurnnl p~th or s logie oporul ion . The Editor numbers the nct-

Pro!!"", !':l<m<"" C .tal,,~ fu, LA!) and )"fIll

'""

3.3 PmgraTlltning Code Bloch

You need nO! terminate a hlock wilh a speeial statemem, simply 'lOp making emries. How" ever, you ~a" program a last (empty) n~t"'ork w ith the title "Block End", providing an easily seen v isual end of the block (an adYamage, particularly in the CaSe of ~x~ept ionally long blocks). In the Program Editor, you cat! create new b locks, or open and edit exi,ting blocks w ithout having to change back to lh~ SlMATTC Managcr. J'\etwork templates
JuS\ as you store blocks in a library to reuse

window). A dialog box appears automatically and he re you replace the dummy characters with valid cntrie" Th~ network templat~ is in.wned af1.er the "elccted network.

3.3.5

A ddres . ing

The add",>scs used in th~ pwgram, such as inputs and outputs or bit m"morics, are addressed in absolute or symbolic mode. Absolut e
~~ dr","inl:

them in other progmlll', you also savo network tempTat~' in order to copy th ~m "gain and again in, fur example, other blocks. To savenctwork templatcs, creale a library ~on !aining at least on" S7 pwgram and Iho So"r-ces container. You program the networks that you wanl to use

Absolute addressing reference" addre:;s.,s and block paramet..-n; with the addr~'s Tn and the bitlbytc address. If there arc three red question marb in the network in th ~ p la ce of addressc" and parameters, you must repla ce this character string w ith valid addresses. If there are three black poin1/;, rep1ac~'IIlem is optionaL The Program Editor che~ks that the dala types of the a<ldrcsses and parameters are corr"c!. You ean deactivate somc of these type ebcch (in thc Program Editor under OPTiONS ~ CosTO MIZE. "LADIFBD" tab, "Type ehcek for addrcs>cs" option). Syml>ollc addressing
If you want to use symboli~ names tor globa l
op~>r.mds in incremental programming, these names must already be as,igned to absol ute address", in the Symbol Table. While entering the program with th~ Program Editor, you can call up the Symbol Tab le for cditing w ith OpnoNs ...", S'0-IBOL TAlIL and then you ~an change symbols or cm~r new symbols ,

as templates quite '"normally" in (any) block.


Then you replace the addresses thm are to chang~ with the dummy chara~tcr; %00 to %99 . You can also vary the netwo,k titl e and the network ~omrnem in this way. The dllmmy characters ""placing the addr"sses are p,,,semed in red because a block cann!)! be stored in thi, form , ']'00. is not sib'tlificant b~eause following saving of the network temp!ate(s), th i, block can b e rejected (dose the block without saving). After cnt<;ring the dummy ~baracters, mark th" nelWurk by cl icking on thc network number at top left before the network title . You can also combine severnl n etworks to form one tem plate; hold down the en-I key while you dick on further nctwork numbers. Now sele~t EDIT ~ CREATE NETWORK TEMPLATE. In the dialog box that th~D appears, you Can assign meaningful comm"nt< to the network and all the dummy character. . In 1he next dialog box, you a>sign a name for the n~twork template and you define lhe ,torage location (Sm<l"<'cs container in a library). Tryou want 10 us~ Ihe n etwork tempiat'", open the rele\'ant library in the Program Elements Catalog and th ~n select the desired network templa1e (double-click or drag to the Ed itor

Yon ~~tiv~IC display of the 5)'mbol addre~~e~ w ith VIEW --} D!SPU. Y WTTll ~ SYMBOLIC Rb~I1ESFO.--r,.,T!ON. The menu poim Vrliw ~ DISPLAY ViTTl! ~ SYMBOL INfORMATION provides, for each netv.'ork, a list of the symbol-toabsolute-address assignments for e ach symbol used in the network. Whi le entering the 'ymbois, you can view a list of all the 'ymbols in the symbol table with INSCI(T ~ SYl\-HlOL (0' right mouse click am! INSLRT SYMllOL) and you can then transfer one of the 'ymbob with a click of the mouse. The list i, disphLyed aUlomatically if y"u have sct Vn;.w ~ DISPLAY WITH ~ SThffiOL SELECTIOX

""

'>DolATIC 57 l'roi""m

](" symbol is nOi yet iru;luded in the symbol tIIl*_)OU Can scle<:t EDIT -+ SnlBOl.S. make 1111: a.tgnnICnt 10 the absolute D<i<;lress, and pos.. ~ also assiifl a symbol comment This sym boDIlStocn transferred to the symbol table "'ben
~d;ekOK.

1"lIIli- begins OIl the left JIO"er rail. You selecl the location in the nJlIj! at whieh }'O\I wlnl 10 insen an dement. then you select the program
elnnents you WlInt
I> .... ;tIt

tile COIT<'Sponding function key (for example F2 for a nonnally open (NO) contaCt),

y(RI can a1 edil the symbols in Regi ster "4: so Add~i5 info" in the Detai ls window. Ifthe columns with Ibe symbol and the ,)"nlbol comment .are not disp layed. fetch them by chcking with !be n\lht mou~ butlon on the addrc .. table ~nd
DlSPLA Y COLt.r.o.ll'S (Ol'iOFf).

;. with 'he corresponding bUllon on the function b ar or

;. from the Program Elements CalalOIL (with il<>"5ERT -+ PROGRA.'1 EJ.L\tENTS or VI[w-+
OVEJt\'l.Ews).

If tIK- ProIl'1'P' Editor opens a compiled block. ".:.ani... OUt "decompiling" 10 the LAD or FBD .-etbod of ~pr~ntation. In do1na so. it usel 11K non-<:"il.'CutioorcleVllllt program sectIOns lD .. e offline data management. in order. for anple. 10 ~prncnt symbols . con:unents and jWJ1p labels. Irlhe mrotm""on from the offline data lUllIIagement ,y$1em is mi.sina, the Pr0gram Editor uses ~ub;;titule symbols .

You terminate a rung ....'jth. coil or. bolt .


Most program elements m~t be ISSigned memory locauoD.'i (v.riable~). The eliieSI "'1)' to do this is to rtnt arrange all prognun elements. and then label them.

1'' _

Con tac lS Binary arldIe-sse, ""eh as inputS are scanned u.ioa comacts . The scanned silPla l statcs at"<: combined a, ~ording to th~ ~rmngemem of Ihc comacts in a serial or paral1e11ayoUI.
1at:1

3.3.6

E ditIng LAO Ekmeon

Prollunlmlna In lI:e ner.1 The prn]U1lm CQlUi;;ts of individllll.l LAD de~I.'I arranged in ..,ries or parallel to one aoothl"r. PTopmrnina of a current p;>1h. or

"Current flo,,';;'" through I n",,",,,,Jlly open conif the scanned binary address ha. siiDDl mte '"I"' (the contact is activated) "C"Urrent

Colt,
Si:nJ>1< coil
C~:I

c",,,..,t . . itlo .".,.,;.1 1\.0"",.",


(e.". ncgouonJ
BoUI

"'11b "'I'P1clr.tWy IItfICh<ttl (~.II. set, use<. ~II<'

...... 1"."0<10< jump functioo)

--jNOTj--

S<and:ard boxeo ... "houl EN..'I'''O Ie-.. tim ... ...:! 0.,...,1<, fuDct;om)

: ''" ,
Flilun ). 7

_.......
S PULSE

SIu.dttrd b<to... wttb E/>. ''0 ( .... ari<lllMtic ""'-1

Block bo~ .. (~ ... I"w1ctiI>It block ""U.)

D'm

" 1= 'CDeof LAD Program Elemcn"

.,
in3

.,

eo"

'"0

I:>c~mpl tj;

'"

3_3 Propmmina; Code Block$


" . lwo~k

"

~.rt.

r.~ay

to ' Oy.
<>f

. .,

an

~ ...

pa,u

h~v ..

, . . ~he<l tn .. or."

tn. bal t , "< noy or. r ... dy

o~

u.<> .... l .

- ... u ..

{p -

p.

.....

i."'~ .~.

'Mhultl

110w~ Ihrough a nomtolly c1os~d contoct if Ih", !/Canned binary addn:ss has si lP'ai stale ''0.. (thc eontaCI is nol aClivaled). You can al.o scan slaIUS bi lS or negale the re~ull of the Jollie operation (NOT conlaCl).

Layout

re~t dctions

Colis
Coils an: ,,-~ed to control binary addresses_ ruch as Outputs. A .imple coil Sels the binary add,....SCI when Cu.tn:nl flows in Ihe coil, and rCIICIS it when power no lonaer 110wo. There ace coils with addit ionnllBbels, such a, Sct and RC8Cl coi),. which serve a special fune_ _ lion. You can aIm use coils to control limeTS and counters, cal! blocb witlioul paramelers. execule j umps in the program. and so on_

T he LAP edilor sets ufl a network according to thc main rung principle. Th is is Ihe uppermost branch, which hegins di~tly on Ihe left power .....il and muSt terminate with a coil or 8 bo~. All LAP elemcnts can be localed in Ihi~ nmg. In parallel branchc!l wh ich do not begin On Ihe left power rail. Ihere are somelimes restrictions in the choice of program elemenls. A ddilional n:s,rielions dictate Ihal no LAD elc_ rnenl may be 'shorl-circuited wilh an empty" parallel branch, and thaI no power" may flow IhrouJlh an element from right to left (a parallel branch musl be closed to the branch in which it wu O!"'ned). Any further ru lcl app lying 10 Ih .. layout of special LAD elemcnt~ Ilff discu ssed in tbe rcleva", Chapl<:T5.

Bole.
rc-prcsenl LAD elements with complex functiono. STEP 7 provides standard boxcs of two difkrenl types, w,thm.1l ENIENO mech_ anism (.uch as memory functions, limer and COllmer functions. comparison boxes). and ,"'i lh ENIENO (such as MOVE, arithmelic and malh functions. data type con'crsions). When you call code blocks (FCs. FB s. SfC. and SFBs). LAD allO rcpr-esen15 Ihc tailS as boxes wilh EJ>;IF.NO. LAD al.., provides an "CII1p1y box in wbicb you can CntCr Ihc desircd funClion when programming,
Bo~<:lI

'Vhen LL.ina

bo,,~

as program demenls. you

'" po
po po

program a single box per networi< arrana;c hoxcs in T brancht~ ;n branches thaI Start"t Ihe left power n,i l
arranl!~ boxes in series by switc hing Ihe RNO outPUI of one bo~ 10 the EN input of the follo,,""ing box

:>

SWileh boxes in parallel in b... nc~. on ,he left power rail via its eNO OUlpul

With Ihe arrangemenl of the boxes, you evaluale the signal slates oflhe ENO outputs: if you

'"

3 5lMATIC 57 Program

terminate the UNO outputs "~th a "oil, "pow~ r flows in to th~ "OJI if a ll Ihe boxe-, ha,-e all b~~n p rocessed without errors in the "a,e of ~ri .... con ncelion, or if one of the I ,,-.. es has be..n prox cessed without errors in the cas~ of paran~l "onnection (see also Chapter 15.4 U.ing th~ Binary Re~ulf').
U~menn

.\!lost program clements must be as< igned mem ory iocation, (nriables). The eas iest way 10 do thi s is 10 first ammge all program clem en ts, th~n lahelthcrn .
Hin~ [ )'

fUll ction s

3 .3 . 7

Editin;:; HJD

Pr<>gramminl.: in gener al
T he program consists of indivi dnal progrllDl elem ent. that ar~ connected togcther via th~ b ina ry sign al fl ow to form logic operation, or ncm-'ork s_ You begin programming a lo gI c opcl"ation by sel ecting the programm ing elements on the !eEl of the logic operat ion

You sCan the binary addresse, men as inputs and combine th~ >canned signa l stat es u,ing the binary functions AND. OR an d cx c\usi'-e OR E3Ch binary i~pul of a bo_~ also >can s tn e bi~ary address at the inp ul. The scanning o f an addrc" Can be neg"ted so that ,can 1':>1111 "i -- can be oblained for , lat " , "0" of the address . You can abo Scan smtus bits or th e result ()f a logk operation within a logic

O pCra!lOn .
Sim ple
b"xe~

"
!>

with the functio ll key, (e_ F2 for the Al'-"D function), g_ via thc m enu
(L~ShRT ~ FBI) LA"UUA{;F ELE.'-!~_"rS ~

A NI) B ox) or
!>

You control bmary addrcsses ,,, eh as outputs w ith simple box~, . Simple boxes g~n ~rally have only one input and may have an additional
)ah~L

from thc Program TIlcmcnts Catalog (with INSERT ~ PROGRA.\! J::U::lI.Jr.-rS or


V tEW ~ OVERVIEWS) .

YOll tcnninate a b inary logic opcr"tion in the simp le't case "'~t h an ass ign box .
Binary fu nction.

for controll ing a binary an edg~. controlling timer and C()unt~r addre,se, . calling block> without parameters, cxecuting j umps in the program, aud so O IL
addr~,s _ ~ya)ua!ing

Th~re

are simpk

box~,

}\;jd ftu-",'i<m.
.: ORfuo"ion.

l!~:,l o.<i".--O R

fu,Id;OO

Nega'io>~ or""'D o.nd ,..,sul, of


lli~ logic

"1" ""-'''''''

L L mR L
> .,
""_'">

Slmp!e bo x..
~."""
fl..ct;

8 inary operand

='=c-<l!~

","'=ti""
(;('.<\1",1

--l

I
CO

tltr.... ..00 Ju"'<r t'>noli"""

Counter o p-eraoo

--1

ju,,:p !"n~'w=.
,,,,,,,,or =!to] ",loy, <le_

Complu box
S ~Qdan:I bo,~whh<>u' l'I\! n~O

_ (~,!!.\ir"","~uJ " U"n~ 1"""t;'-"'


Time"- ad<:lress
S 1'\1
S PU LSE

SuotI.,.,r wilt EN_ 'EXO (t.:,: mtbm<.-ti<> f!(...clioo>}

fll<d. "OXO,
(~ IO.

tunc,;"" hlock calls)


DB.m

81
Q

, eo

BCD

= -

"

out,
oul2

f-

in ' in2

,"0

Fil:ur. 3 .9 Exampk, ufFBD PrugnmElement.

3.4 Prognunming Data U I()<;k.

~ o. ~

' E>'

R.,.o"."

". "

1-0

" ",

~,

"

"B u ie u" _ "/II{a u ltl"


fl~ur e

L .
example, you cannot arran ge edge evaluation. and call boxes following a T branch . Any fiorth er rules applying to the layo ut of special F"BD el emen ls are di>c,usse<i in the relevant ehapteTh. When us ing boxe, as program elements, you

3.10 Exampk of an FBD Ketwork in "3.Dimcru;onal" Rep,"s<nt.>tio n

Comple" boxes Compkx boxes represent program elements with compkx funnion. ST EP 7 provides "standard boxes' in f\<.'o version.!:
~

wit hout EKIENO mechilflism (,neh as memory functions, timers an d ~ O\lntcrs, ~omparison boxes) and witb ENIENO (suc h as MOVE. arilhmetic and maTh funed<Jns, data type conversion),

""progrnm a single box pe, netw ork


;>

!>

arrange boxes in T branches in branches thaI stan at the left power rail arrange boxes in .eries by switching the END outpUl of one box to the EN inpUl of the following box
AND or OR boxes via the END output.

If Y<JU call code blocks (Fe s, FBs, SFCs and SFBs), FB D also repre,ents the "all, a, boxes with EN/ENO. FBD also l'ro~ides an "empty box" ill " h ieb you can enter the desired function "'hen pro" gramming LaJout
restri~d o n.

!>

!>

The FB D editor Sets " p a network from le ft to right and from tk top down. f rom 'he Idt, th~ inputS lead to the functions and the outputs exit to Ihe right , A logic opcratio ~ always bas a ''1erminating funct ion" _In il~ ,impl e,! fonn, this is an assignm ent of Ihe result of the logie operation 10 a binary address, With the he lp ofa T branch of a l(}gic o pera tion, you can program funher '"'l cnninating functio~s- ' for a logic operation ("multip le outp,,"'), Following a T bran ch howeve-t, Ihc selection of programmab le el ~ments is ,estricted, for

In Ihe case of boxes switched in >eries. you can control their process ing as a group (see also Chapter 15.4 --Using the Binary Resul1")_ You ev aluate the error mC5sag~S o f tho;.- boxe~ by combining th~ E~O oulpUlS: ANDing of the ENO outpUls is fulfilled if all boxes have been proc essed w ithou t error, and ORing of the ENO output$ is fulfilled if one of the boxes has been proee".d without error,

3.4

Programming Data B loc ks

Chapt"'" 2 .5 "Creating the S7 Program" gives an introducl ion to progT"4m creation and the uS" of the program edi tor. Data b locks are progmmm ed in the same way in LAD and FBD, .'

3 SI).IATIC S7 Prugnun 3.4.1 CTnlTing Data Blocks


t>

You be!,;in block programming by openiD& block. either with a double-click on the block in the project window Qf thc SL\tATIC Manager orb)' "'Iceting FILl:! ...... OPEN in the e,wor, Iftbe block doe s not yet exist , create it as foI1Q"~:
t>

Dala block referencing a user-<iefined dalll \)1'<". or 'ODB of ty~.' Creation as a data block of user dam type; in thiJ; "".e th~ dam .Iruettlrc is used whi"h you h."e declared when prollrAmmil\g Ihe c;:<I!Tespondiog user dam type t:DT.

In the SIMATIC Manager: ,elec t the obje.:t BloeM in th~ lefl-band ponion oftbe proje.:t windvw and crcat~ a new d~ta block with IN snRT - t S7 BLOC,,- ...... DATA BLOCK. YOIl lICe the properties window of the block, SpecifY the number and Typt o f Ihe <illta block on the "G~"1lCTll I Pan r' tab (I Chapler 3.4.2 M Types of Dl\", Bloc~M). Instance DBM and DB o f ~ pc n onJybc "1led iffurn:uon bloc~ FB. S)"S[cm function blocks SFS or user dal~ rypes UD T are present in Ihe blod,: contaioer. You can also enler the ~maining block properties lale!". In Ihc program editor: "'ilh FILE ...... NEW. you get a dia log OOX in which you ~lIn en ter Ih", d<;.;rcd block 'md~r Object name". In the dialog window New data block' which i ! 5ub.'e.:juc nt ly displayed. you arc requested 10 defi~ the ~-pc of data block (s<'C Chapter 3.4.2 Types of Data Blocks"). After clo!inll the dialog box, you can program th" bloc~ contenls.

I>

'Data block referenc ing a functi()T1 bl""k' or In<tancc OS"

Cf(;lIti011 as an instance dala block; hcre, Ih~ data " ruct u<c tbat you h",.. declari when programming \M relevant function block is frnnsfC"TTed_
U$er

Wheo creating a data block on the basil of a data \)'P". you simultaneously defme the u rn on whicb it is based; I.e. the liDT mUil\ already ha>'~ been presIIIlt io the block: ton miner. The S3me applies 10 !heereat;on ofa data block" ilh ""signcd function block.

t>

3.4.3

Hlock WIndows and Vie""

You Cln till out the h~adcr of:> block as you ereIte it or you can add the block propcnk! .t II laler point. You proJOllUIllater addition [0 [he block header in the editor by selecting FILE ... PROPIlRTTfS while the block is opI:D. 3.4.2 Types of Dat a BI""k.

When opeoing a dSla block whon lIrueture is ba<ed 0<1 a user data type or a (5y.le.,,,) funclion block. you will ~ ash"d in the slnndnrd sen ing "hether you ,,-i5b to o pen the data block using the pmgram editor or the application Paramelerization of data blocks'. The parameter " iew prt,ents tbe data nlues arouped thnologically. and permits more con>enien! parameterization (...., Ch.aplcr 2.1.8 ~onj:oring and "'lodif~"U1g Data Addf(;s~s,. The datH ~ie"'s are d~riboo b<:low. The propam editor pmvide:; t"" vic,," for programming (cresling) dMa blocks: ;;. Tbe d eclaration view is used 10 define the llats structure for global daUt bl<.><;n, as "c 11 ~_~ Ihc de fault values. eo You Can handle the online v.luc! in Ihe data
>k

Whcn crcati ng a new data block . you ar ~ requested to defme ito; type, \Vhcn crcat,,,!! using lhc 5lMATIC Manager. you Set the type in the ,eleclion box of Ihe propc"rues window; when creating wilh the program editor. by cU<;king one o f lhe options offered in [he '':'lew dHta blocL " window. A ditre~nltalion i. made hc:tv.ecn tllrH typeS of data block depeoding on their erellion and applition;
I>

".

M Datll block Or Sha~d OS' Creation global data block.; ~ou decla~ the data addre",es wheo programminij: thc dHtn block in this CH.C

u.

Eacb ' - presents a table conlPining the abso.e" 1u1~ data add.... se. in sequence. tM n8Jt>C' and clara 1)-ptS. the initial values aDd corruncnts (Fig_ ~ 3.11). The data >->cw eODtatnS an additional column with the actual 'aluc. If you oprn a data block from Ihe omine data management, you arc provided with Ih~ oftline " '11"10,,, "'nh "hieh you cao edit Ihe d~IH in the pmgrammin g device. !fyou open a data block

'"

3.4 Programming Data Bloch

F j~U T~

3.11 Eumplc or on Orene<:! [)"" 1310";' (Dednration Vie"-")

which i. present in the CPU "s u, ermemory. th~ editor di,p l~y" the online window wi th whi ch you can edit the data val ues on the CPU.

of the user J"t.~ type or from the th~ fundion block.

d~cI "r~tion

of

Offlin e w indow You I,"C the dec laration view for input;; w ith global data b locks You dcdare th~ data addr~sses in th is view; you definc lh~ s~"uencc of data add[\;\S~s. assign a na me and data type to each data address . and Can "dditional1y em er a conuuem. Each data add .. e<s lS ass igned a deb.ult va lu e . This i, Z<'ro. the smallC8l value or empty d~pcnding on the data type . You ca n modify the ddau lt v~ luc in the initia l v alu e col-

The data view additi onally "hows th e ""tual value colwnn. The default values from the initi al vo lue column arc entcred as standard in this co lumn . In the data "jew. YO Ll can enter a d ift" ren! in itial value for the load m emory and thus an act l!ai value for the ",'ork memory (F igure

3.12).
The possibility wh ich exim for assigning indi vidual default value. to ea ch data block is parti cularl y im portant for the data b locks derived fmm a Ll..ier data typ<: or from a function b lock. t'or example, if you generatc severnl instance data blo<.:ks o f a function block, all dala b locks have th~ defau lt value sct in the function b lock . In the data view, you can m>w iT1 dividllally as sign other values to various dam addresses for each in.tan ce .

"=.
The data "dtlrc>se, "nd the d~fauh values are already dcfincd for data blocks which [\f~ derived from a user dam type or from a fundion hlock. They are obtained from the declaration

115

3 SIMATIC S7 Program

view

In the offline win<1ow, y ou roit the ,"'''' in ,~c ofllin.< data ~lOna~<m<,, 1.

In Iho vtiliJ,. "ind<>,". Y"~ monitor the da", in

the CPU'. won: memOlY

I'

U,eHTT --+ SAVE 1<' wri t. ll ,. aotual

val". imo t h< offline dato .

to write tho &rual val ue ;"to the load m em o,),

an" won: memo,),.

'[ ~~efam! va,IU.BT.-.:

..

':~

Initial

~alu"

- lr-~,c,c,C,"C,~.~"C'"~.-'J .. _:I;;:~AO~'C"'.~'C"~.C'"C "


Load memory Wo rk m"mory

OHli n. dato< in the prog ramming davlce

Hgur e 3.12 Data SL o!"a!F wilh Incremental PrognlIrnniIl8

Online w indow You usually usc the on line window to view the actual dam valu~s ;1) \he Ll'er m emory. H(lw_ ever, you C"n also u,e ;t to generate d ata hloch. The initial value column;n the dec laration ,~ew show. \b e init; a l va lu e from the oftlin e data m anagement or thc ini\ia l ,'alue from the load memory if tb~ omine project a'.,oc iated with the CPU program is n ot av ailable _ The acnml value column ;n the dma view d is plays the a~tual value from thc work memory. W ith E VIl' ---> I N T TIAUZE DATA BLOCK you requ~s t the ~d Ltor to re place a ll actual value, hy the in itial values agai n.

defau lt valu e, and th e oaluc in the ''':tual val ue colunm a , the initi al value inlo the omine data
man"g~m~nt.

Kote that the comple te inform "tion ~o n cenl i ng data addresses, such as e.s- lh~ name, is only p resent in the amine data management. 11 i" nx:ommendah lc to also write the d ata bloch g~ llerated in the CPU'. user memory into th~ offline data lIllIllagem ent so th aI data consi, tc ncy is rcl"incd (Chapter 2 .6 .5 "Block Handling" u nde r "D~ta block> offiille/olllin~").

'''ill

3.5

Variables, Constants and

Wh<.-,,! wri \i ng hack with PLC ---> DOWNLOAD. you write the ,"a lu~ in the i1~tui11 ,"i11ue column into the work mem ory_ You arc there fore able 10 use the progmmrning device 10 inilu~ncc \he values of data addres,es during rrogram eXecution. ThO' yaluc in th e ;n itial v alue column is rej ected.
Wh~n w rilin g hack with FlL_ ---> SAYE . you t: write the value in the initia l value ~oJumn "'" the

Data Types
3.5.1 Generul R~mal"l<.~ Con c<'rnin g Variab les

A ,' ariable i, a value with a >pc,:ili e format (Figure 3.13). Simple variable. c o ns ist of aa address (such as input 5 .2) and a data typ;; (su~ h as BOOL for a bi nary value) . The addres" in

'"

3 .5 Variable., Con.."nt. and Dam Types


(Urn, comprise, an addtess identitier (wch as J for input) and an ahsolute stomgc location (such '" 5.2 for byt~ 5, bit 2). You Can also ref_ ~n;nce an addre" or a variables ymbolically by aigning the address a namc (a symbol) in th~ ,ymbo l table.

compon~nt ,, ~Iues

of an array consisting of 30 11'T into the accumulator and furth~r proccss

il). Constants a~ used to pres et variable> to a fIxed value . Th ~ constant is given " spe~ifi~ prefIx depcnding On the data type .

A hi t of data type BOOL is refe rred to a s a binary add,.".,., (or hinll'Y operand). Ad d,..."es comprising one. two or four hy:cs "If vari ~bJ e~ with th~ relevan1 dala type, are called <ii;:i'''/

3 .5.2
Wh~n

Address;n!,: Va riables

opcr"nd,'
Variablcs. whkh you decl are within a b lock. are to a. (block-) loca l variables _ These include the block paramel<:rs. the static and temp orary loc"1 dam . even the dara addresses in global dara b locks . When th ese var i abl e~ are of an e lementary data typc, they cau also be a cces.ed as operan d., (for instane~ s tat i~ lo~a1 data as UJ op~rands, temporary local data as L opcratlds. and data in g loba l da:a b locks as DB operands).
r~ferrcd

ad dressing variables, you may choo.e betwcen absolmc "ddr~ssing and ,yntbolic addres sing
[>

Abso lute addre" ing uses numcri~al addresses beginning with zero for c,,,,h addre,s area. Symbolic addre,sing u.;;es alphanumeric natllCS, which you yourself dcfmc in the symbo l table for gtobal addr~.'es or in the declaration section for block-loe,,1
addr~sses .

[>

Local variahl~<, h owcv~r, ~an "Iso ~ ot complex data typ<> (such as stnlC111res or arrays). Variables wit~ th~,e data type, reqllire m On! than 32 b its . s(' thal \h~y can no longer, for example, be loaded int0 the accumula tor. And for t h~ ,arne reason, they cannot h(: addrC"S,ed with "normal" ' STL <ta\cm~n" . T he!"e are special functions for handling (hese variab les, w ch as the IEC fun~tions, wh ich are pJ"<'widcd "-~ "standard library with STEP 7 (you can generate vari ables of com plex data type in block parametcrs orthe <am~ data type). If variables complex data type contain com pon,,'ms of e lementary data type, the<e componems can be treat ~d as (hough they were separate variables (for example, \lOll ~an load a

Ab so lute addressin!;: of variables Variable. of ckm~'lItary dat a type can be referenc ed by absolnte addresses_ TI,e ab sol ute at!dr~ ss of an input or output is computed from Ihe module Slart addre ss, which you ,ct or had set in the configu",tion table and the type o f s ignal ~onncction OIl \k module_A d istinction is m"de bC lwccn bi nary ~ignal~ and ana log signal<
Bina ry I'ign'l/S

or

A v>0a..u;, """sis" ""d",u and ,1>8 da,~ 'J'P"Hi J~.><>d 'y""'xJ;Cd#y,

01"".

Va_a ble i

A binary signal conta ins one b it of in formal ion. Example, of binary signals are the input signa ls fro m limit ~witchc~, momentary_contacl switches and 'he like whieh lead 10 digital input modules. and output ,ignal. which control lamp', contactors , and the like v ia digi1aloutput
modu l e~_

Ana/"K .l'iKna/s

Add ress .. 081" 1yP'"

Address klenHfier

..

Memof")' location

Fl~ ur.

3.t3 Structure of a VMl.b J~

An analog signa l contains 16 bils of inionnalion . An analog s ignal corresponds to a "~han. ncl", which is mapP"d in th~ con!rol ler as a word (2 by tes) (sec below). Analog input signals (such a< voltages from resi,t,once 1hcrmom~"1~Tll) arc carried to analog input moo uJe<, d igi tized, ant! lllad ~ available to (he controller as 16 information bits. Conversely. 16 bit~ of

J S(/>'tAflC 57 Program

mfonnation can control an indicalOr via an analog output module, where the infomlaaou is cun ,'~ned into an analog value (such as a cur_ rent), T he information width of a signal also c~ sponds to the infonnation width of the "ariabl~ in whieh the signal is slOred and processed . The infonnal ion width ~nd the inlcrprclation (lflb~ informat ion (fo r ;n;;tanc~ the positionsl weight), taken tog~t her. produce the data typo of the variable, Binary signals an: store d in variable, "f data type BOOL analog signals in vaTiable, of data type L'\T. The only determining factor fo' the addres.>ing of variables i~ the information w idth. In STEP 7, th~-re are four w idth" which can be acce".d wilh absolute addressing'
t> t>

the byte containinR the vari able . n ,e addre" iMmifier is supplememed by" B, EX3mplcs;
ill 2 inpm b)1e no. 2

QB 18 Output byte no. 18


VAriables of data type WORD com;;"t of two bytes (a word). They ha>e as absolute addre,s Ihe address idemifl~r and th~ number of the low-order byte of th~ word containing the variabl e, The address idcntiflcr "' s\1pplemented by a \\', Example,'
IW.t Input word no . 4 : cOnla;"'; bytes 4 and 5
contains byle, 20 and 21 Variables uf <.!ata type DWORD consi" offo ur b'1C~ (a doubkword). They have as ahsolute address the ~dd,"ss id~ntifior and Ih e nw nbeI of the lo\\-orJer byte o f the word containing lh~ variab le. Th e address identif,er is S\1pplem~nt.d by a D. Examples:

QW 20 Oulpllt word no . 20;

1 bit

Data type BOOL Data type BYTE or anmh~r dala


type with I; b its

8 bit, 16bit s

t>

DatatYP<'WORDoranothndata
l)'pC w ith 16 bit,

ID g

t>

32 bits

Data type DWORD Or another dala Iype "ith 32 bil'

Input dOllble"ord no. 8: conlains b)~es 8, 9. 10 and 1I Output doubt.word nO. 24: contain, byle' no . 24, 25, 26 and 27

QD

2~

Variable, of data typo BOOL are rdcrenccd , ia an address identifier, a hyte n ",mber, and ~ scp=ted by a dedtnal point - a bit numb ....... Num bering of the byte s begms at zero fo r nch addre,s area, lbe upper limil is CPU-specific. The bils ar<; numbered from I) to 1. Examples: I 1.0 Input bit no. 0 in byte no Output b it no. 4 in byte no. 16

Addr.,ses for the data area include Ihe data b lo~k, Examples :

DB lODBX 2.0 Data bit 2,0 in dnta block DB 10


DB II.DBB 14 D~la byle \ 4 in data bloc\:: DB 11 DB 20 .DBW 20 Data word 20 in dala block DB 20 DB n.DBD 10 Dam doubleword 10 in data block DB 22 Addi'ional in fonnati'", on addressing ' he data area call be fOllnd in ChapIe. 18.2.2 "Acces>ing

Q 16.4

Variabl e, of data type BYTE ha"e as abwlUlc address the address identifier and tt.c number of
QD, 2"

QW24 , OB 24

OW 26 ,
.. 1 07 ." .. ,07 .. 25 OS26 CB27

0= Openmds"
Symbolic addrc"in g of variables SymooJic addressing uscs a name (called a symbol) in place o f an absolute address, You you,selr choose mi.> name. Sueh a name millt begin with a letter aud may comprise up to 24

"I

os

QW2S

F11:IlN 3.1.t
Byte Co ntent! in Woru.; and Double" ",,<is

''"

3. ~

Variables, Con Slan ts and Data Types

characters. A key\vord is nol permissible as " symhoL There is no difference between u pp"r-case and 10wCT-ca,~ leners when <.--nlering a symbol. During the output, Ihe ~ditor applics thc notation defincd d uring declaration oflhc sYInbol. The nam~, Or symbol, must b e ~110C31ed to an absolute addr~s,. A. di st inction " made betwecn glo bal <ymbol8 and symbols thm ar~ local 10 a block G lobal symbo!. You may assi!{T\ names in the symbol tabl e to Ihe fo llowing objccts:
r> r> r> r> r>

leading 'if'. Whcn tb c Edito r cannot distinguish a local symbol from an address, you In ..... t p rece,j(; the symbol wilh a .. #" eharncte r during inpnL Local symbols are available onl y in the pro--gramrning device database (in thc omin e con_ tainer Blocks). Iflhis infonnation is missing on dccmnp ilatin", the Edit"r in~crt.~ a s"bslimtc symbol. Udnll symhol names If you us~ symbolic n ames while pwgramming w ith th~ inc r~menta l Editor. th cy m ll.t have already been alloca ted t o absolute addre.se " YOli also have thc option of cnleriag new symbolic names in the symbol18ble duri ng proj, ram r input , You <:<ill subsequently ~ont;nue program input w ith the new ,ymboli c name ,
TfYO li eon'piic .. "O lireC I~XI file geaerated c.g , [rom LADfFflD blocks . the complete assignnlent o f symbo lic name~ to absolute addresscs is only made avai labl e during the compi b,t ion.

])a13 b locks and codc b lo<:ks Inputs. outputs, peripheral periph<.-"TaJ OUlp"ts mputs and

Memory bi ls, timet> ',nd eo"mer.; User data type5 Variable tables

A g looaJ symbol may also include spaces . special characters and counIty_sp~citk charaelers such a" thc umja,,(. Exceptions to this rule are the characters OOh~-' and Ft'ho' and th~ quotation mark ("). \vllen using symbols contaiJ,ing special ch aractt-rs, you mu.<t put the symbo ls in quotation marks in thc program, In comp iled blocks. th~ STL Ed itnr a lways shows global symbols in quotation mark>.

In the case of arrays. the indivi du al c omponents ar~ a<:cessed via the array name and a 8ubscri pt. for example MS ERI ES[1J for Ihe fi rst compone nt. In L A D and F13 D . the index is a constant INT valuc , Itl :<tructures, caeh sub identi!1er is separated from th e preceding subidentifier by " dc~ imal p"in l> ro r insrance FRAM.E.H EADER .CNUM. Component.< of ",er data lypeS a..., address~d exactly like structures
J)atlllldd~ess~s

You can us c g lobal symbols throughout the p rogram; each such "ymbo l m1.lS l be uniq ue within a program , EditinK imponing and nportinB of glohal symbols ar~ d~scrib~d in Chapter 2 .5 .2 Symbol Table", Btock_local symbols T hc names tbr the local da'a a rc spec ified in the dec laration seelion of th e relevant b lock. These names m ay contain only le n ers, digi's and the unde rline character (no umlauts'). Local "ymbols are valid only within a block. The 8ame symbol (Ihe 83me variab le name) may b e used in " differ.-nt context in another bl ock. The Edil-Or shows local symbols with a

Symbolic addre.sing of data uscs complete ad dre s>ing including the dat;, bk><; k. Example: the data b lm;k with th~ symbolic address /l,-fVALUES com>1ins the variahles MYALUF 1, YiVALUE2 and M TI ME. These variables can b e a,Wr~ssed a, fo llows:
"MVALUE5" . ' 1 \ , = 1"NVALUES".MVAInE 2 " MVAL1.rES" .'1T!Y.E
Pl~ asc refcr to Ch apter I ~,1.2 "Accessing D ata Opcrnnds for further in formation on addressing of data.

'"

3 SIMATIC S7 Program Table 3.4 Divi,ion oftht 0... T)Ipc.

(n bits)

J.!.J

O,tni.w o rD llal)'ptl

Da\a \~ ,\i'llU\a\.e me cn:!.!amris\ics of data ell5enlial1y the repr~>;cnlalion orthe COntenl, of


a variable. and the permissible rangco. STEP 7 provide!! predefined dala types. which you can c<>",bin~ in.o u_= dIt", !ype>O.

You ~an find example. of the d~d"nltion and ust of vanabks of an data \'I'\~$ in I~ hbrn.ri"", "LAO_Book" and " FRO Sook" undenhe progrDm "Data Types" program that yon can download from Ih<: pub lisher's Website (<ee ~ge 8).

The da\a ')"\'ItS lIt avai\ab\t on a ,\oba\ basis

~~~~i&..~~~\.J...\\~~~~ "~";he-;;;;;e"1:llI'"i;:P;:,.
Depending on stru~IU", and application. Ibe data types with STEP 7 are classified as foilows: dallllypu
typeS

3.S,4

EI~mtntary

Dalalpn

f...u.~<u"~~"'<:&.~~(..'"~'"I:t.'\....,,~
a word or a doubleword. Tlble 3.6 mow,; the elementary data type. _For m~IlY data type,. there are tWO con,(8nt r~pr.
sentutions tnal you can use equally (e.g. Tuv\ Elf or Til). The lable contains \1M: minimum value for a dalll type in the upper line and the maximum value in Ih~ lower hne. O llra tioD of eleme ntary da,a types

11o---....."'['<~tttenmry I
I>

> CompLex datil


lj5Cf

data type. :> Parameter types Table 3.4 ~hOW5 the pro~rties of Ih.,. d>.ta Iype das5<'s.
Table 3.5 E.uOlplcs of O.::l.nuion >ad Initial V.luo
, [

Table 3.~ shows some elUlmplcs urthe declara(ion of v8riable. of elementary dala ~s.

""

3 ,5 Variables. Con,tant" a"d Data Types

TabJ~

J 6 O"erview ofElem<:ntary Data T)1>C'


( Widlh) ( 1 bit) (8 b its) (8 bits) (16 bits) Dc,s cription Bit Bxampie for C<>nstJhl Notation
FALSE

tJata 1)l'"

"OOC
BYTE

TRUE
8-bit
()'w
b~xade<'imal

BiI' [6R1Xl, 16#00


BilINiFF, 16/!f1'
Printable chanoclcc, q!:. 'X

number

CHAR

ch ara,tcr (A Se!!)

WO=

16-bithexaJe<lllla.l
tlum bcr

WII16'1oooo,INiOOOll W~l61ifffF, J6!iFFFF 2"OOOO_ooooJII)()(}_ OOOO ""llr l 1111 111 1 Illl

16bil b inary number


Count ,alue. 3 ,let'.de. BCD Two g_hit u(1,igned dccim~l numbc'n;
DWOIW

B II(O,O)
UII(255,25~)

(32 h its)

32-bit he~adecjm. l number

D WJJ16"OOOO_ OOOO, 161iOOOO 0000 DWII 16 t1 frfF]FFF,16li' FHPJFFF


2'iOOOO_0000_ .,_0000_0000

32-bi' binary number


Fuuc Sbit un,ilP'eJ

l ll llll 11 11 LI#(O,O,O,O)

111 1 l ill

dedmal numbers
(16bilS) Fixed.point numocr Fixed.point numbt'f

BiI(255.255.H5,2~5)

32768
~32

767

(32 b il.)
(32 b i!

LII-2 147 ~83 MS t ) lll+2 14 7483 647') '. -I.23 4567E+02 2) in exponential rt'pY'C<rntation

float;ng-poim "umbe"<'

a, de<:iII1al cumbcr
SSTJME
TIME

12 3.4567")

(16 bits)

nme value in S L~lAl'lC format Time


"alu~

SST SST!MEif2 h46m30.


TiP'-24d20h.l 1m23.64 7m. n",lEN24d20b,llm23.&47m. T#--24 .855D4d
nMEII 24g~5 i34d

;4),,,,

(32 biLS)

in lEe fo. -

mat

DI" I ~JO.(JI-O 1 DATf-'1'2168- 12-3 1


TIME 01' DAY

(32 bits)

Time of day

TODJoOO:OO :OO 1L\-lE OF DAY~23 : 5~:59.999

1) "Lit" may be "mtlled ,[the numocc 1> outsld~ tho L"l number rang.
I)

for value r.mg~

>C'C

text

3 SIMATIC S7 Program

Na"", is the identifier for a block-local variable (liT' to 24 chara~t~r', aJphanumcri~ and underscore only). YO ll em er the associated data n'"," in the Type column.
With the cxception orthe temporary local data and h lock parnmeten o f functions. you ~an assign a t> initial vallie to the v"riable,. Use th~ ' yntax suitable for the data type for this PUTpose. Commen fs are optional.

CHAR
A , -arinble wnh data Iype CHAR (character)

r .. seryes one byte. Data typ.- CHAR repuseuts

a 5ingk ehameter in Asc n format. Example: ""N.

Yon can us .. any printable cbaractcr in apo,troph .. , . Some spec ial characters rcquireuse or the notat ion ~hown in Tabl .. 3.7. Example : 'SS' represcnl. a dollar 'ign in ASCI! code.
Tabl. 3.7 Sp<X'ial ChaIl!.ct<,.. fur CHAR CHAR
H~

BOOL, BYTE, WORD, DWORIl, CHAR A variab le of data lype BOOr. ""prc>cDI, a b it valuc (for cxample input I I.O). Variab les with data types BYTE , WORD and DWORD are b it .trings comprising 8, 16 and 32 bit,. respe~ lively. The individual bilS are not cvaluated. Special fon n s of the,e data types are the Bel) numbers and the count ~s l1<ed in c<)IIjundion with counter funCT ions, as well as data type CHAR, which represen ts "" A SCll character.

n...,ription

, "
Sl or $1

17h....,.

4 2 """

Doll.r sign Apostrophe


L in~

SP or Sp SII. or Sr

"00
OC
mJ~.

fel {lf)

No,.. page (rt)

Camaie re"'m (LK)


'hb,,]alo[

S'T '" $t

09."

BCV n~mlx,r,'
BC!) numb<:rs hs'-e no ,pecial identifier. Sim ply enter a BCD number "ith the data typ .. 16# (hexadecimal) and use only digit> 0 to 9.

The (l. IOVE function aUows you to us~ lWO or tom ASCli characters enclosed in apostrophes ~, " sp~'Ciai form of data type Cl lA.R for writin;:: AScn charaCl<:rs in a variable.
T"T

BCD number' occu r in coded processing of time value, and counts and in conjunction wi th conversion functions . D ata tyJ>C S5TTM1, " i, ">cd to specify a time value for 'tarring a timer (.ec below), data type 1611 or C# for ,pe~ifying a count vallie. A C # count value is a BCD nuInber between 000 and ')')') . wh .. rehy the sign is always O.
As a rule , lICD numbers have no sign. In conju nction with the conversion functions. the 'ign of a BCD number is stored in the leflmo>! (h ighe't) decade, so that there is on~ lcss decade for the number. Wilen a BCD numhcr h in a 16-bil w<mllhe sign is in the uppermost Meade. whe",hy only bit position 15 is ",levant. Sign.l1 state "0" IDCan, that the number is po5iti\'e. Si!!ll"i state ,. ," 'tands for a ncgati"" numbcr. The sib'll has no afleet on t.b e comeot\ nf the jod i' idual decade " An cquival .. ot a>signment appli .. s for a 32-bjt word. The availab le value range is 0 to 999 fo r a 16bit BCD number and 0 to '" 9 999 999 for a 32bit number.

A variable w ith data type INT io; ,tored as an iut .'!e, (16-b il tixed-point "umb.. r). Data type L"'T ba.s uo special identifier.
A ,"sriabl .. with data t ype Th'T T"<:"""'-'" one word. The , ignal ,tate, of bi ts 0 to 14 r ep res ~"l the digit p",itioru; of the number; the signal , w e of h it 15 represents lhe si),,'Il (S) . Signal state ""0" mean, that thc numlx:r is po;;itive . sig nal state ' 1"" that il is negati' e, A ne gative num ber i, repre,ell1ed as two', compl.. ment. The permissible number range is

from - 32 767 (7FIT"",)


to -31 768 (8000ocJ. DL "T A va riable v.ith data type DINT is stored a< an int ..",~r (32 -b it fixed_point number) , An int eger "I is stored as a DL T variable wh .. n it .. xceed, 32 767 of falls bJow 32 761> or when the number i, pr~c ed.-d by type id .. ntificr L# .

3.5 Variables, Constants an,1 Data Ty)'('s

Data typ" CHAR

.".

.
,

.
1 0 \
Byte m+1

BCD number, 3

dee~d

ASCI! Cod.

S;gl1

BCD num""r, 7 deeadu


Byte m

Bytem+2

Bytn m+3

"

28127
Sign

24 123

20 [ HI

Om type INT

15 14 ...

D~'" typ"

OINT

3130 ...
1S 1
D~UI

11> 15 _
"'.

d ;;

2302

2 ..2'"1'" ..

... 2'2' 1'1 :


... 0 '"

Iyp" REAL
... 2322

3130 .

Data type S5TIME


15 14

,
... 0

D~"'ty""DATE

'I','"c,'".','''.-,------------,~;'-""~~I '
,

1514 .

,, 'n !)

Data type TIME


3130... .16 15

':: '
'~"I~", .'

30 I5I2 2",...
Data type TIME_Of _DAY

... 6 " " .

"

3130

... 1615 ...

, 0

Sign

3 SIMAnc S1 ProJ!I3:n

A variable with da.~ type DiNT re,erYCS one doublewoml. Th.o: signal <ta.cs of bus 0 to 30 represent .I>e digit posi.ioru; ofrl>e number. ~ sign is s.o;n-ed in bi t 31. Bit 31 is ''0'' for a POSI.ive and "1" for a n.. gati ..... nnmOO. NegallH numbers aN:> stored as two', complement. The number 11l"],:c il
from .,.2 147483647 (7FfF t 'FFF box )
to -214 7 483648 (8000
~J.

A dc-normalized floating-pomt number may be in the followin!! range: LIn 494 x 10- 31 to -1.401 298 )( 10"'"

.. 1.401 198 X I~~ to "'!.l73 494 X ]()_Ja

'0'

REA L
A variable ofdaU-type REAL represents. fra~

n 'e S 7-300 CPLis Cannol ca!cula.e wi.h denarllIali:tffl float ing_point numben. Th e bit pnttern of a denOlmali zed numlxr is in1el"Jlll'tcd ~~ a 1.ero.lfa rcsuh falls w;thin .his ranilc, it is rep resented a. zero. and ,tatu. bit. OV Bnd OS arc ~et (l\crflow).
A \"ariahle of data type REAL consists .nler_ nallyoftrnee components. namely the s'iln. tbe S-bit c~poncru to base 2 0Uld the 23-bit man tina. The sign ma~ assume the '"lItue -0.' (posili,e) 01" , (oe!!a.i,e). Beron" the exponen. i~ stored. I constant value (bias. -I 27) is added 10 it SO that it sbows a "~Iue ... nse of from 0 10 255. Tbe mantissa repre"""IS .he fnoctional portion of tl>.- number. The inteaer ponion or the manti,sa i, ,,01 sa' cd. as it is either always I (in the ca~ ofnonna lized floating-point numbers) o. alway' 0 (in the ea,e of d~'I1<mnal i 7.cd no~t ingpoint tmm~rs). Table 3.8 shows the int er_ IIBI ranl;c ofa domiog- poinl number.

lion. and ;5 ~w..ed liS an-bit flrnning-poim numb<."T. An i ... tllC1" 1~ ,tore<! as a REAL v&ri.ble when you add. decimal poinl.nd II z~-ro.

In exponc:rJ! ",pret:ntalioJ!, you can prcde tbe or " E" with an imeger number or frlle.ion ",ilh Seven relevant digil$ and a sign. The diglls that follow the "e" or "F' reprcsem the exp<>nent to b .. sc 10. STEP 7 handle. the conversion orthe REAL variabl.. into the internal representati on of a floating_point nnm""'.
~e"

REAL variables are divid ed ;nt" numbers. which can be represented witb comple.e aCeurney (''nonnah1.w noating-pointnumbers) and thos.e witb limited accuracy ("!lenOT\lllilind" floaTing-po.ot numbers).
The ,..lac range ofa nonnalizcd fl""tinapoin. number lies between, 3.402 823 X 10-l8. 0 - 1.1 15494 X lO-l8

SHL\l
A \"ariablewith dara I)'pt: S5TIME is used in the bB~IC iani'Ja!!C"S STL, LAD and FBD to ~et tbe Slil.1ATIC timers. It n::ser.o:.I one l6-bit word with I + ] decades. The lime i, spcciJied in bours. minuteii. sccond.$

'"
i

and milliseconds. STEP 7 handles convc ... ion


in to imernal repre5enta.ion. Internal
1'q)1l'$C11-

1.17S 494 X 10 U to -30402 823 X 10-;8

Tabl .. 3.M Ronge Limi" of a Floatini'Poilll Numboc r Sign F ponent ....


Mano.>:I

Dc..::ripuotl
1'01 " '~hd IOooti"".po"" nurnl>er - infmitc Po.ili,. _li,,~d foatlnll _poinl oumber 1'o.ith-e don:or!n.l,,'ed tloatina-poun number
~

0 0 0 0

'" '"

0 0 0 0 I ... 2S4

..

Not equal to 0

. 2~4

""',
0 0

Noc cqual 100

,=
II'"'pli"" dcDomIahzed floatm&-poinl number 1\'pri'" nonnati2ed fioaUJIa-point Dumber
infinite

1'01 equal In 0

Arb",..f")' Not equ.al to (I

'" '"
'"

1\Ot . ,-..ljd floa,ina-poinl IIUml=

3.5 Variables. Constants and Data Type,

talion is a, BCD numher in th e rang~ ()()() to 999 . Th .. tim e interval can a>sum.. the follow ing v"lu~s; 10 m. (OOO() ), 100 ms (0001), I < (0010). and 10 s (0011 ) . The duration is the product oftim~ interval and time value. Examples; S5TIMEII'500ms S5T#2h46m 30. DATE A va,iable with data (ypc DATE is stored in a word as an un< igned d_po int n um~r. The ~ont~'T1t' of th .. variabl.. correspond to tae num ber of days since 0 I .0 1 ,1990 . I ts repres~lHnti o n shows the year, month and day, separated from on~ another by a hyphen. Example" (- 005 0t,eJ (- 3999 h< . J

a decima l point, may be omitted


E ~ample"

TIME at' DAY#OO:OO :OO (- OOOO_ODOO b,,) TOD#23:5 9: 59.999 (- 0526_ 5BFFn.:,)

3.5.5

Comple:.

D~ta

Types

STEP 7 de fines the following Four complex da!a type s '


t> t>

DATE

A~ D

TlM r

t"". .

Da! .. and lim e (BCD-coded)

STRING Lnaraeter string with up to 254

Chaf3Cl~TS

DATE#1990-D 1_0 1 0 #2168-12 -31


Tll\lE

(- OODOj,e, ) ( = FF62 tcx)

> ARRAY A rray variab le (combination of variables of the sam e type)


t>

STRUC T Stnleture variable (~ombit1atioll of variables of d i{ferct1l types)

A variable wilh dala type TIME reserves on~ doublewo rd, Its representalion contain, the ;tlfommtion for day s (d) , hO UTS (b), min u~es (m) , ,eeond, ) and mi ll i, cc o'M d;; (ms). wherehy individual items of this in fonnmion may be omiucd . Th e contents o f the "ariab le are interpreted in mi llisecond. (ms) and .,ore<! as a signed 32bit fixed- poim number Examp les: TLMT.!l24d20h3 1m23s64 7ms (- 7H'F_ FFFF h<> ) TlM Ei/Om < (- ()()()O _ OOOO~e,J T#---24d20h 31 m23s64gms (- 8()(I(:U )()o)I\oxl
A "decimal r~'Pr~,untat ion" is also possible for

Tk data type, arc pre-deli ned, with me length o f the data type STRTKG (characwr stting) and the combination and size of (he data tyre' A RR.".Y and STRUCT (s!r.uolUre) being dd" w(i r.y (he US~T, You can declare variables of complex dma types only in global dam b tock . in instan~e data b locks, a s temporary local data or as b lod<
p a r amet ~r s

Vari ahle, of comp lex data types ~an only be applied at b lock parameters a. complet.. variable., There are TEC functions for proce"ing variah les of data types DT and STRTN(,~ e ,g. extract ion o f the d"tc an d conversion to the DATE rcprcscnUl ~ion or comhining two charactcr strin g' to one variab le. Thes~ me functions are load able standard FC b locks that you ca" find in the Stan dard Ubmry under the lEe Hmclio" Blocks program. DATE_ A;\'T) _ lTME The data typc DATF._ AND_TIME represents a tim e cons isting of the date and the time of day. Yon can also us e the abbrn ia tion DT in place o f DATE ANn TTM'E. The individua l componems of a DT variable are A Se n coded (Figure), 16).

TIME. e.g. T IMEII2.25h or Tlt2,25h. bM mpies: TlME#O ,Oh T IME#24 .l!55 134d
TarE_O t' _DAY

(- OOOO_OOOOt,.,,,l
(- 7FFF JFF Fh)

A variable of data type TIME_OF_DAY rCSC1"\'es one doubluword . It contains thu n~lln ber of milli s~~ond,; since th " d ay bcg,m (O:OD o 'clock) in the form of an uns igned fixcd_poim Ilumbcr. I!s r.... pre'emation contai ns the information for hours, m inu tes and s econds, "~'Pa rated by a eol0l1 The m illiseconds, which follow the second, and a", <epa rated from them by

125

3 SIMATlC S7

PrO~'Tam

Tabl~ 3 .~

lOxampl or the Dcda"'tion of DT \ 'mable< ~n d STRL'IG Va".hk,

STRll'OG
The dat. type STR Ih"G represents a character ~haracten;. Yo" .pecify the maximum p<.:rmissib lc numlx.'T of character< in square bmckcts foHo"ing the keyword STRING

.tring consisting of up to 25 4

If th e initial Of pre-assig ned value is ,hortCT than the declar.u maxinmm lenglh . (he remaining charactCT localion, life not reserved. \Vhen a ,'ariahl~ of data type STRING lS post- proonly the currently re.,erved chilra~t~ r locations are taken into consid~ration. It i, abo
~~>sed.

pos~i blc

w ddin~ an empty string" a~ the in i_

Th ig speci fication ~"n abo be omitte<:l; the Edi(or th~n uses" kngm of 2$4 byICs. In (he ca:;c of function , FCs. th ~ Ed itor doe, not permit specification of the !cnh'lh or it demand:; me standard length of 254. 1\ variabk of d"T~ type S TRI NG oc~upks I\l/() byt~s more of memory than th~ d,.,darcd maximum I~ngtb..
Prc-ass;gnm~nt i, ~aniod OUt wilh ASCllcoded characters be(ween single invcflcd com_ mas or w im a prdixed dollar , ign in th~ ca<~ of cenain characters (see data typ~ CHAR)

tial value . Figure 3. t 6 show, the stntCl<l re o f a STRTI\G variable.

Data type ARR."..Y r~pres ~nt' an array or fidd compn$;ng a ftJ<td number of elements of the same data rypc . You
,p~ cify

brack~l'
in; (i~!

the range offield indices in , quare following the data typ" ARRAY. The ,alu c (lU 1he le n must be less than Of

o.ta format DT
8;'('~

a.too form8t STRING

Yur
Month

o bi$ 99
1 bis 12 1 bi$31 O bis 23 Ob is 59 Obis 59 Obis 999

B),".e

Maxlmurl l<>nglh AC".llall.. ""th tstcltua01e-

Byte n+1

8 y"" n+1
By:e n+2 Byte n+3

',m "
Maximum leflgllT

Byte ..,.2

0"
Hc ur

..

Byte n+3

2r..d ::I>ar;ocer

I"e,~~

n+4

Minute Second

Byte ...
Byte n.m+1

..
mrn <;haracte r

Byte 0+5

~yte n+6
j3YteI1+7

"'

I Wee kday

...

W""k<]ay _ from 1 - Sunday to 7 - S"tl",hy

Flgu rc 3.16 Structure of . DT and a STR NG \"aria":"

'"

3.5 Variablell. Constant, lIN! lla.1.& l'ypes

Nam. MOA". v.1.


WO
Re~h

Typo

Inilla l V.lu<
0.4. I~. II

Comrnoms

ARRAY[l .24 ) RIOAL ARRAY]-I0,.101 TIlI.fE OF_DAY ARRAY(1. 14.1. 4)


OW

0.6. 3.0)

Amoy ,-ari.ble with 24 REA L clemenTs

21 (TODII01UO:OO)
%(1...-0)

Ton arno.y ,,~'h 21 d""''-""li


T,,"O-<hmcn..ional..moy with 96 okmC"D1i

"'"'.

ARRAY fl .V.AI CHAR

2 (...).1 (-b")

Th'o-d;mom;onal ",.,..y with 4 element.

equal 10 the final value on the righl. BOlh indiC<;~ are TNT numbers in the NI"lIc - 32.7i>R to +32.767. A field can lIa'., up !O 6 dimensions .,ach of " ,IIO!!e I imi1S are separated by D= 1 .

ter ir Ihc bloc k parameter is or Ihe ... me data I)'pe: as the components.

Th., datD Iype of the individual field componems i. located in the line under the da,a l}-peARRAY. All dDta Iype. c~CCpt ARRAY are per mi . sible: it can also be a use r data Iype,

If lhe indi ~id'-'3.1 ficld compom:lIls ..,.., of elemenlary data types. you can process them ""~th "norma\"' LAD or fBD functions.
A field componenl is IIcresscd will> lhe field name ami an index in square bracke ls. The ind ~l( is a tiJ<ed value in LAD!ll1d FBD and ~an DOl be moditied al rumim~ (no variable index. ins ponible).

PNt_as,<lgnment
AI IIIe declanttion SUllie, yOll can pre_a"' gn values 10 ;ndi\-id'-'3.1 field components (nol as 1 block pIIr.rnle-ter in rollClioD. as an i",ool pantmeler in a fun<:tion bl""k or as _ lemporary variable). The d ata Iype of the pre.assignment value must match the dala Iype O!"lhc !ic!d.
You do not require to preassign ull field com ponenls: if Ihe nlImher of preassianment VIII ues is less than the number offield components, onl), Ihe fi.,;1 componen1~ liN pn."-".sil!l1ed. The number of preassignment vMlu<:s musl 1>01 he ~atcr than !he number of fie ld COmpoD~nlS. The p,.., .... ssignment values are each Separaled by a eomma. Multiple pre-assignme!l1 with Ihe SlIme vlIlue, is specified wilhin round brockelS w;lh a preceding rcp<: lilion faCtOf.

Mlllrl-dim"n.<irma/ jidd< or arrays


Fields can have up 10 6 dimetlJiions_ Multi dimcn~'onal fields are analogou~ loone-<lim",,sional tields. At the d<,.~laralion stage. the tanges of the dimcn,;<ms ate written in sqUIITC brackets, each separated b)' ~ comma , Structllre

or the variables

An ARRAY variable always ix"n! at a word boundary. that is. at a bytc ",ill> an e veo address. ARRAY ,ariabl"" oceup)' the mcmO<y up to the next ","ord boundary.
Component. of data t)'pe nOOL hellin in lhe leaST silP'i lkanl hil; cOmponenlll ...r data type BYTE and CHAR begin in Ih~ righth.,nd byte. Th~ individual componenlS are lisled in order. In multi-dimcnsional fields. Ihc compotlcnlS ..,.., slored line_wise (dimerulionwise) statting "lib Ihe first dimension. With btl IUld byte componcnll. a new dimens;,," always 5t;u"\S in the neXT byte. and "ilh componenls of other data type new dimen.ion alwlI)'$ starts in Ihe nexl word (;n lh~ nex, even byt~),

Application
You can appl)' a field as a complele variable al b lock panmCICN of data type ARRAY with Il>e same Structure or al a block panuneu,r of data Iype A.."-"Y. F O'f example. you can copy lh<o conlentS of a field vanable usinSthe .~ystem func_ tiun SFC 10 BLKMOV. You can also specify individuallielu components at a block p"ntmc-

3 SIMATlC $7 Pn>gnun Ta bl .. J.1I hJ.ampl .. ofD""lariul! .


Name MotC",u
T,~ ~

1,,111. 1V.lut
FALSE

'''U~

""

Off

0.1.)'

"''''' '00'
,,~

TI<U,
S5TL\IE ~ Ss

SSTI\IJ:

maxSpu<I

END_ST RUCT

"'00

C,mmnl Simple ,lnI<:tun: ,~able with 4 componmb Vto:iAbk :-ll>ICont.Dn oftyl'< BOOL Van.ble Mo,cont.Dff of typ: BOOL Van.ble )o.lo.co ~'- Delay of type SSnM E V"".bk :\lo!Cont_ m,,~SP<'e<l of type lNT

STR UCT STRUCT represeD~' data SUUC lun: oomiSling of II. fixed number of components Ihal can each be ofa diff=1 dna I)~.
You specity the individual structure ~ompo "ents aDd their cia", 1)'}lC5 under the ]inc with lhe variable name and the key"ord STRUCT. All .lat. typel' can be used including othet siruciures,
Th~ d~ta ~

$m<efllrc of t~e '"Qrillble~

A STRUCT ,'mabIe alwlYS bc:iW II word boundary. thaI is. at a byte with an eH1' addre:Js; following thi;" the indi"idlUll components are ~8!<:<I m the memory in the order of tltcir dedllltiOn. STRUCT "lriab!C!$ o<;cupY Ibe memory up to the oe't word bowldary

Componcrm of data tylX BOOL bellin in Ihe least signifkam bit; components of data type BYTE and CHAR begin in the right-hand byte Components of other data t)lpl:s be:gm 8t a word boundary.
A nested structure is a strotture a, a component ofanother stroclUn'. A nesting depth of up to 6 ,tructures is possib le. All componenlS can be: accessed indi'~dually with "normal" LAD or fBD functions pr",~ded tbey .re of elementary data type_ The individual names arc eac:h ,cpa-

At the declaration stage, you Can ~-l5sign values 10 the individual structure componrnl$ (nol.., a blo<;k paramcterm a function. as an to
(lut parameter in II funnion blOf;k or (IS a temporary variable). The data type. of the pre-assign. ment "alues must match the cia ... types of the components.

nlted by dOL

3. 5.6

Pa rameter T~l'"

Application
You can apply a comple,e variable at block parameters ofd.ta type STRUCTwith the same Sln lctull' or 8t a block parameter of data Iype ANY. For example, you can copy the contents ofa STR Ucr variable with the syst ~m function SFC 20 RLKMOY. Yo" can a lso speetly an indIVidual smlCture component at a block parameter if the block parameter is of the nme data Iype., Ihe componem.
If the individual stru= eomponeDts Ire of elementary data type':!l. you can Pf'X~ lbem witb -normal" LAO or- FBD functions. A JtnJCtUre oomponmt IS accessed ,,~th the nrw:tUfC name and the component name separaIl:<! by. dot .

Para.nmerrypes are data I)~s forblock paramo etCI"$ (Table 3.12). The Icnt.h s~ifications in Ihe Tahle refer to the memory teuircments for block parameters fOf function block!. You can abo use TllitR and COUNTER in the symt>ol table as data I)lpI:S for timers aud counters.
3.5.1
Unr Data Type,

A uscr data type (UDn corresponds to. S\nICnne (cOl::lb:rwion of COmpoo~'1l1ll of IIDY data ,ype) "ith global "wdity. You can U$C a USC1' data type ifa data occun fteuenlly in your prop;un or you WIlDt \0 ISStgn I name to _ data stntcture.

UDTs have global validity; i.e .. once dec lared. they Can be "sed in all blocks. UDTs can be

3.5 Variables, Constants and Data Type" Table 3, 12

OnTvi~w

of P.""n.,., Typo,

addrc ssed symbolically; you as,ign the absolute address in the symhol tab le, The data type of'a UDT (in the symbol table) is identical w ith the absolute address. If you want to give a varia ble the data ,(rucrnrc ddincd in the UDT assign the 001' to il at declaration like a ''normal'' data typc , Thc 001' can be abso lu\ely addre,sed (UDT 0 to UDT 65,535) or symbolically addressed. You can also define a UDT for an entire claw type. When progrmnmins the dala block. you ",sign this UDT to the block as a dala ,tNeN,." The example "Mes:lag~ l'rame Data" in Chapter 24, 3 "'Bricf Description of the "Message Frame E:<ample'''' ,hows yon how 10 work wilh user data types , Creating (lOTs You can create a user data type usi"g th~ SIl\1AflC Manag~r or also the program edifor:
to>
L>

n",n\>ct (tM~ ab,olute a<klres8 UDTn) under "Namc" You Can also enter the other block attributes later. In the program editor: use FILE -) NIlW to obtain a Jialog bo:< in whieh you can enter the dcsired data type (the absolute address UDTn) under "Obj~C( namc".

You can fill in the block header immedia\~ l y when c1'cating the data typ~, Or enter the auribut~' later. With tbe data lype open. you can program subsequent e:<ten,ions in the program ~Jitor "sing FILE .... PROPIl~T!ES .
A double-click on data type UDT" in the SIi\1ATlC Manager opens a dcclantlion table Ihat looks exa~ tly like the declaration lahle of a data block. A lroT is programmed in e xactly the same way as a dmn b lock, with individual lines [or Name, Type. Initial value and Com menK The only diffcn:ncc is lhal .witching to the data view is nO! possihle. (With a UllT, you do not create any variables but only a collection of dala type,; for thi, reason, there can be no aClu.a1 "alue, here),

In the STh-fATIC Manager: select the Blocks object in the 1<:1, pan of the proj en window, and create a new UDT ",ing iNShRT"'" S7 BLOCK ..... DATA T....PL You an: th~-n provided with the attribute, window of the data type . On the "General _ Pan I" tab, emerthe

The initial va lue, you program in the UDT a", tra1)sf~11'ed to \h~ variables 3\ dec laration.

Bas~Functio",

Basic Functions

Thi, OIeClion of the book describe. !bose functions of the LAD and FBD proi"'TDIDinS lang uages which r~fl'sent a ~~rtlIin '"basic functionality", The,e funclion~ s ilo'" you to pro gr.lln a PLC on the basis of contactor or relay
~ontrols.

In a ladder diagram (LAD), Ille onang:erocnt of the COntactS in H r ics and para Ud cirelli., detemurt<:5 the combiru.Di\ of binary sig""l s-.te5. In a function block diasnm(FBD), boxes analoi\Olli to d.'Ctronic $witchtllg system, repfl" $CDtthe b oolean fu nction s AKD and OR. TI,e mrmory functions hold Onto an RLO >0 that it can, for example. be scanned and processed further in another ~ oflh., program_ 'Ote mo" e fUl\ crio ns arc used 10 ",,,,chanKc the values of individual opcran<b md "ariablo:< or 10 copy entire dala areas.
The timing relay. in comactQl" control syslenu arc timers in prosrammahle controllers. The time!'> integrated in the CPU allow you, for uan'plc. to proa:ram waiting and monilOrinS ti mes.

In ChapteT 5 Ml\.femory FunclionC you ",ill fmd .. programming e:otample for the binary lo~k o!><,,,,tions and memory functions. and in Chapter 8 "CounterJ", an example for lime!'!; and COunters. In both oasts, Ih e e:otumplc is in all FC function without block pflnimeleo_ You will find the same examples is function bloc"" (FBs) with block parameters in Chapter I~ "'Block Parameters"'.

,,'"

Bina ry Logi~ O Pf nllons Stnes and parallel circuits (LAD), AND, OR and exclusive OR functions (FBD): negauon: lakino: account o f the sensor
M~mory ru nelions LAD coil!;; FBD hollOt'; midline outpuu; edge (\"iuauOl1; cOII~eyor bel! example

Finally. the co un lers can count up twd down in Ihe range 0 to 999. This seclion of the book describes the funenon. (or tbe oJX:r .. nd are'" for inputs, OUtputs. and memory bits_ Inputs and outputs arc the link 10 the process or plant. The memory hi" corre_ 'pond 10 a""iliary con!aclOrs wh ich <Ior( b inary S\a{C~_ The subsequetl\ sections or thc book describe the relDllinUlIl OJl'CnIld 8m1<, on whIch you can .Iso u"., binary lo~k Essen_ tially. these are the data bilS in global data bloch as w(l1 as Ihe lemporary and S1ali~ local data hits.

,
,

"IOH funellons 1'>IO VE box, system !'unctions for IDO\ ing

do.
Tim ~n

S1.artmg 5 different kinds of timer. resetnng and s.eannini I timer. IEC liIn.ers

Counton Setlwg a coumer, up md down counlin&; resetting and .scannmg a counter, lEe cOunters; fud eXlllnpic

''0

4 Binary Logic Operations

Binary Logic Operations

4.1

Series a nd Parallel Circ uits (LAD)

Binary signal state< are combineu in LAD through series and paralle l connection of contacts, Series connection corresponus to an AND function anu parallel cOllllec ti on to an OR function. You use lhc COntacts to check the signal states of the following b inary operands:
t> t> t> to>
I> I>

ically a_ possible to "contact c losed". " power flowing", and "coil energized" , If "power" i, flowing al B point in the ladder diagram, this moans thlll the bit logic combination applies up to this point ; the result of the logic operati"" (R LO) is " I ", If "power" is 110wing in a single coil. the coil i< encrgi~cd: the asso<;iated b inary openmd then carries signal state T.

Input and output bits, Tim"", and counters Global data bilS

m~mory

bils

LAD has tWO kinds of eonta~t1; for scanning bit operands: the NO contact and tbe NC contact,

Tcmporary Io<;al dala bit.> Static local data bits Starns bits (evaluation of calculation suits)
r~-

,,0 <on'.ct
'-';C contao.

Bin ary operand

- I I If-Binary opeI';md

-I.1f--

You can reference an operand via a contact using eith~'T an absolute or a symbolic addr~'Ss, LAD uscs onlyNO comacts (scan for signal state " 1") and 'NC contact'; (scan for signal stme "IT) ,
A rung may consist of a single ~omaCl, but it rru,y also consist o f a large number of contact. cmmected togethe,. A rung must always b<: terminated, for example witb a coil Thc coil controls B binary operand with tbe RLO (the "power flow") of the rung .

N ormull}' open (NO) contact


A normally open contact ~OtTe5pon u~ \0 a "",an for signal <late" I ". If thc s~anned binary operand has signal , ta te "I ". the NO contact is acti""ted, so it closes and "power flows" ,

The example, shown in this chapter ~a n be' found in fun cti on blo<;k FB 104 of the "B a, ic Functions" program in the "LA L) _ Hook" library that you can download from the publisher's Website (_ee page 8). For incremental programming, you w ill find clemen\s for binary logic operations in the Program El~ment Catalog (with VLEW -4 OVERVlfWS lCtrl -KJ or with I~SERT -4 PROGRAM ELEML'<TS) under "Bit Logic" .
th~

The cxample in Figure 4.1 (l~ft side) s hows sensor Sl conneClcd to input I 1.0 and scanned by an NO COntact, If sensor SI is open, input I 1.0 is "0" and no pow~r flows through the NO contact. Contactor KI. controlled by output Q 4.0, does not ,witch on . If sensor S I is now activated, input I 1.0 ha< signal statc "T', Power flows from tbe left pow~r rail through the NO contact into the coil, and ~onta~tor K I, which is conne~ted to output Q 4,0. is aClivated ,
Th ~ 'NO contact ",ans the input for s ignal state "1" and th~n c1o'e~. regardless of whcthcr the sensOr al the input is an NO or NC contact.

4.L.1

1"0 C ontac t and /li e Contact

/Ii ormally closed (/liC) con tMct

In order to expla in the bit logic combinations in a ladder diagram, we will refer below a, graph-

Power flows through an NC contact if the binary operand ha, thc signal state "0"', If tbe

'"

4 Binary Logic Operatiolt'l

Mode of opfrat1o . of tliO contact

,,<>do of &!l .,.tion of ~C contact

,I
"
' 0'

,
" '"

SM''''

octivat.d

,I
"
'0'

--

,
T

,, ~

oc Wa'~d

"

~H-r~
"
Figure
~ .I

r-w-r}- H+--ri- Ht-r}"


" '
~

'0'

'"

' 0

NO Con",", and r--C Contoc", SCt to "I ". In all otber case" no pmvcr flows and tile (Jpcrand Coill is reset to "0"", "C"twork 2 shows a serie, circuit w ith one NC contact. Power tlows through an NC contact if the associated opcmnd bas signal state " 0" (that is. (he NC contact is not activated). $0 jXlwer on ly I1,JWs thmugb the ,erie, circuit in the e xampl~ if the operand ConltlCt4 has signal state "I"" and the operand ConmcI5 has .i g-nal >!ate "0""

signal state is "I ", an NC cOma" "open." and the now ofp<)W"," i, interrupted. !n the example in Figure 4.1 (right 'ide), power tlow" through the NC ~ontac t if sensor S2 is not dosed (input I I , I has , ignal ,tate 'il"). Power al.o flows in the coil and energizes comaClC>r KlatoutpuI Q 4 ,1 .
Ifs~nsor S2 i, now actiwted. input! 1,1 has ,ig nal state ' T ' and t~ N'C contact opens. Thc pow~r flow is intcrrupted and contsctC>r Kl relcases.

-l .1.3

Parallel Cireui"

The NC comact checks the input for Slt:llal stale "0" and then ..,mains closed, regardless of whelher the senSOr at thc inPUt is an NO or NC contact (also see Chapter 4 .3 "Taking Acc ount of the Sensor Type") ,

\hen tv.o or more contacts are arran~ ed one under the olhe" we refer to a parallel d rcuit Power flow, through a parallel circuit if one of the contacts is closed. Figu:-e ".2 shows a typi ca l parallcl circuit. In n et" ork 3, the parallel circuit consists of three contac!>: any binary operands can be scanned. All cont~cts are NO contact" If one o f the opera.nds has signal 5!atC " I", power flows through th . rung t(J lh ~ coiL The operand ~oDrrollNi by lb. toil is $elto "I"", If all operands s<:ann cd haw s ignal statc "0", no power flows to the coil and the operand Coil3;s resct to "0" Ne!" ork 4 shows a parallel circuil w ith one NC contatt . Power flows througb an NC contao if the associated (Jp~ra"d is "0", that is , p<)wer flo"s through Ihe series circuil in the example if the (Jp orand Contacr4 has signal stalC "1" m the operand ConractJ has s ignal , tate "0".

4.1.2

Series Circuit'

Tn series circuits , two or more contact, are connected in series , Power n(J"s through a series circuit when all C<lnlacts are closed. Figure 4.2 shows a typical ,erie, circuit. In netwMk I, the seri es circuit bas ,hr.econtac,,; any binary ()per~nd, can be scanned. All c(}mllcts are N O conIac\>, If the aswc iatNi operand, all have signal Slate "I " (that is. if the '\10 COntaCtS are activated), p<)\\er flows through the rung to the coil. The operand controlled by the coil is

4.1 Snies and Parallel Circuits (LAO)

SerI....ntctlop

H H

NlICWOl1< 1 tact1

""".~

II

"""~,

II

CoO'

( }--I

C.",.,,,
Coo_",

"""~,

I I I I I I I I Cl

I I

Coltl Nelwork 2 tllC14 Contaclt5

f1

C." ( }--I

Contact4 ContactS

I I

COO,

,....n .,.on._
No...,.' C.-,

"""_
Contact3 N,twork .. Contact4

""" )

~,

I I I I I I

I I I I

Coo.",

Contact3 Colt3

I J~t5 I

CO"

( }--I

Contact4

ContaC1S

co.

I I

LAD. you can ,I..., program a brancb in l~ middle or lhe nmll (for an e~ample. see figure 4.3 network 8). You thell gel a jXlralid brallch tliat does Ilot begin at the left power rail. u~ of LAD proifDm elements i. restricted to thi s parallel branch: your altention i, drawn to this in the rcl~V8nt chapters.
An open" paralle l circuil is called a Tbrallch.

Co nn fctlng se ries cin:u; ts in PUlIUC'

Instead of COD lac IS. you can also alTllngo smell eircuils one under the other. fiSIlre 4.3 , hows two examples. In network S. power flows inl.O the coil if Contact! and Cmi/act] 8r.:= clo~d or if Ccmlllcd and Conf(J,"f4 Me closed. In the lower rung (~etwork 6), power flows if ContactS or Con/ac/(j alld Con/oc/ l or Contoct() are dosed.
CCl nnr(tinK pa raUtl clrcultl In urltll

4. 1.4

Combln.t1nns of Binary Logk


Optr.lio n~

You can combine series and parallel circuitS. fOT example. by RlTllnginll several series circu!ls in parallel or several pan.llel circuits in s",nd. You can ~ombine series and parallel circuits even when both types are complex in nnNre (f igure 4.3).

Instead of (ontacts. you can also amonie parallel dftuits in series. figw-e 4.3 shows twO examplle"5. In net\\OTk 7. power flows into the coil if dther ComClctl or Con/CleO and eilher Confaef] or Comact4 ..re closed. To ollow power to flow in the lower e.umple (network 8), COlI/aefS. ContCIctO and either COlllact6 or COli/aeO must be clostd.

.. Binaty tA&ic Opennionll

P .-.JId "' ..,110.


N_ _ 5

~h.r leo

"""n.."Io

,
CO.

t""'
-~.

I ."".on I

"""'"'"

~r- I
"""""' I

( )-----1

"""N_....k7

"""""' """"'" I

"'" )-----1
,

Strlt. a .... dom ..r ... ~ <UMflIoD.

II""' I Con~r4 -_. fl'" I ~: I Ii"


Co-_
4. 1.5 l\"l'11.a,in& Ihe RlMIult or,he Logic Ope rallo n
The l\"OT COnlacl llfgaleS the RLO. You can use this COOIaCI. for c:ltample. 10 rv.n a HTles cir<;;1it negated 10 a coil (Figure 4.4 NfI"oR: 9). Po"cr

CoO'

( )-----1

CcWIO

( )-----1

4.2

Binary' Logic Operations (F BO)

will then only now in'o ,he cOil if wrc is DO JIO""cr in the r-:OT contact. tha i is. if ei!her COnlaN} <IT Conlocl2 is o~n (Ke the FifUre in the adjaCC1lt pulse diagram).

In fBD. the logIC opennions performed on binary signal stalO'S take.1>c form of Al\"D. OR and Exclusi.-e OR functions. The operands wbose signal S13IO'S you wanlto scan and combine "'" wTineo a1 tbe inputs oftbesc functions. You can SCan the following operand.:
:> :>
I> I> I>
~

The same applil:;l by analogy for nel"ort 10. in which a NOT con'ac' il insened after a paraUd cireuil. Here. CoillO is SCI ,fnelther o f the con,acts i~ closed.

Input and output bi". memory bits (discussed in this SCC1Ion) Timers and counters Global data bus Temporary local data Static local data bits Status bits ((valuation o f calculation
re"ult~) bil~

You can insen NOT in~lead of anoth"" comacl inlO a branch that begins .t the left power flOil. Insening a NOT comact in a paNnel bnrnch ,hal begin~ in the middle of a rong is nOI permissible.

E,ttY binary operand Can be addressed absoIUI~ly o. symbolically_ Wh~n <canning a binary

,"

4. 2 Binary Logic Operations (FBD)

NOT CU Dta ~'

(n.~ a t<

Roul, oflh< 10::1< 0 <cation)

N"twotil 9

r-nf--~II
N"twori( 10

Co~taC!1

Contact1
Co<tIi>ct2

INOTrl---<(

Coil9

)--I

Contact2
Coil9

I I I
.I

,,!
~

..

1.

OO.~ct3 NOT~I__________ ( )--I


Coill0

-<

Contact3 Contact4
Co~1 0

Contact4

FI~ u c"

4.4 Exomplcs ofa NOT Contact

operan d, or wi thin a binary logic circuit, you can negate the result of the logic operation with the negstion symbol (which i, a circle) , In FBD, you PWIlflUIl one binary logic cireuit p"r nenNork. The logic circuit may consist of on ly one or of a vcry luge nnmber o f in tercon_ ncc!~d functions , A logic cirenil. or logic op;:ta1ion, mu st always be lenn inated, for example wilh an assign ,tmement, Thc assign controls a bin aryorerand with tho ",sult of the logic operation. Thc examples sh own in Ihis chapter Can be fOllnd in Hmet ion block FB 104 of the "Basic FunClion5" program In the "FBD_Book'" library that you ean download from the publishers Website (sec page 8) . For incremental programming, you "'illtind the elemenr; for binary logic Qpel1llions b. th~ Program Element Catalog (VIEw -4 OVERVTEWS [ClTl - K] Or with iNSERT ----> PROGRAM ELE).fB.'Ts) unMr "Bit Logic".
4.2.1

thc scan.ned operand is negated prior to exec lltion of the logic operation (see below).

OR

fu~ct!on

Exo!m;w_OR fUDe';""

~XOR

Th e numkr of binary ftmctions anu the scope of a b inary function are theorel ically unlimited: in practice. however, limits are Sd by the length of a block 01' Ih~ size of the CPU's main memory.

Scanning And u,il:ning signal states Before the binary functions perform logic operation, on signal states, they scan the binary operands SliMe function inpllt~. An op<rand can

be Ica nned for " I" or "0". lf scanned for "I",


Ihe function inpu\ leads directly to the box, A ;;can for " 0" is re cognizable by Ihe n~gation character at lhe function input.
CbL fo<
.j~nol ll .t . "

Ele rnen l ary Binary Logle Operation s

I"

FBD uses the binary function s AND, OR, and Exclusive OR. All functions may (theoretically) havc any num));;;r o ffunction inputs, If an inpmleads dir~ctly to th~ function element, the sign al stale of the orcran d leanned i, u,ed directly in lhe logic opcrntion: if the input has a negation ~hara eler (a circle). the sib'llal sta1 e of

Cb k for
';~D .. I.!a!.

"0"

----1~ ----1L_

A sean for "I" produces a scan I\;stdt of" !" " ,hen the SIgnal slate of Ihe binary operand seallIled is " I "; it prodllce, a scan result of "0" whcn the s;gnal slale of the binary opemnd is

4 Binary

Logi~

()p<:ratiuns

Ch""k fM .lgDal.I ... "1"

11 .0

Function box

" " "'


4.5

, , -\1

~,..l
11.0

,I
-,-

C bd.: fo r . ignal "at< "0"

s.n.".. -~
" '

"

,I

.....,, , \1

&.01.01

..clN.",d

'"-,-

'"

" .,'
"

!t.1

Fun ction box

Function bo"

Function box

fI~~""

S c ~nniDg

for Signal Stat. " 1" . nd 'V '

"0". A scan for signal state "0" negat ~, lh~ ,can re,uh. that is, the ,ean result i, " I" when the s tatus ofthe binary operand ,canneJ is "0"', The binary functions combine Ih~ sa", I<,s,dl. which is. at it wcrt:. the rnult appt:ed '"direclly" to th e box. As far as fun~tionality is concerned. th~se 1WO m~thoos ofscsnnin g binary operarnl> allow you to treat NO conlacls and NC contac ts identically.

put. Ibe AND function is nonnally used, although it would also be possible to use an OR or E,cl~s j \'C OR,
S , an ...-jtb~"t l<>'Jk UP ~ t~liOD

ir.put ---j

8. I {:Jc:}-----["~'E"":JI

Here all example : "0" IS applied to !he input module for a non-activated NO contact (Figure 4 .5). A scan for ' ignal ,late 'T' forwards this smlus to a funct ion oox. T" effect the same for an N C contact, you have 10 ,can an input wilb an NC contact for signal state " 0" (mu>! includ. a c ircle for negation), The signal state " 1-applied to th c input module for a non-acti,ate<;i NC contact i. then ~onvened into ,ignal slate '"0" at the function bo" If you now activate bolb th~ NO and XC contacts. Ihe function bo" will show signa l 51at. '"1"' in both cases. Additional infoImation can be fo und in Chaptcr4.3 "Taki ng A~ "Junl o f the Sensor Typ""'). You ntust always co::mcct the output of a b inary in the simple,,;! case, sirup ly conn""t tbe O" tpUl to an A"ign box (also see Chapter 5 "'Memory Functions '). With Ihis r ~sul! of tt,e logic operation, yo" c an also , (an a timor, . ",eo cute a digital operali"n. call a b lock. and", on. The nellt cbapter p rovide, all thc information you need.
fun~lion ;

Simply sekct the AND function, conn~cling only one function input aod removing tbe other,
A"l) function

Th e A};TI function combines tv.-o b inary states with one "nother and produce. an RLO of "I"' when ooth Slatos (both .can resulls) arC "1". If the AND function ha, seyer.. t input'. the scan results of all input' must be .. , " for tbe collecti, e RLO 10 be "'1 -- . In all (}\h~r ca,~" th~ Ah'D function produces an RLO o f "O" at its funct ion ontput. Figure 4.6 shows an ~xample of an AND f uncrion. In 1\et\1.-nrk 1, the AND function has three inPlOtS. each oj' which can be connected to any binary operanJ . All operands are scanned for si gnal ,tate "'I '", SO lhat the signal state of the operand, is directly ANnOO. lfall the operands thaI were scanned h ave a si gnal state 01" ' 1", the ANTI function ,~IS th e operand Olllpllll to .. ," "ia the A ssign box (sec nex t clwpter) . In all olher cases, tho Al'-.'D condition is nOt fulfilled and op-."'1"and O,I/putl i, res~ : to "0" .
Nen~otk 2 shuw\ 3n AND function w ith a negated input . Negation of tho inp ut i. indic'a'cc1 by a eirde . The .can remit for a negal~d

To assign the signa l "t~tc " f a binary operand oJirttlly to another biruuy operand wit.llOU\ per_ forming any additi onal logic "peralions. for nample to connect an input directly 10 an out-

uo

42 Binary Logic Ope ration. (FBD)

A.",' n fu nction
Netwllrl< 1

Inputl Input2 Input3


Network 2

,
Outp<Jtl

Inputl Irwu t2 l"l'ut3 Outpotl

I I I I I I I I I I I I I I I I I

.....

-' 1 ..
,
,

,
,
',I
"

Inp<J 14 InputS

==d , ~ OutPUt2
~""

Input4 Input5 Outpul2

I I

OR fu"<tlon I Network 3 Input l In;:>ut2 InpuO


Network 4

InpUl l Input2 OI.ltpul3 Inputl Outp"O

,<
I I I I

I nput4 ~
l"put5

> I

Input4 OU\j)IJt4

,,
O
,

Outpul4

""""

E ~du. i, . _O R

I\tncr1on
,~

Netwllrk 5

Inp"tl Inpull
Network 6

~o...lPUt5

Input t Input2 Outpu l5 Input4 Input5 Outpu\15

I I I I I I I I

I I I I
,I

Input4 Inp ul5

=:d. xoe ~OUtput6

, 1 ','
I

mi

I'i~ur.

4.6 Exa mples of Binory f unction:;

opcranu is " I .. wh~n thi s operand is "0'", that i" th e Al\'D condition in the exa mple i;; fulfilled when the operaodlnput4 is '" I'" and the operand / Ilpu rj is '"0 ", OR function
Th e O R functio n combin ~s two b insry ~ignal ,tates and relu rns ,m RLO of ' T ' w h en one of Ihese statc; (ooe of lhe scan results) i , "1 ", If d,e O R fu nction has several inp uts , Ihe scsn re , u lt of only one inpm n eed be " 1.. in order for

the result o f t~C logic op~ralio n (RLO ) 10 be " 1'", Thc O R function ,<,turns an !{LO of " 0 " when Ihe scan result, of all inpU1S are "0'" , Figure 4, 6 sh ows ao e xample o f an OR function, In ' ktwork 3, the O R functi on has three inpllts: each of these inputs may be connected 10 any binary operand . All op~rands art; scanned for signal s tate "1 ", SO th at the . ign al , tate of the operands is d l,<,c tly O Re<! , If on e or mor~ of the operands scan ned h ave signal Slat~ .' \ ' .. th e neX t ,tatCme 'H set, th ~ operand

137

Binary Logic Opt-nliom

Outpull 10 "I ". If 1111 of Ihe open1n<!s scanned have signal Stall.' '"()". Ihe OR condition is nol fu ltilled and oJ'Crand OWl"" I is reset 10 '"0" .
Nelwork 4 sho"'" lin OR funclion with a negated input. Negation is I"<'pr=!ed by a circle. The scan resuh of. nCJ>IIu,u operand is ~I ~ wben thaI operand is '-o~, IIIaI is. the O R coDdi_ li(," in the example is fulfilled ,,-brn !be oper' and /flpUl 4 b~s II .ignal Sgle of"!" or Ibe operand J"pl<l5 1Ia~ II .ignll\ ~tale of'O". Eadu.lve OR fu nction The Exciu,ivc OR funclion combi nes 1"0 binary states w;lh one anolher and I"<'ntms an RLO of "1 ~ ,,'~n t~ IWO Slates (scan result.) are not the same. and RLO ~O~ "-hm lbe Iwo st~tes (scan re.uhs) an: ,dentieal. Fillll"" 4 .6 shows an anmple of an Exclusi,'c OR funCTion. In z.,ctwork S. two inpulS, both of which are , canned fOI slgnnl ,tate '"I". lea<l1O Ih e Exclusi ve OR fun<:ti(ln. If <.Jnly One <.Jf the opcmnd, scanned is "1 .., the ExcllL~i, e OR e()n dilion is fulfilled and the oJ'Cmnd o..lputl is sel 10 "1", If both Operandi lire "1" or ''0''. opmond 011'1"'11 i. 1"<'5el iO ''0'' \;"C\Wor\c: 6 silo"" an Exdus,,~ OR function "'ith a negated inpUT. N"ea;<I;()n is rep~ed by' circle. lbe scan n:.ultofa negatedopera.nd

ii "']"' when that operand i. ''0''. IhaT is. 'he

Exclusive O R condition In the ex.unpl~ is ful. filled " hen bOlh inp Ut op.,mnds hav~ the sMIle signlll SllIte. You Can aoo program an l:ac1usi"e OR func{ion " 'jth _ than two inPUl5, in ",hi~h case the exclt.t>i'e OR condiuon is fullined (in the.ea.;c o f I direct <;can) when an une\~D number of the ope"mds ...-.umed rove. SCan n:suIt nf

--I ~.

~.2 . 2

Combin~tlo nl

of Sinn)" Lo"k

O p~r"llon l

QU can casily combine binary function. with one another. For ins!!lnce. ~'Ou ean combine SCHllIi A.. 0 functinns inTO one OR fuOCTion or "' "HI OR functions intO one F"clUS;"c OR funclion. The number offunttions per 10iliC opcm' lion (per network) ~ theoretically unlimited. The u.;c Q( a "Tbraneh" in Ii loic operation gives you additional options. at1(}wing you 10 prnjp1llll mon.- than one output per logic operan<)ll (.ce Chapler 5.2 "'Fl:lD 1:Ioxc~"). You can link me output of one blIW)' function with the iOPUl of another binary function in ordet-IO implcm<:nt complex bmary I~ic operations. Figure -t.; prm'id6 a nwnber ofexmnpies.

lnpout1

,
OU:pu\8

,""'" Inpout3

'OR

.., I

,..,...,
~
~,~

Inpu!7

4.3 TakinJl ACOOWI! o f me Sens<>.-1'ype

NAND fUn crioD N. twork 7

Input! Input2

,
~ """"

InpY I1 Input2 Input3

I I

I I

'""'"
NOR

I I I I

0''''''''

I I I I I
I

r.l><1lo.

N. I _ 8

Input4 Input5 Input6

..,
"""",W
,

'-"
Input5 Inpul6
""'~W

-,

NetWork 9: You are monitoring the limit switches at the ends of an X axis and a Y axi . These limit switches may not be actuated in pairs; otherwise. limil swileh error will be
rqIOl'1cd.

A nellation may not immediatel y fo llo w a T-

branch . Figurt 4_ 8 shows a NAN D fun cti oll (an AND function witb negated out put) and a NOR function (an OR function with neaated output) , The RLO of a NAND func=tion is ''0'' only when all inpulS have a signal state ofMI", A N OR fu nelion ~tums an RLO of"l " o nly wlKcD oonc o f Ihe ;nput5 has a signal state of "I",

Network 10: You can link arbiuary function inputs with binary funetion$. fQT example you ciln place an h clm; .." O R function in front of the second input of an AND fuoction Network II: Using the negation symbol. you negate the RLO. eVen belwe,," binary funclion!, for instl nce you can negate the RLO o f an O R function and use II as input 10 an t\l'.'J) function. 4.2.3
N~Bting

4.3

Ta kin g A cco un l of th e
S enso r Type

t he Res uh

oft h ~

Logic Operation The circle at the inpul err output of a function symbo l negales the =uh o f lhe logic operation. You Can use negation
~

to !.Can a binary operand. whicb is equiva_ lent to scanning for signnl slate " 0" (sce abo,e). beru'ecn two binary functions (which is equivalent to nc=gating the =ult oftbe logic operation). or at !be output ofa binary function (for exam pic if you wanl to set Of reset a binary operand wben the condi tion is not fulflllcd, that i" wh en RLO . MO"),

Wheo scann ing a Sensor in a userprogtam. you must lake account of whetber the sensor i5 an NO eOO~1 or an NC contacl, Depending on !be SCI'I:IOr type, there i. a different siinal stale al the relevant InpUI when the sensor is lICIiv.. tcd: "I " for liD NO contact and "0" for an NC co nlaC!, The CPU has no meanS of dctermining w~ Clher an inp ut is occu pied by all NO contact or by an NC contact, II can only detect signal stute "I" or signal state "0". Prognomm ing wit h LAD lfyou ~trucrurc the program in such a way that you wam ~ scan ~sult of I" when " SCIlsor is actIVated in order to combine thaI SoCBD ~su lt fuM her, you mu" scan the input differe ntly for different kinds of sensOfil. NO cOntacts and NC
M

to

4 Hi"ary Logic Operations

, , ;' ,
-

(; .., I : Bo,h .. n.on a ... 1'0 <on'uf!

So1/) Ufl;o",

->
0

" "
0

" .,. .,.


M

, t ) "''',,,''ed ,1 4

Cu. 2: On. ~o contaN ond un.l'C <un(.

~5j

, ., ."" "".
-

-. , . lr , " .,." 0
-7

Bolh Hn"""" actlv. ,to<i

HH4H H 1HH4H HH'H HHH'H H H1


1 4
0

.,.
Con"'ctor
plcl<8 up

"
~-jllu" 4.~ T~kjng oontact~

"

"

Conr. ctor
pict. up

.,.
"

Account of tho Se""'I Tn'" (LAD)


10 you for this purpos~.

arc

a~aiJablc

An KO comaCl rerurn "1" if 'Me ,cann~d input is al.o " I ". An NC co ntact return;; "1 -- if !bc ,canned input is " 0". In this way. you ~au al,o

directly scan input' that are to trigger acli, ities when they are "0"' (z~'TO-acti"e input<) and sub'equcmly re-galc the scan n:suit. The ~xampJ" in Figure 4.9 shov., programming depcndent on the sensor type . In (he fint "a,e, IwO NO contacts are connected (0 thc programmable controller. ant! in the second case one NO contact and one t\' C ""uta<;t . In both cas .... '. B conta~Wr conneclcd 10 m OlUput i, to p ick u p it both , enwn; are ac!iva!cd_ If an NO contact is aC liva(ed, (he sig nal ,tale at the input i, "I"', and Ihis is scanned with an NO contact so thaI power ~aO now wh .... n the nsor is acti, -ated. If bolh NO contacts a ro a~1:ivareJ, power flows throngh the nmg to the coil and the ~ontactor pich up Ifan NC ~on1 aCI is aCllvatcd, Ihe .ignal sta(e al the inp "l is " 0 " In order (0 have power flow in Ihis e"l'e when the ,en,or i, activated, th~ result Il1U';I be scanned with an NC conlaCt. There fore, in (he second ca,e, an NO contact and an NC contact mn,1 be connected in series 10 make th .... contac(o r pick up w hen botM senson; are activated. Programmin g with FRD If you "u-u~tun; Ihe progrnm in ,uch a way that you wa nt a scan result of "I" when a sensor is

ac tivated in order to ~ombine IMat <can remit fimher. you mllSt scan !.he in put dift-"re nrly fo r diffcrent kind. of <enSOr:>. An r-:O contact produces signal state "1" when activated. and i, scanner! dircedy when activalion "I' (h~ sen>Or is 10 produce ft S<:an result of " t "_ An NC contact ,etums 'i~nal stalC "0" wh.... n 3clivaled ; if yon want a scan r~sult of" ]-- when the::-:C eOnta~, is activaled. it mu,( be ncgaled, th"" scanner\. In this way. you can also scan inpm, that are (0 (rigger acti vi ti~s even w hen (hey Mm'e a signal stale of ' -0'" (zero_act ive inpnt,) and further comhinc the scan reSllh_

The example in Fig ure 4 .10 shows sensor typede p"ndent programmint:. In the first C"SC, two 1"0 COma<:l, are e01lllect<XIIO the programmable controller, and in the <econd ea,e one 1'0 contact and one NC contact. In b<)1h en_Ie " a C(lntaClOr eonne<:t~d to an outpnt i, to pi ck up if hoth " '''wrs ar~ a<:ti" ated_ If an 1'-'0 contact is aClivated. (he signa! St at e at Ihe inpnt is " I ", and this is scanned directly so that the scan resu lt is " 1'" "hen the sensor i< ac li "al~d . If bolb NO contacl.'S an; acti\cated, and Al\'i) condition i. fuJfill<XI and the colllaclOr picb up.
Ifan l'C contact is act iva(cd, !.he signal Slate a( th~ input is '"0--. In order (0 obtain a , can rcsuJ( ,,[ "I" , the inpnt mUSI be negated Wh~fl seanned. In the second case, you n~~d an AND func!ion with on.... direct and 0"<: negated ;"I',n in order for the e'-'nt:<~lO r to pi ck up w hen both sensors are acrivaled

4.3 Takinj;; Account of the Sen_ Type

c.", I : 8Gt~ "'....... . .. ]\iO r ..n'",!>

E-s~

,
"
&
Q
4 .~

I
"0"

~I

E-s~

---7) H "'
I
"
1.~

c.", 1 : One ~O <o ...u .mel .. lie NC r.n._..

'"

"--J
&
0 4.2

r
"

" "'"

E-s~
"0"

,- T

->

S
"

~
&

" "'" " "'

-----... , ,"

'to

~
&
0 .3

11.5

" '"

...

"

'"

"'

0".3
~

...

"".~

"

"'

" Coo

-~

Fljtu .... 4.10 Taking Aerow" of1h< SeruorT)-pe ( ~ FBD)

'"

Memory Functions

5.1

LAD C olis

In & l&<!der diHllrwn (LAD), the memory functioIU are u~ ;n c"njunction with s"ries and ""mllel circuits in order to influenc", the siiJIpJ sate.< of the biImry op.....mds .... ith the aid oflbe n:sult of the logic o!"'rntion (R LO) lIen",rated in the C PU.

II! Ihe co;!. The n01Cfion of the , ingle coil d"P"llds on the Masler Conrrol Relay(MCR}: If the ~1CR is activated. sian"l Slale 0' is n.<~;8ncd to me binary operand loc~ted o,cr tbe coil.
SJmpl~C"'1

'1lH: following memory functions are 8Y'Bilable ~ The single coil as an Ds>ignmcni of the RLO
1>

The coil, Sand R '" individually proi!mmmed Inemory function.


T he boxes RS and SR as memory functions

Ifpo .... er flow, inlo ilic coil. Ihc opeT11nd is ~t: ,fthere is no pow..... Ihc operand IS re~~t (t"iI.'Un: 5.1 Ntlworir.: 1)_ Wil.b a NOT COn!~C1 before The coil. you re"",r.' e me function (Network 2).
YOtl ClO1 nl<a direct the po,,"cr flow in(() !;evcral coi ls simulmnC<"lusly by ammging the coils in parallel with the help of a T-bT"II.nch (NetworK 3). All opcrdlld. '!",citied OVCr the coils rupond in the same way.l:p 10 16 coil~ can be cODne<:led in parallel.

1> 1> 1>

The midlinc output, as


The coil5 P DOd N as power flow

inl.<:rmcC; at~ buff~rs

cdg~

c,calwl\ions ofllle

1>

The boxes P~S and l>."EG ... ..die nalua lions of opC'l'ilnds
~ di~_

Midhne outputs and edg'" ",valuano!lS


clI$~

in ~tHii in sub'eqn"'nt chapt"'rs.

armnge funher eonIPCT~ in ~ries and I'arallcl eircuits after the T-bran<:h and befo~ the co;1 C'/etwor\l:: 4). You
Sec Chapter 4.1 Series 1OI1d Parallel Cirruits (LADr, for fiInhCT c1Ulmple~ ()flbe single coil.

~;m

You can usc tbe memory fimctiQllli d.,scribed in

!hi, chapl<.T;n conjunction with all binary o~r ands. There are restriction.> when using temporary local data hir. a. edge
TI,,~
m~mory

5.1.2

Set and Re.et Cull

bus.

examples shown in this ch apter arc found in function blocK 105 of the "B asic Func tiOll.>

Set and resct coils also lenninate a "mg. These coils only become "'live when power floWS

through Ihem.
Binary QPerand

prolP1lln in the LAD_Book" libmry thai >Qt, can downJOiw frQm the publisher's Web~itc (see pagc H).
For incrcmL"fIlal programming. yQU ....ill lind the program elements for me memOfy funCTions in the proaram element ca1.ll10& {with VIEw ~ OVI!RVII:WS [CI,I - K] or with L'iS[RT ..... PIW(lRAM EL~\'(Il'iT!\) under "Bit L01! i~".

i')
Binary operand

(.)
If pow.... fio",s in til", sel COIL the operv.nd O'CT the coil is set to signal '!lllt . I' If J'IOV.CT flo"'$ in the /"eSC"< coil the oJm"llnd o'er the Coil is !\:..cl to signal state 0'. If thcre is 00 power in the SCt or l ese, coil, tbe binary operand remains unaffectc<! (l-igu,.., 5.1, Networks ~ I1lld 6).

5.1.1

Slnll'eCotl

The single coil as terminator o f a I\IIlg assiil15

Ihe power flow directly to the operand located

'"

5.1 LAOCo",s

SIll> J. coli

Ii I I I~I I
N_ork2 N_twork 3

,..rwork , laCn

"'")--I 1
INOTI
CoII2

Contact1 Coil1 Contact1


Col 1 2

I
I I

I I I I

1 )--I
Coll3

-,

n n
I C

~_:~tet2

I
Coo<od.

Coo"'" {",)--I CoO,

n n
i i

CoO<

N_rwork"

l lil

"""

Coo"""
c.,,~,

I
I I

~
H
I
Ulet '

II

~ "'.
CoilS

I I I

I I

~
I
I I --, I I
I
I I

CO"

ConlaCl1 Coil1

1')--1
CO"

N_orkll

,teet2 I

c.".",

(0)--1 CoO,

N_lwork 1

H """ """"'" I I
I,
"-11I.U~

"'" 'J

c~li10 $)--1
Coil11

.,..,.., I ""'" I """"" oj CO.


Co'1 9 CoillO Coi l11

)--I
5. 1 Sin,l. Coil. SCI and Rc= Coil

I
I

The function of the set and reset ooils depends on the Master Colllrol Relay. If the MCR is IctiVlt"~l. the binary o!",rand 0\'''''' the coil is not affected. note that the operand used with a set or resel coil ;$ usually reset al STartup (complete TCSlal'l) . In SIX...:;al cases. \he signal stale ;5 fCtai ned: This dep<:nds on Ihe ,lal'lUp mode (for
Plea~

u~mple "'"8JlII restal'l). on the opeTllnd usod (for example SlaTic local daTa). and o n the oeItings io Ibe CPU (for uample fCtentive eh.alrscteri~tics).

You can a""" ge several "I and reset coils in any combioation and logelher w ith single coilo in Ihe .ame JUng (Ke\work 7). To achieve elarilY in your programming, il is advisable \0

'"

5 Memo,), Functions

)V"oup the set and reset coils affecting an oprrand together in puin;, and to u,c them only once in each ca,e. You should aho a void additionally controlling tM"Se opera"ds with a s ing le "oi l. A, with the . ingle coil. you can also arrange contact, after the bran~h and before a sel Jnd reset coil. 5.1.3 ;\-tcmor y Box

P1eas~ nole that the operand u8cd with a memo ry fuu"ti,m at startup (complete restsrt) i. usu a lly reset. In special cuse,. the signal 'tate ofa m emory box is retain ed . Th is depen ds on the 'tatnlp mode (for example warn, re.tart). on Ihe operand used (for example "alic local data), nnd on Ihe s~t1 i ngs in th~ CP U (for instance retentive char~Cleris tic.,,) .

S R memory fu n rtlon
ill the SR memory box, Ihe reset input has pri-

The functions of the s~t and ,.."et eoil are 'urnmarized in the box of a memory fun ct ion. The common binary opcI1lIld is localed m'e< the box. Input S of the box corresponds here 10 the sel coil, input It to thc rcsut "oil. The s ignal state of the binary opC1"and as,igned 10 the memory function is at o(jtput Q urthe memory function. There are two version, of the memory fiUlclion: As Sit box (res~1 pnority) and ItS box (set priority). Apart from tbe labeling, the boxes "Iso di m .... from each other in the arrnngGmc"T] t of the Sand R inputs . Binary oparand

ority. Re'~1 p riority means thal thc mcmory function is Or r~mains resct if power 1I0w~ " s imultaneously" in Ihe set input and the re,el input. The TCS~t inPUI ruB priority over the sel input (Figure 5.2, N~twork 8). B ecause the , tatcments are ex~cllted in ''''1ucnce, the CPU initially .cts the m~rnory operand hecame the Sl1 inpltl is processed fi",l , bUI resels il again Whl"l1 it process e, th~ re,ct input . The memoryopl-rand remains ""set whil~ the rest of thu program is proccssed. is an output, this bricf only u.h, pbce in the proce ss-image output table, snd Ihe (exlernal) output on the r .. le,ant output module r~mains unafTe<otcd. The CPU does nO! transfcr Inc process_image output table to Ih~ output modules uotilth" e nd o f th~ pro"'T"~m ~yc1e .
~"tli t1g

Ifthc

m~."...ory op~rand

R S ho ("

," ,
"" ,
0

"

The memory fu nction w ilh r~Sel priorily is the "normal" forn, of the mem ory fllU~tj(>n, "i ncc th~ reset ~tat~ (,ignal slate ''0'') i~ nom, ally Ihe ,afer or Ie'S hazaniou s State . R S mom ory function

A m emory function is sct (or, mor~ precisdy, Ihe b inary op<.-rand ovcr Ihe mcmory box;, ,~-t) if the sel input ha, . ignal state " 1" and th~ ro:sct inpu.t hss signsl Mate '"0". A mcmor~ fllIlction is resel if there i, a "'I"' at the resel input snd a "0" al Ihe sel input. Signal >late "0" at bOlh inputs has no effec t On thc memory function. If bolh input' are '')"' at the t>aIIl~ time . Ihe two memory functions respond diiI~"Iently, the SR memory function is resCt and the RS m emory function i. ",,\. The function ofthe m emory box depend, on the Ma,ter Controll{c1ay. Ifthc M CR i, active . Ihe binary operand of s mcmory bo" is no lon ger s fTecINl.

Tn Ih c RS memury box, the . et input ha s prior ity. SCI priority means thaI the memory function i~ or remains ,cl if power 1I0w< "'simultaneou<ly" in the ,et input and Ihe resel input. The sel input thm has priority over th e r,""ct inpu t (figure 5.2 Network 9). In accordance w ith Ihc ,e'llJcmial exe~utjon o r Ihe instruction" Ihe CPU r~scts the memory operand wilh the reset inp ut first procusscd . bUI th en sel, il again when proc,," ,ing the "et input. T he memory operand remain, set whik \he rest of the program i, processed. If the memory operand is an OlJtput, this bricf n:M:lling lak~S plac e only in th c proc cs<-imsge

'"

5.1 LAD Coils

Ne twork a Contactl

Conlactl Contact2 Memory1

D
i i

I I
0

.1

WI

r:cn
I
,

Ne twork 9

, ,,',

Cont"ct3
C<m~'

Memory2

= I
Coil1 2

I
I

fE'

Network

'"

'""

,
I
)--I
,

I
N etwork

,
Coll13

"

I
,

M. mury rl!ootion ,,-i,b latchln

T"

..
,

If Network

12

..

'[j~" : C~:14
Network 13

Conlact2

Coil14

V1

( )--I

..

"

[j"""
CO il:15

."".
Coil1 5 Contact4

- - ( )--I

"
. . ... _....

'"

5 Memory Functions

outp L table. and the (external) output on the lt rele vant output module is not atle<:ted. The C P U doe, not transfcr the proce,s_image output table to the output modules until the end of the program cyd~, priority is the exception when using th~ mem ory function , It is m.d. for example. in Ihe implementation o f a f~ult message bufrer ifthe still current fault message at the set input i> to co nti nue to set the memory func(ioo d..spile an ac knowledgement at lhe reset input Mem ory functio n wit hin
P
S~t

5.2

FBO Boxes

in FBD . the m emory boxes are used in conj unction with binary lo~,;e opemtions in ord~,. to intlue nce the 5ignal states of binary Op"Tands with the aid of the result of the logic operation (RlO) generated in the CPU.
Available memory functions arc
:>

The a>sign box for dynamic "outro!

r ung

.. The boKt'S set ,md re,et as individually projlI'mnme-d mcmory functions


.. The boxes KS and SR as full_fl edge-d memOly functioDS

You can also p lace Ii memory box within a mng , C omacts can be connectcd in series and in para llel both at the inputs and at the output (Fig"'" 5.2 Network 10) , It is also possible to lea'.., the second input ofa memory lx>x unswitched. You can a lso connect several memory boxes logethe r within one rung , You can arrange the memory boxes in series or in parallel (Ndwork II), You Can locate a memory function after" T branch orin a branch that starts at the let, power ra il Mem ory functiu n "lth (atching
In a re lay logic diagram.

.. The midline output box as intermediate buffer


1>

The boxes P and N as edge evaluations of the re5ult oflhe logic operation

.. The boxes POS and NEG as edge ev"lu"tions of operands The boxes for midline outputS and edge evaluatioru; are dis-cussed in delai! in subsequent cbapters You can lISC the memory funclions described in this chapter in conjunction w ith all binary operands, There ar~ restrictions when using temporary local data bits as edge memory b its.
The examples shown in th is chapter arc fOlind in r\lnction block YB 105 of the "Ba,ic Functions" ptojll'9.m in the "FBD _Book' libra,'y Ihat you can download from the pubhshds Web , ite (se~ page 8).

memory function is Lls~ally implem emed by latching the output to be controlled , 1bis method can also be u,ed when programming in ladder logic. However. it has the d is advantage. when compared wit;" Ihe memory box, th~t the mC1llory function is not immediately recogn izahle .

th ~

Net\1:orks 12 and 13 in Figure 5.2 ,how both Iype, of memory function, set priority and reset priority. using latch ing . The principle of latching is a simple one , The binary openmd con[rolled w ith the coil is scanned. and this scan (the conta ct of the coi I") is connecled in parallel to Ihe set condition. If G." "act f close,. CoHN energiz es and closes the contact parallel to Contacli. If Contact I now opens again. Coil14 rcmains cnergi7.cd. CoON d~energi ~es if Conta~,t2 opens . If signal i;tstc "1" is p"ent at both Can/acl] and COn/acl], power does not flo w into the coil (reset priority). This situation looks different in the lower network : If signal . tate " I" is present at both Conlac/3 and COn/acI4 . power flo"'s into ilie coil (set priority) .

For incremental programmmg. you w ill ftnd


programelemems forthe memory functions in the program dement catalog (with VIEW --> OVERVIEWS [Ctrl _ KJ or with INSERT --> Pro()RA.~I EL E.M.ENTS) under "Bit Logi c"
th~

~U . !

A SSign

n ,Ca5sign box as tenninator o f a rung assigns the result of the logic op<:rution directly to the operand adjacent to the box. If the RLO is ' 1" at the inp UI of the assign box . the binary operand is sel: if the Rl.O is "0", Ihe oper.md is rese t, The function of (be assign box depen ds on the 1\'!aslC[ Control Relay (MeR): If Ihe

'"

5.2 FBD Box",

MeR is activated. signal state "0" i, assib"'cd to the b inary operand over the box .
6ina ry oper~r>d

-l

A muober of example., in Fig ure 5.3 explain how the "" ign box works _ Nelwork t : Th~ '-'P~rand Outpull dir~~dy assumes the signal state of the operand Inputl. Network 2: You can use negation to reverse the function of the assign bo,, _

Network 3. You can d irect the RLO to ",veml boxes simultaneously by in,crting aT-branch and arranging the bo"e.' \~ith the relevant opec~mis ODe below the othec ("multiple output") . All orerands oV~c Ihe box~ , respond in the <ame way_ N etwork 4: You can in,en binary fuocl;ons between Ihe T-bratleh anu th~ lc-'TIllinating box. thu, expanding a logic operation by additional [unction boxes . You w ill find adu ilional examples for th e ,,"s ign box in Chapter 4_2 "Flinary Logic Orerations
{FBD)".

A"ilIn
Network I Inputl Network :l Input1 Network 3 Input2

..
Ou!p~ t l

I I
OlJlpUt:l

l"Putl Outputl Inpvtl


O~\put:l

I I

....

CJ

q I
OutputS

, r:l'

CJ

, "" n,
r=J

Input2

Ne twork 4 Input3 Inpu\4

L>H
O ~tput5

Output3
O~tp~t4

9,L
OUlpUt7

Input3 Output4

I I I I I I

CJ

"

I I

CJ

OulputS

- I

OutputS
Oulput6

S<t and ...1


Network 5 I"putl NetworkS

=
-

I I
OutputS

Inpull Ocotpua Inpu!2 Output7

I I
I ,

r:=J
,
i [7]

Output7

.,
,

I~

Inr()12

. "'"twork 7 Input! _ Input4

Inpu\3 Input4 Outputll

I
c

Oulput9 R
OutputlO Oulput11

"""".

OUtputtO

Output1t
Fil:u~

5.3 Ass;!!". Set and Reset (Hl D )

'"

S Memof)' Fun~Iio~
~ . 1.2 S ~I

and Rent Box

S.2.J

M em or y 8 0x

ScI Rnd reset boxes alro terminate a logk oper. alion. These boxes are a<,:tiv~I~d only woen the
rc~ult

o f the 10llie operati on going into th .. box

is

~I".

The functio n, of the set and reset boxc s arc: ~ummarized in tbe box of n memory function. The common bioary openmd is 100aled o,'er the bo" Input S of the box corresponds bere \{)!hc set box. and inpul R 10 the reset box. The SignBI mile of the binary opmInd as~ianed 10 the mC'lllOl"y function i. at OUtpU! Q of Ibe memOf)' funclion,

If Ihe RLO going inlO th~ $\:1 'oo~ is "I". Inc operand over the 'oox i~,scl to sianal ,tate "1". I r the RLO going inlo Ihe reset 'oox i, "I ". the operand o,-er tbe 'oox i5 Kt to signa.l 5tIIte ~O", If the RLO going into the "' or fe.! bo" i~ "'0", the binary operand remains unaffected. The function of the """ and reset boxes depends on th~ Mas!el Control Relay. If th\: MCR ;~ ",ti. vated, the bmary operand OVer the box i. not
RfrC ~led_

Fillure 5. 3 shoW1 'C\leTIIJ ~xamplcs of bow the sct and ",,,,,t boxes work..
Network 3: The opeJand 0ulpuI7 i, sel "'h<n the operand lnpu'l is "1". 0u1pt<17 remain. SCt wh<n l"pUll rctums to '1J1&I S\.ate ''0'',

There are two 'e!"Sion s of the memory fu nction: As SR box (resel priority) and as RS box (.", prion!)). Apar1 from Ihe labeling. the boxes also differ from .... ch other in tbe arrangement of the S and R inpUIS. A memory function is KI (or. more precisely, the blIlary operand o>"er tb.. memory box is set) when the sc. inpul is "\ """lbe resct inpul is ''0''. A memory functi on is reset when Ihe reset input is " \ " and the set inpul is "0". S i~nal state "0" at both inPUI;; has nO dfe.:1 on the memory functiOn. If both inpulS haH signal ,tate "'\" si.."nultaneously, Ibe twO memory funC1ions respond di(ftTCIIdy' the SR memory function i! reset and the RS memory funC1ion IS SCl
n

Network 6: The opel1lnd OurpUlllS reset'" hen the operand lrtpu,2 i$ "I". 0u'put7 remaim resel when lnp.<l2 rerurns to signal Slate ''0''. Network 7: You can Rmnge severa l set and boxes in any combinati oo aDd loge!her with a,ssign boxes in the >lme box after a T branch. A. with the assign box. you can a l.o pr.:lgram binary functions after the T-branch and befOTt' a sel and reSCI box.
re~et

To lICb.icve clarity in your programming, il i5 advi ,able 10 JOI"OUJ'! Ihe SCI and re"'" bo",es Bfflinl( an operand in pairs, and 10 uSC them only oncc in each ca~c. You sho uld al.., avoid controlling these operands '.nth an assign bo".
Please note that the operand ust<i wilh a sel or box is usually rc:set on sWlUp (cold re.tan or "'ann restart), In ~ial cases. the sijplal stale is reeained. This depends on the ~tarh.lp !11(lde <for instance hot TC:S!an). on rhe operand used (for e.~ampk StaUe 1~a1 data), and OD the 5ettinw:s in !he CPU (.uch as retrnti\ e "bamete,. iolics) .
re>ll:t

The functioo of the memory box d~s on the Mas!er Control RelAY. If the MCR is lIC1ive, the binary operand of" memo!), 'oox is no longer affecled . Please note thaI the operand used with a memory function i. normally reSCI on startup (cold 1"H".AI1 oc wann restart). 10 spce:ial cases, tbe signal 51alO of .. mCTl>O')' oox is retained. Thi~ <lepcnds OIl the ~1lUtUp mode (fOT imU'lnce hot restlll). on the <>pennd used (for example stalic local da! a). and "n the serungs in the CPU (such as n:'temive charaC1erislic.).

...

SH: me,nory funCllon input has priority. Reset priority means tbnt the memory func tion i. n. remains reset iflbe RLO is 'T al trn: 111.1 W>d resci inputs M~i mu!laI:twusl)- . The reset input Chen has priority o"er the sct input (Fi8U~ j.4, I\etwork 8).
r~.ct

In the SR memory box , Ih..:

Be.:au..e Ihe s!atemenl ~ are e~oxuted 10 seqllcnce, th CPU lirst .ets Ihe memory Op<:Tand b<:"HU~C the sel i"l'ut i~ I'roccs~ed r.rnt, hut ~sets it again when it prO<:e5~e~ the reset inrul. The memnry op"rand remains reset wbile Ibe re~ of the program ~ processt'd. If the memory operand is an OUlput. this brief ienmg take~ plac<: only in the proc:ess,image

"etwo'" 8
In put1

Inpull

---I'

.~O

OUtputl2 InpU!3

In ....!'"

Inp(lt4

OUlpUt13

"

"
,

,
"

~ ,
t tjlu re
~.4

Momory

Function. (FRO)

'"

5 Memory fu ncti<>n. OUlput lable, and th e (ex temal) output on the relevant o utput module r~main, unaffected. The CPU does not trans fer the process,image output table to the output modules until the ~nd of the program cycle. The memory fllnc tion w ith reset priority is the "normal" fonn o f the memory function. as the reset state (signal stale "0") is usually the safer or less hazardous state .

5.3

M .idl io c

Ou t puts

lI.1idline outpms are imennediate binary buffers in a ladder diagrJ.m or function block d iagram. The RLO valid at the mi dline QutP\l\ is sto~d in the opernnd o'er the midline outplll. This op er, and can be scanne d again at another point in (hc program, allowing you to also post,proces~ the R LO valid a: midline outpUl elsewhere in the progrMlL TI,e following b inary operands aTe suitable for iruermediate storage of binary results:
[>

RS rncm(lry functiou
ill the RS memory box. the set inpul has prior, ity. Set priority m e aIlS tbm the memory function is or remains sct if the RLO is '"1'" at Ihe sCt and

reset inputs "~imul laneously" The set input th~ "Il has priority over the re ,et input (Figure 5.4. Netwo rk 9). Bccau"e ,he statcments are e~ecut\!'d tn sequence . the CPU initially reSets the memory operand be~a "sc the reset input IS pr<><:eiSed first. then .et;; it again when the set input is pr0cessed. The memory operand remains ,et while the rest of the program is processed .

You can use lempo",r)" local data b its if you only require thc in t ermeui~te resu lt w ithi n the b lock. All code blocks h ave temporary local da\.a Static local data bits are available only with, in a fnnetio " blud:. , th ey Ston' th~ signa l , tme Ufitiltbey are reu sed, evcn beyond the block ooundaries.

[>

[>

If the memory op~rand is an output . this bricf resetting t>ikes placc only in the process, image outplll table, and th e (external) output on th e relevant o utput module is not atl"ected. Tb<: CPU doesnol trans fer the proce",imagc OUlput table to the output m odule, umil th~ cnd of th e program ~ycle .
Set prio rity is tbe ex<:eption rather than the rule. Set priority is used. for exampk, in the imple, mentation of a fault m~"age buffer if lh. still curren! fault message at the Set input is to cOn' tinue to set the m<:lDory function despilc aT) acknowle,lgem=t at the reset inpul. Memory functiun wIthin a lo gic op eration You can a lso place ~ memory box within" logic operntton Binary functions can be programme d both at the inputs and at the outpUt (Fi gure 5.4, Networks 10 and 1 1). It is al.>o pos, sihle to leave thc second input ofa memory box unconnected. 'Within a logic operation . you can a lso interconnect several memory boxes. Tbe rn~'illory boxes may be placed one behind thc other or u nder one another after a T, branch.

Momoty bits at"<; available globally in a fixed CPU,sp;: cific quantity; tor darity of programming, try to avo id nl"ltiple use of memory bilS (the same memory b its for dii~ fcrent tasks).
Data bits in g lobal data blocks are also available throughout the entire program, but befo re they at"<; used require the rdevant da, ta block to be opened (even if imp li ed tbro"gh mas> "ddres.ing).

[>

The function of the midline output dep;:nds on th~ .\1aster Control Re lay. If the MCR is acti, vated. the b inary opcran d adja~ent to the m idline output is a.signed , ignal statc "0". The RLO is then "0 " following the m id line output (that is. there is nu lunger a "flow o fpuw er"). Note: You can replacc th e "sCTatchpad m~m, used wilh STEP 5 by the tem porary local data anlilab lc in e'ery block .
OJy~

~.3.1

"lid line Outputs in LAD

A midline output i. a single coil within a rung. The RLO valid up to th lS point (the power that flows in the rung at this point) is stor.-d in the binary opemnd Over the midline output. Th~ midline output itselfha, no clTect on tbe power flow.

5.3 Midline OUlp uts

Binary ope"",.d

(. )
You can scan the binary operand Over the mid line OUtpUI al an"thcr p<lint in the program wi th NO aod NC contacts. Several m idl ine outputs can ~ progrnnuned in <me nmg. You can place a midline output in a branch that stansatthe le ft power rail . However, il must nO! ~ located directly at the power Tail. A midline output may also foHow a T-bmnch. hut may 00( tcrrninat~ a rung; the _ingle c"i l is availabk for thi. purpose. Figure 5.5 shows an example of how an in ter_ mediate re,ult is slnred in a midline output. The !{LO from thc cirellit fOlmed by Cumaer/, Con/actJ. ConluCl4 and Comacl5 i. stored in

midline output MidC oulf. If thc con d ition of the logic opcTation i, fulfilled (power Ilows in thc m idline output) and if Contac/3 is c losed. Coill6 i, energized. The J.lLO stored is u,ed in t\.,o ways in the next network. On the one hand. a ch""k i, made to .ee if Ihe condition of the logic op<:ration WlIS fulfilled and the bit logic combination m ade with Call1aCl6, and on the other hand 3 check is mHd e 1 set' ifthc condi0 tion oftb e logic opera,ion WaS no, fulfilled an d a bit com bination made with Conlael7.

5.3.2

i\lldlin~

O u tputs in F B D

A midline output is an a"ign box within a logic operation. The RLO valid up In Ih is point is stored in the midline output over the midline outpUl box

}l i dUD~ outp~b

(LAD)

Netwo-rk 15 Midline outp uts (2)

>-M--j l~1 idl


Ml d tln ~

Midl"OOI: :'__-.:~~I3ct6

~I-ict-'~I------i(

CoilH

)--I

ou' uti (HID)

Network 12 Midline ""t puts (1)


"

" "

Input2 Inpul3 Input4

Inpv~ _

,.,
Midline!

&

"
"

,
Oulpol16

Inpul5

M"" 1 " I ---f'" oo' , ~". ~ Midline!


&

3I
. :

Input?

I'" I

OutputH

I I

Figuc< S.S Midline Outputs

5 Memory Function, ory bit). This mu,1 be an operand whose signal state must be avai lable when the edge evaluation is again encoum~"'ed (in the next program c ycl e), and which i, not used elsewhere in the program. Memory bits . data bits in global dala b10cb, and static local data bits in funct ion b locks acc all suitable as operunds. The e<ige memory b it stored the "old" RLO with which the CPU last proce,"ed the edge c,-aluation. If a signal edge is now present, that i~. if the eu=nt RLO differs from the signal stme oftbe edge memory bil. the CPU corrects the 5ign~ 1 state of the edge memory b it by a~signillg il tl1e "value" of the "new" RLO . \Vh~n the ed g~ evaluation is n~xt processe<l (usually in the next program cycle), the signal Slate of the edge memory bit is the same as that ofthe current RLO (if this has not change in the meantime), and Ihe CPU no longer de t e~1S an edge.

.... klline ""tp~'

Binary op ... and

---4

11

I--

You can ~heck the b inary operand over the mid~ lin e output at auother point in the program. Several midline oulp ,IIS mayb~ programmed in one logic operation. A midline oU!put box must nOI tenninate a logic operation; tbc assign box is .vailable for this purpose. Networl<, 12 and 13 in Figure 5.5 illus!rntc how an intermedi ate r. sull is stored in a m idline ou'pUI. T he RLO from the c i",uit formed by InpurJ , Input2, {"pur3 and Inpm4 is stored in midline output Midl_ourl. If the condition of the logic operntion is fulfilled and if the signal stme uf lnput5 is "I". Olllp",16 is activaled. Tbe ,tored RLO is us~d in t" 0 ",a)lS in the nex! network. O n the one hand. a cbeck is made 10 S"e if the condition of the logic operation was fulfilled and the bit logic combination made with {npIll6, and on the oth~r hand a ,heck is made to sec if the condition ufthe logic operation was not fulfille<i and a bit logic combina_ tion made with 1"1'''17.

A detected edge is indicated by the RLO after edge t' al ... ation . If the CPU detects a signal edg~. it sels the RLO to " I " after edgo evaluation (power then flows). If there is no si gnal edge, th" RLO is "0".
Signal ,tate "I" after an edge evaluation Ihere f",re means "edge detected". Signal state " 1" i, present only b riefly, usually only for the length of one program cycle. Since the CPU does no! deleet an edge in 'he next cycle (if the "input RLO" of the edge c,'aluation docs not ~hange), it "''' the RLO back to "0" after edge evalua_ tion. P le..,e note Ihe perfonname characteristic, of tbe e<ige O\slualion when the CPU is switched on. If no edg~ is to be detected, the RL O prior to edge e,'aluation must bt; identical to Ihe signal state of th e edge memory bit when the CPU is switched On. Under certain circumstances. Ihe edge memory bit must be reset in the stan up rourine (depending on the requirc<l perfor mance and on the operand used). 5.4.1 Edgt ["aluation in LAD

5.4
5.4.1

Edge Evaluation
How Edge Ev.lua tlon Works

With an edge evaluation, yo ... de'eet the change in a signal Slate, a signal edge. An edg~ is posi livc (ri,ing) w hen the signal change, from "0" to "I". The oppos ite is re ferred to as a n~gati\' e (falling) ~d ge . In a ~ircuit diagram. the equh'alent of an edge evaluation is the pulse ~"ntact ekmen1. If th is pulse ~ontact d ement emils a pulse when the Tclay is switched on, this corresponds to 'he rising edgc. !\ p uls e from the puis. contact . lement On switching off co=sponds 10 a falling edge.
Delc~tion of a signal edge (change in a signal state) i. implemented in the progr6m. The CPU compares the CUrrctlt RLO (Ih. ,,",suit of an input ch k. for example) w ith a .lOrod RLO. If the two si gnal staleS are different. a signal edge is present.

The stored RLO is located in an "edge memory bit" (it does not neces.arily havc to be a mem-

The LAD programming Iangnage provides four differenl elements for edge evaluation (see F igme 5. 6).

'"

5.4 Edge Evaluation

P""ili"" od~e 1~ tb. I"'''"' flo..l\"egaUvo edge in th o p<lWfl" no"


I'Mirin ..I~ ..lon ,,!,onll

Edge memory b<1

--4('Jf-Edgo memory bit

Ememllil2 if the series circuit con<iSling of Comuc/4 and ContuaJ interrupts the power 110w,
You may program an edge evaluati<>n with coil a fte' a T-bmnch or in a bmnch that slans 81 the left power raiL It must nO! be placed directly at the l.. ft power raiL E d ge evaluation uf a n operand

--4(NJf--

Edge memory M
N<l:"",eodG" ora" "p<rand

- LM-'",_ --'
operand

NEG
0 -

LAD represents the edge evaluation of an operand using a box. Above the box i, the operand whos~ signal state change i, 10 hoe evaluak><1. The edge memory bit !hal Slore' the "old" signal stale from the prcceding program eydc is loe8led at input M _BIT
With the unlabeled input and the ontput Q, the edge evalnation i. "inserted" in the rung instead of a contact. If pow<'J n<>ws inlo the unlabeled inp ut. output Q emil.< a pulse at an e dge; ifno power 110w, in this input , outp ut Q i.< a lso always ,e ,et . Yon can arrange Ihi' edge ev~!u"tion in place of any contacl. even in " parallel bran~h that docs not beg in at the k fl po"cr rai l. t 'igurc 5.9 shows the usC of an edge evalnation
of an operand in Nelwork 17. The edge ev,,]ua-

Edge mC1]tory bil - , " ,,-,',"--_0 '

Youc.n pro<:css the RLO dire<:t ly following an edge evaluation . Ihat is to say. store it with a "ct coil, combine it wi th down"ream comacts. or "ore it in a bina ry operand (a so-called "pulse memory bit"). You usc a p uhe memory bit when Ihe RLO from the edge e valwuion is 10 be used els~wh">re in the progr"m: it is . '" to speak. the intermediale buffer for a detected eJg~ (the J'!llise contacl eletn ~'11t in me circnit diagram), Operands suitable a< impulse mem ory bil are memory bits, data bits in global dam b locks, and lcmpomry and static local data bits. l:dce evalnation in the !,ower flow An edge evaluatiun in the powu flow is indi cated by a coil lhat contain, a P (for positive, rising edge) or an N (fot n egative, falling edge). Above me coil i, an edge tn=ory hit, a binary operand, in which the "old" RLO from the preceding edge evaluation is stored , An edge eval uation like thi, ,ktecIs a change in the pow~" flow from "rower flowing" to "rower nnl 11 0W ing" and vice verla. The example in Figure 5. 9 shows B rositive and a negative edge evaluatiou in Network 16. II' the parallel circuit consisting of Contacl! and Contact] is fulfilled, the edge cval u~tion ~mit, a brief puIs . wi th EmemBil[. If COnlu,/2 is closed at th i' instant, J.kmory7 i, oet. Memory7 i, ruset again by a pulse from

tion in the upper branch emits a p ulse if ' he operand Contact1 change, its signal stale Irom "W 10 "1" (positi,'c edge). This puhe sets M emotyO The edge evaluation is always ~'Oabled by the direct connection of the llnlabeled inpul to the left power raiL The power cdge evaluation j, enab led by Contacll. If it is enahled with "I" allhi, input, it emits a pu lse if the binary operand Contact3 eh'mg~s its "ignal stale from "I" l<> "0" (nes"'i vc cdge).

5.4.3

Edge Ev"l,,"t;on in FBD

The FBD programming language provides four differ..,,! dements for edge evaluation (see Figun: 5.7).

The RLO afler an edge cvaluation can be dirc'Ctly procCSl;ed r<>r e~amplc stored with a set box, combined. with subsequent binary funclions. or assigned to a binary uperand (a socalled "pulse memory bil"). A pu lse memory bit is used when Ihe RLO from the edge evaluation is to he proees.ed ~lsev.h~-rc in 'he program: it is. 3' it were , the intermediate bulf~'T

'"

S Memory Funclion'

...... ,h~ ......

or,h* RLO
N"l!oll>'. <><Ix_
..r,loe IU,()

"'" ----4 """"""


p

E<l9ft memory till

----4

I--

Ibe 00>; is Ihe opmutd "'hose signal .ale clLange i. 10 be evalualed. The ~dge lTIC'mory bil Ihal holds the ~old" signal its.'e from Ihe last proa:ram cycle is 1000ated I t input M BIT. OUIpUI Q i~ "I' "hen tbe CPU detects a signal stale chmoge in Ibe operand. Network 15 ;n Figure 5.9 edgc eVBluation o f an operand , Upper edge evalua tion ros .. milS a pul ~e when opcr:lnd /"pml aces from "0" to "I" (pos";"e edge). This pulse ~u Me"'ory!. Lower edge evaluation NEG em;" a pu l", when bmary opct1ItId ,,,pm) goes from "J " 10 ''0'' (negali"e edg e). This pul~ re~ISM<,mory} when operand '"pul! i. >OJ".

P... I, I>" odx. or. n " ,,*rud

Binary op&falld

Ed~ m..-nory bit ~ M ~~$ 0 ~

<>f." .,........d

J'I'~oI"N

E,;g....."""'Y bn

~ M ~~G 0 ~

".,.,,-~

5.5
dele<:led edge. Operands suitllble as pulse memory bil~ are memory bi.s, daa bits in glob al data blocks, and .emp orary and s.a.ie IOCkl d ata bit~.
B

Blo ary Scale r

ror

An edge evalualion is nol permilted after a Tbranch, Ed"e e... lulltl(m or . he RLO An edge evalua.ion of the RLO is indica.ed by a box con.ains a P (for posili~e, ri:ii"ll edge) or an N (or negalive, falling edje). Above lhe IxIx is the edge memory bit, a binlUY operand conalning Ihe ""old"" RLO from the p rt:vioul cy<:le. An edge e"lIlualion like this de.ccrs a c hange of lhe RLO within a logic circuit from RLO "1"10 RLO "()" and Vice versa.

.ha.

A hinlll")' scaler bas One input Bnd one output. If .hc .illnal a. th .. input of the binary .scaler c hanges its Stale. for example from "0" 10 "I", Ihe ou.pu. also changes its siJPla l ~Ia.c (f igure 5,8). This (new) signal Slate is retained untillhe neXI, in our ~ xample pos;Ii~e, siJlllal state change , Only then does IhI: siJPUlI state oflhe OUtpul change again. This means Ihal half .he .npUt frequency appears at the outpUt of Ihe bi"",")' $Caler.

o
Output

o
-I,
I

The example in Network 14 of Figure 5.9 shows a positive nnd a negalive ed"e ev"IUII l ion. When the OR function eonsiSlina: of ' npUl' and btpuO is fulfilled" the edge evalUIItion cmib M hnef pulse with EmemBIIf. [f ' nput! i$ "I" al this insant. M<,mory/ is ~t_Memory' is rt:set again by pulse from m<'mBil! wh<:n!l.e AND function comprising Jnp"t~ and InputS is no longer fulfilled.

5.5.1

SOIUlion In LAD

There are many different ways of soh ing ' hi s task. Iwo of"'hich 3rt: presented below. The firsl solulioo uses mC1110ry functiotu (Figure 5.W, ~elwork!; 18 and 19). If the signal SIIle ofille operand Input_' is "I". the operand O"lpul_ ' is set (the operand MemoIY_'IS s till resel). If the signal Stale of the opcnnd 'nplll_' changes to "'0"", Memot)'_' is also sct (O",p"I_ ' is no,,' "I,. If Input_l is''\"' lhe ne>;1 lime arouud, Outp",_ l is re>K'l again (Ue",oryj is

Ed"e .--I uatlon of an opera nd


The edge evaluation of an operand is 1000ated at we beginninj of a b inary logie operation. O,~

".

S.S

Ilin~ry

S.caler

' I EdJl' ."OI"'110~.~'i\"''""'::::::=~,,:-:==:::~~=::-:'':====-:=~==::-~ Edll~ (I,. 7


'. ",.two", t 8
. dluallon In powor now
Me
ConlaCt"l

Edg9 meroory bi l

Con:.C12

11--1 1

I--"' "'---" " -Ii~


Con!acI4
1-1

(p)
Con(act!i

1f--1'

SR

0
.-J

1 )--1 - - - IIII-- ---(N )------i!!_ R 1"" "_ f7 !~. ....Iu. tion of an Opol,*nd

Edge """""'Y b.t2

01-- - -1

.'. ,I
,.

Network 15 d~ .vatuatlon of an ~'* ""

..

now l~). If Inplllj is once again . 'O~. Alemo'Y_1 IS reset (.ince Outpul_ I i, 00'" also re~el) . Now the ba$ic 5ta1~ bas heen n:a~~cd again .. lier twO input puis<:. and one output pul.e.

The .e<."(md SOlution uses the i.lotclling function (NetwQrks 20 and 21 ) eomm<)Q on ell:uil diaII1""rn . The principle is the .ame as in the tlrsl seotution c~cept thaI Ihe r,,,e1 condition - as is usual will! latching . is "zero "ctive-.

'"

N_ork It Binary scaler wllh mamory bo. .a (2 )


~m

- -'

,
R

NittWork 20 Binary scaler wilh Ialch!ng function (1 )

I :~F- ~: I -'-~-In'
""twor1< 21

"-'-' ( }--I

BInary scal ar with 1 lchfr\ll function (2) .

f-_'_11L~'~___-l"'"e- __r-______________Momo~ " C' ~(

1-'-,!""'-'i=1
n~wr'

,--_ e~ry_2 M--1

S. IO llinary Scaler E>.llIilpl ... (LAD)

5.5.2
Th~

SnlU IJo n In FBD

IlLSk , IWO

are many ditT=1 ways of sol,"in, Ihis of"hich are prescnled ~Jow.

instn.tClion JC>i is e"C"CUIW (you ""iI! find dct3.ile<l descriptions of the jump Qpe:rIIliOU$ in Chapter 16 "Jump Functions"),

Thc firsl solulion useS memory functions (Fiau re S.ll. Networks 16 and 17). If tbc sign.1 S iale of the operand InpllI is "1", lbe opt!1lnd 0 1<11'''/ is SC I (th e operand MemOly is slill re~t). If th e ~i gna l ~tatc "fthe openmd Inpll/ changes 10 "0''. Memory is also set (Ompu/ is now T1. ff Inpul is "J" the ne,,' .ime around. OlilPlil i~ rescI ag.. in (M..mOry is now 'T'). If b'pul ii once ",am ''0'', M"",,,,)' is reset (since OUtplll i~ now also ~set). Now Ibe basic stale Iu.5 ~ reached again after Iwo input pu[,.e5 and one

III our eumple. the jump label is called -bifl and i. in N~IW'ork 20. It i~ bere that the program
M

<can is resumed if no edge is dCI~ted. The actual binary scaler is in Network 19: If O"lpWO is " 0". ;1 is sct; if il i~ "I", it i~ rc~CI. This oeN. ork is proccsse<l on ly when an edge is ,klccled al IllP"tO. In ~ssence. every tltne an edg~ i. d~lecled al1npu/O, Ou/P'U() dmoges its signal rulle.

OUlput pul~.
The S<."COnd solu.ion uses an edge C'o... lualion of the operafld Inpu! (Figl.lrC 5, I J. l'eIWon:s 18 10 20 ). Ifno edge i. detected at l"pulO. the RLO IS "0" fol lowing edge ~",'alualion and Ihc jllmp

5.6

Example of II Con' e,'o r Co nt ro l System

Thc following ""ample of a functionally cxtre",~Jy simple cooveyor bell controllYltem illustrate, Ihe u.o.c ofbioary logic operations and

'"

j.~

bample ()f a C onveyor Control

S y ~\C'ITI

BIn.ry >._ler (Um) .Netwol1l 16 Binary acal8r w ith mA mory bous (1 ) Input

..

Me mory
,,~

,-

, , ,

,
R

~'M

'R
0
~

..

.~

- Mo~" , Network 17

'. ~ ':.1
".'~

0",.,.,
,~,

Binary scaler with memo!), boxes (2) Memo

'R
Q

".'. .: :" - .': :' .-

-. .... - .',.
-"

. ',"

OUIPUI

Network 18

.. dg.... v alu..tion (1)

-.. .-' ,.

19 Binary s caler with e dg e ltValuation (2)

OUlflutO
OUl putO

-<!

&

I - I

Network 20 (next n ..twor1l with jum p I. bel)

~
fieurc
~.Il

... ",., ...... . -.-.-;.' .. - ';' I


.~.

'.::

..... ..'
~~t .:":'"~

.. I

Bin ary

S c al~"T

Exomple. (FBD)

memory functions in conjunction with inputs . OUlpUI< and memory b it>. Functiouul de.triptlo n ?arts are to be transported by conveyor beh. nne craIe or pallel per belt. Th~ es'~ntial n.m~ lioll' are ,.. fol lows :

be lt' (end_of.belt) sen;;ors no longer det~ts


t h~m.

The example is programmed wilh input', outputS, and memory b it', and may be progranUlled in any b lock at an~ location. In th is cas." a fundion ",i'hout function value wa.~ ch()sen as block Si::n 3ts. symbols .'\. fe w additional signals ,upr!em~"T1 t the function al;ty of the conv~yor belt ~ontrol system:
0>

> When Ihe bell is empty. the controller req uests mOI~ pans by ;:;suing the "ready_ load'" .ignal (ready to load)
0>

\Vben the "Starl" sigl1a l is issued, the hell st~rts up and Iransports the pan, of the conveyor helt. an "end_oI _ ~lt" ' sensor (for instance a light harrier) de Ic~ts the pans. at which poim the bell motor swit ches off and trigger' The "'readyJcm" 8ignal (ready I() remove) When the c ontinue" ' ignal is issued, Ihe pan, are lran sponed f unher lltlti) the '"endAtth~ ~nd

I>

Basic_ ,1 Set' the controller to the basic <late

t>

Mati on
Swit~hes lh~
ti (ln~

belt on. ,..,gardless of condi-

po

t>

! Stop SIOP< the conveyor as lon g as the "0" sign,,!

'"

5 Memory functions gram in this Coapter can be found in a functian b lock witb block pammeters which can also be called as often as needed (for seven l conveyor belts). When programming. the g loba l symbols can ,,1>0 be used without qU()\3tion marks provided they do not contain any $p'-""ial Charac ters . If" symbol doe, contain a spc~ i al eharaNer (SUCh as an umlaut or a space), it must be placed in quotation marh. In th~ compiled block, the edi tor indicates all global ,ymbols by selling them in quotation marks . Figure 5.1l show s the program for tb e conv~yar control sy~tcm (functio[] block FC 11 ) under "Conveyor Example" in the "LAD~ Book" library that you can download from th~ publish ers W~bsite ~e pag~ 8).

is p,-.,sent (an /'-' C comact a, sensor, active")


i>

"z~ro

Light~bartier1

The pans have reached thc end of tbe belt


!>

fM"fauh l Fault signal from the belt motor (e .g. motor protection :;witc h); designed a, "zero ac tive'" signsl so tbat, for e,,"mple . wire break also produces a fault signal

We wanl <ymbolic addrc"ing, that is, the oper ands arc given names which We then usc 10 write the program. Before entering the pro-gram. we create a symboltabk (Table 5.1) cOntaining the inputs, outputs, m~mory bits , and blocks.

Program for LAD The c.~amplc is loc ated in a function b lock lhat you call in organization block OB I (,elected from the Program Elements Catalog "Fe Blocks'') for proccs.ing in a CPU.

Prnl:ram for F'BI) The


e.~ample

is located in a

fun~tion

which you

Here. the e"amp le is programmed" ilh memory boxes. In Chapter 19 "Block Param~t'-"rs", the ;;amc example is shown using latches. The pro

call in organization block OB 1 (from the Pro gram Element' Catalog "Fe Blocks") for pT<>' ccssing in a CPU.

Tabt.S.1

"

,,'

I .. .

it

iti .

'"

3.6 Example ofa Conveyor Control Sy stem

fC 11 Co"vo)nr <o~tr oJ ' )."""

Networ1< 1

L<tdP'"~

N.twork 2 PBrts
~

rud~

'o-",move

"M

'~,

~ _Lo~_N

Remo.e

I I

(,

EM- Rem- ?

(,

Basic_51

i, , " ... I :'......... .,',",' , .', ...,


Q
.- "
~
,~,';

to re"""1o

IMfalfl!1

,
I:
Continu"

..... . .' ,. . '".


,

RemovQ

N etwor~

Belt F."d~ to load R"ad\


EM_Rem_~

,~~

a""ic.J '

I I

(,

, " ,

wload
Q

,
,
,

, ,

,
Netwerk 5 Controll taR molor

'00'
lMfauH!

EM_ Loa

Ie

,
M,

'""

.. .... .. .... .. ':'-'! .. . .. ,;.;.


,
:.~r.:

... .. ., "
."
'

..

...

' .', '.!-'~


,;"~

:'01".

'':1:;

..

,"
Fig .. ..., 5.12 Sample Conveyor Cuntrol Systom (LAD)

'. ... .. ".:.' .. "


,. II:

" ;:c': ._.0"

In Chapter 19 "Block Parameter," , t:te .ame example is 8hown 11,;ng la\chcs. The prognull in lh; s Chapter can be fOlmd ;n a funCl;on block with block panun~te", which can al,o be c "lled 38 often as nccd~d (for ,cvcml conveyor belt').

a, "" L!1nlau, or a ,p~ce), jt mmt be plH~eu ill quotation marks, In the compiled b lock. the editor indicates all global symbols by setting them in quotation marh_
Figure 5.13 shows lhe c ircu it diagram fOT the COM"eyor control sys,em (function block Fe I I ) nf the Conveyor .LUilllple" p rogram in lhe "FBD_ tlook " libra,y that you can down load rrom the publisher', Website (see page 8)_

Wkn programming, t1:e glob" l ,ymbols can ,,1'0 be u.'-'<l without q L wtati on mark; providd they do not co ntain any 'p"c;al charactC1"S _ If a symbol does colltain " opecial character (such

'"

M~>mQry FunCl ion~

f'C 11 Com',

'Or

oonlNI .,'".",

Network 1 loood port.

light_ barrie r 1 Baslc_", IMfaull l Network 2

'""
-

..,
--<
-

~
n

Pam ready to remov..

load
Lig~t_barrier1

..,
,
N

~
~
n
Re~dy ~

BaSic_ 51 IMfau!tl

Network 3 Remove parts l oad


Remove BaSic_ 51
IMfau~ l

..,

, , ,

""""ve

oe

Network "

Belt reedy 10 load

Remove Beslc_",

..,

Reedy to load

load /Mfault 1

..,
,

oe
Q

Network 5 Controlling the belt motor

Remove Load Man on ISlop


IMfau~l

..,

B,, ~

moll

Figure S. 13 Sampl e COIweyor Control System (FBD)

,w

6 Move Fundions

Move Functions

The LAD and FBD programming languages provide the following: move function.:
~

The SFes ar<- 'yst<:m fun<:tions from the "tandard library Standard Library in lhe System
Fun~liun

MOVE box Copy orerands and vari"blos with elemen. tary data lyres
SI'C 20 BLKMOV Copy dat~ arca

Bloch prob'l"anl .

6.1

General

"
~

SFC 21 FILL Fill data a...,a

t>

SFC 8 1 UllLKMOV
Unintemlptible copying of daw area SFC R3 READ_ DBL Read data area from load m~mory

[>

[>

SFC!l4 WRIT DBL \Vri IC dala area into load memory


System memory ?wcess-I"",ge mput ~r><I output t..t>tcs
TUllO ....

You use the move fun<:uon;; w copy information bct"'~cn the system memory. the USer memory. and the user dmH are" of the moollies (l'igure 6.1) . Information is trans ferred via a CPU_internal n:gister that fu nclion, as int.<:nncdime storage. This register is called accumulator 1. Moving informat ion from memory to accumulator 1 is referred to as 'loading and moving from acc"m"lat.or I t.o memory is <:aUed lransferring" The MOVE box contains
Wor!<. memory

Modules Peripherat inputs

and

counter..

D~ta In data blocks

:' ait memory

,,-

Constants. pointer~

1
MOVE

.. -.
u

r' Process~ma~a.t""'llt
and output tabtes l' Bit memory

1
l
st;oct<

'I

"System memory
Fl~urc

Data in ,;"t8 btocks Wotk memory

Peripheral outputs ModutM

I
'"

6.1 Momory Att .. tUT Loadi ng a.tld Tnm,fe.rring

6 Move f unctions

both trnnsfcr paths. It mOveS information at inpul IN to accumulator 1 (load) and immediald y followin g Ihis fro m accumulator I 10 !he operand at the output (tran<fer)

FBD representahon

MOVe

6.2
6.2.1

MOVE Box
ProC l/"Sslng the M O VE B ox

'" "

,"0

f--

mIT

MOVE

Representation In addition to I~C enable input EN and the enable outp ut ENO . the MOVE box has an input IN and an Qutput OUT. At the input IN and the output OUT. you can apply all digital operand. and digital variahks of e icmentary data type (except BOClL). T he variables at input TN and output OUT can have different dala types. The bits in the data fonnats are discn ssed in detail in Chapter 3.5 Variables, ConStants and Data Types' .

'" "

0", ~

," 0

Different op erand wIdth s The operand wi dths (byte. word. doubleword) at the input and the output of the MOVE bo x may Hry. If the operand at the input is Iess than at the output, it is moved to the output operand right-j ustifi ed and is p"dd~d at the left with zeroe5. If the input operand is "greater" than the output operand. only that part o f the input operand on the right that fits ioto the out pUt operand i~ moved Figure 6. 2 explains thi, . A byte or word at the input is loaded rightj ustified into accumulator

For incremental prQ~ammin g. you will find the MOVE box in the Program Element Catalog (wi!h VIEW -t OVERVIEWS [Clrl - KJ or with iNSERT -t P ROG RA.>.t ELE.\!E}."TS ) under 'Move.

InpUl lN

, ,.)

01 ,

(n+l )

01 ,

(n+2 )

01, 01,

(n+3)

01Doubleword n 01
Word n

,
I"
24 123

,.>

'"

'" , ,.> '" '"

(n+1 l

01By... n 01
Bu"', Accumulator 1

16 115

*,
,.) ~

,
OutPUt OUT

0[7

,.) ~
(n+l )

01B yte 0 01

,''--_~'C')':c_~oJlc'_--'''c'_'c)_...::l''--_'c ' ') _ coJI '_--"cC'JI_....::JOI Dou bleword n l 'c': C ..


Figure 6.2 Moving Different Operand \\idths

'"

6.2 MOVE Box I and the ...,mainder ili padded wilh justit1ed from accumulator L
Fun~tI"n
z~roes.

byte or a word at OUlpu! OUT j~ mnove<J right-

Thl' MOVE box m oves Ih~ ;n fomlltion of th~ opcnuuJ al input IN 10 Ih~ ~d at output om. Th~ MOVE box only move~ information w h~n the coable inpUI is "I ~ or is unused. and when Ihe master colum] relay is dUncf\Pzed.
J f EN - "1" and the MCR i. ~'1lergizw, zero i. wr;lIcn 10 output OUT. Wilh "0" ut the enable inpu l. Ihe operand at output OUT is unaft~cted . MOVTi dne~ nOI1"C{XJr! errors.

can conneCI MO VE boxe~ in parallcl. When connecting boxcs in parollel. you require a coil 10 I<.-rminale the rung. , r yo ~ hav~ nOI provided for C!TOr e;-Hh,ation, a<sign B "dummy" operand to Ihe coil, for exampl~ a t~mporary local data hit. You c~n connCCI MOVE boxes in :<tri..,;. In doing so, lb.e ENO output of the p receding box lcad~ 10 the EN input orthe following box.. If you arrnnge scveflll MOVE boxes in one nono: (pafllll~1 at thc Icfl power rai l and then ~<.)(tlinuinJ; in series the boxes in Ihe uppcrmO~1 branch are proce~scd tirst. frnm Icft to righl. and then the boxes in The parallel branch from left tn nabt, etc.
You CDn fInd examples of the mO~e fUDCtioos in the: ''In>-ic Functinn.~ proa:ram (FR 1(6) orlbe "LAD_ Book" library thaI you can dnwnload from the publi~hcr's Wcb>;ile ( _ pai:" 1:1).

IF EN "I" or not wired THEN ENO:'" 1 IF MeR e nabled ELSE THEN OUT ;- 0 OUT ,-IN

.=

ELSE

MOVE bl'" In a logic circuit (FBI

ENO := ' 0

Enmplt
The cor"en!! o f input "ord l W 0 arc mm'wto
ml:TllOl)'

word MW 60.

If~ou w~m In process the MOVE box in dcpt.'Ddence on specific conditi ons, you can program binary logic ci",uits before Ihe F.N inpul. You caD conutc1the ENO output wllh bi nary inputs of olh..". u""tio"-,,; fm instance. you can arrnng~ MOVT' boxes in series, ",hcf'cby the "NO ou1put oflbe preceding bo" lew 10 Ihe EN input of tlw; followin g boA.

\.AD ... p......,talion '

f-- ---I E ENOf----1 N


FBD re-pr4I5OOtation
-

'M"OO,V 7.,'1

FN and ENO need nOI 1:><: w'",d.

,w 0-l'e''--'OU''"'. r- MW '" c,V;"'" r


MOVE
EN OUT MW60

You can find examples oflbe move functions in the "BIl!Sic Functions" progrum (FI3 1(0) of the "l.N)_l:Iook library lhool you CIUl downlood from the publ1shcr's Websi\(: (...", page S).

6.2.2

M o \ing Opt"noodl

In addition to the operanJ,j mention<,d in thi s

MOVl;

bn ~

In .. run," (LAD)
~ne,

You can arrnng'" contact:. in

and in paral -

lel before input EN and "fter OUTput Ef>.O.


The MOVE box mu~1 only be placed in a ~h that lcads directly to lbc ldi power rail. Th i$ bo1tnch can al .... ba\-e Conl&CIS before the inf'!Ul EN atld it need nol be the lOP hranch. With Ihe direct COIUlect,on 10 the left power rail you

ehapltt, you can als.o move limer and coumer value. (~ce Chapte r 7 "Timers" a.nd Chapter 8 "Counters") . Ch apl~r 18 .2 " Bl ock Functions for Data Bloch", deab with using data oper ands.
" to\i ng Inpu ts

IDo IWu IDo

Movin g an input byte Mo"ing an input word Moving all input doublc\\'ord

'"

lOJiTlg iwm the pmces!i image or tramfen+" g the pr,,"cs. image of Itw input>; is al,o pN'",i ..ible for all CPU, with tbe S7-300 and for til" ncwer CPU. "";11t lite S7-400 in the ease of the inpul bytes which lire nol JIfC>'<."n1 as an inpul module.
l<l
Muv i n~

outpun
Movinll: lin ,)UIPUI b}1 ' Moving "" OUlp~t ,,"ord Movi ng au output doublewoHI

The peripheral o u~p"IS (PO:;) M!"C u,ed for transrers to the 110, Only those add,,,>,,,, cnn be ac~~"""d Ihal are also OCCUPIed by IJO mooules. Transferring to IJO moo.luJ". \hat have a procen_image OUTpuT table sImultaneously updates tbat proce<s-image output table, so there i. no diffuenee beTween idmlicaUy addns,ed ouT_ pu!:> and peripbe!'\ll outpUts. 1\10,lnll hit memnry

QB"

QW"
QD"

MD. MWn

Loading from the p"",e~~ image or traru;~rring to the process image afthe oUlpu:s is alS'l pern,i.sible for all CpU. with the S7-300 and for !he ""'Wei" cpu. with the S7-400 in th~ ca5e of the oulpul bytes wllkb lin: not p""wnl a~ an OUlPUI module. Moving from tho 110

Mno

Movi"S a memol)' byte Moving n memory word M,,"in!j: a m~.,..,ory doubteword

Moving from and to !he bit memory ""Idre~ a"'3 ,. 1I1,,a,.~ permi<siblc. since lite ".-bole bit mem"ry;s in !he CPU. Please rIOte here the diif<.T,:nee iD b .. mctDOfY ""'" "i~c on the ~arious CPUs_

LH II

I'lD n PIWn

Pro "
O'Q. "
PQWn

wading a ~ripheal input byte Loading a pc,;phcl'lI.l inpul word Loading II periphen>! input double"ord

LWn

LD.

Moving a local data byte Moving: a local <1"1# "un.! Moving a l<xal dnla doubleword

"",

Transrerrlllt! 10. peripheral inpuI


Transferring to. peripberal oull'ul wem! Tmnsf.rrirw 10 a peripheral OUlpUl

MO'ing from and 10 the l Slack l_< alw,"ys .now~-d PiuS(: nOle lhe informaTion in C1wo.pl('f 18.1.5 '"Temporary L ....... "J D.I#~.

6.2.3

;\ \'(/\'inll Con f tunt$

PQl) "

doublev.ord
Wb .. moving in the 1'0 area you cau ao;ces~' ." diifere", cqx:rand.s depending On the dinxliou oflbe move. You 'p<.>Ct/)' LO inputs (Ph) al the IN inPUI of the MOV!:: bo~, "",I 1 0 output~ (PQs) at The OCT output.
When moving from the I 0 to memol''' (loading). the inpul modules ate acee ..ed as p<.T1phl-ra l inputs (Ph) , Only Ihe &\"ailahle modules may be addreued_ Plc,,!~ DOl. tlml diTC<:1 landing from the IJO modules Can mOye a diJfcrcn! ~lIlue than loading from Ih" input>; oelhe module "'ith the samc Iddrt.ss. While the .ilP'a! StUC5 of th~ inpuTS COlTCspunds I<> th" ,alucs II the sWl of the I'fOStanl cycle (wben the CPU updaTed the pTOee$._ image). the value. loaded din.."tl)" from the VO module. ITO the current ,'aluc>.

You may specify ~ons tanl va lu es onl y a t Ihe It' inPUt oflh e .\ 10\'E oox . \ lo,1nK constanlS 01 d~mNltary dala
Iyp~

A fu<;<l value, or conwuu. can be =fC1'T'Cd 10 An operunQ To ~l!hallCe cl~ril), thi~ constaD! no be tnlnsfc,.n:d in ,me o r ie,..,raJ dirrerem formats. In Chapter ),So4 " FI~mC'fltary Dat" lyP<-s. )OU" llJ rmd an overview ofallthe di f_ ferent forma", . ,\11 c, m<tunl< thaI can be mo,cd us ing the MOVE box belon~ 10 th~ ~Iem.ntal)' dald Iy!'-"S 'Eumple$:

Moymll a 2-dijCit hexadecimal number

-1000

MO"m~
~Io'ing

' .0
SST- 2s
TOO"g ,30

an I"'T ntJl'llber a REAL DUmbcr

MO'-mil: an 55 Illner Mo~mg a Time of day

".

6.3 System function. for Data Transfer

J\.I(lving pointu. Pointers are a special fOlro of con<tan! used for calculating addr<:SSCS in .tandard blocks . You can uSC the MO VE box to ,Wr<: these pointers in operands.
P III.O

If you use a variable w ith comhined data type, i\ must only be a '"complete' variable; oompo-

Movin g an area-internal rointcr Moving an ar<:a-<:rossing pointer

nenB of a variable (e.g. individual field or sITUcmrc component') are not permissible . You can usc tbe ANY point~r \0 define an area with absolute addre s< (sec Chapter 6 .3 I "ANY Po inte,).
ANY parameter" Ith t he St'C 83 and 84
The system functi on, SFC 83 READ_DBL and SfC 84 WRlT_DBL !Jan,mit dum be\ween data bloch present in the load and work memories . Complete data blocks or pam of data blocks arc pen nissiblc as actual block par<IIII~"\crs SltCBLK and D STBLK.. With symbol ic a<idre,>.ing, only 'completc' variables are accepted whicb are present in one data b lock; inilividual field <.>r structure compon~"Il\l; aTC not permi"ib le . Use the ANY pointer to speci/)' an absolute addressed area .

P;'tM2. I
6 .3

System Functio ns for

Data Transfer
The lollowing system functions arc available for data transfer
t>

SFC 20 BLKMOV Copy data area SFC 21 FILL F ill data area SFC 81 UBLKMOV UnintcITUptible copying of a data area
SFC 83 RF.AD_ DI:IL Read tram load m emory

t>

t>

6.3_1

A,'1Y I'ointer

t>

t>

SFC 84 WRIT_ DilL Writc into load memory

You require 'he ANY pointer when you want to .pec ify an ab.,olutc-addrc"",..d operand area as block parameter ofryre ANY. The general format of the ANY pointer is as follows : P#[DataBiock]Opcrand Type Quantity Examples: P#MI6 .0 BYTE 8 Area of 8 byres beginning with MB 16
P#DJll !.rHIX30.0 INT 12 Area of 12 ..... ord, in DB 11 beginning with DBB 30

ANY parameter f(lr the SFC. 20, 2J an d 81 These ,yst"'" functi on" each possess two parameters of data type Ah'Y Crable 6.1) . You can conned (in principle) any orerand. any variable or any absolutc addressed area.
Thble6.! Panunctc-rsfurSFC20.21 and 8 1

SFC .

'"

Paramc',r SRCBLK }1FT VAL I)STIlU<


BVAL

Iliaralion INPUT RETUR1'; OUTPUT


~m

Data TlP<'

to~t""ts, I~ripti"n ~ource

ANY
~, ,,~

orc. from which data arc t(} be copied

.. ._. . . .
'

" "'

ANY
I.'lT
AN!'" ANY

Error inlorrnati on Dc" ination to which data are to be copied Source area to be C'upi<Xl Error informatiun D,"ination to w~ ie~ t~. wurcc "rca is to be copie<! (mcl"w"{I: multipk: oopie,) S""rce orea trum whicb do'o an' to be copie<! Error infomlati on Do"ination to which daUl are to he copiod

RET VAL
liCK

RETURi\' OUTPUT INPU T RETURl" OU1T'UT

SRCIlI.K
~,

VAC

on
ANY

DSTlJLK

'"

Mov~

Function.

Pil1l8.0 WORD I Input "'oro IW 18

1'#11.0 BOOL 1
Inpul I
(.0

Example (Figure 6.3, SeN"orir; 4): Starting with memory b}1e M S 64, 16 bytes are to be copied to dala block DR 124 suning from DBB O.

Plealie note that the operand addJ"e,ss in the ANY pointer must al ..... ays be a bit add~ss.
It mllk~, ~ense to 'p"cify a constant ANY

6.3.3

U ninterruptlbl e Copylni of Data A rea

pointer when you ..... ant to acceSS a data area for which you have not declared variables. In prineiple. you t1Ul assign variables Or o)leTBnds to an ANY pIU1Imeter. For example, PIIII.O UOOL I' iii identical to'l 1.0' or the rele...ant symbolic addres .

SY$tem function SFC 81 UBLKMOV copies the content, of a source a~a (pa rameter SRC Fl LK) 10 a dCitination a~a (parameter DSTBLK) in the direction of ascending addres,es (incrtmenta.lIy). The copy funclion i. unintermptibk. crntmll the polSibtlity of increa""d res~ limes 10 imenupt . A mni mum of512 b)1<:S can be copied. The following actual partlllKten may be liD cd : I> Any vatiables from the operand areu for input~ (I). outputs (Q). bit memoty (M), and data blocks (variabks from global data blocks Or from instancc dala blocks)

6J.2

Copy Da ta

A ~a

The sYStem function SFC 20 BLJO,-IOV cop,es 'he conten\5 of a soure. area (parameTer SLCULK) 10 II destination area (parameter DSTnLK) in the direction of ascC"lldinll addre s&C1I (incremental).

The follo ..... ing actual parameters may be assigned:


c>

> Variables from the temporary local data (spec ia l ein:umstances 1I0vem the use of data type ANY)

Any variables from the openmd areu for inpUIS (I). oulpulS (Q), bil memory (~t), IJ1d da\.a blocks (variables from global da\.a blocks and from instance dau blocks) Variables from the temporary local da\.a (special cireUl11$tances govern the use of dat8 type ANY)
Absolute-addressed data area" .....hieh require specification of an A."'lY pointer

>

Absolute_addres~d dati. areas ...... hieh reqUIre specification o fan ANY pointer

I>

I>

Sf"C 81 cannot be u""d \0 copy li.mrs or counters. to ropy information from or 10 the modules (opcnmd area Pl. Or to copy system dall blocl<s(SDSs)ordaUl blocks in load mem ory(data. blocks programmed "ith Ihe keyword (,iIl",ketf).

You cannOl use SFC 20 10 copy limef$ or coun ters, to copy information from Of 10 the modules (operand area Pl. or to copy system data blockS (SDBs) . In the eaS<: of inpulS and outputs. the speci fi ed area i, copied regardkss of "hetheT or nmlhe addrt'$Ses aclUally ret"""'nce !npm or outpUt modules. Ifthe CPU does nO! possess Sf"C 8J READ_DilL. you ~an also specify. vlIriable or an ana from a data. block in the load memory as the $OUn:e ana.
Source area and destination area may nOI O\'or_ lap. I f the source area a nd the destination area are of different lengths. the transfer is completed only up 10 the length oftbe shoner ofthc twO areas.

In Ihe case ofmpuis and outpulS. the speci lled arca is copied regardless of whether their a ddre,>es ~fcrence input or OUtpuI modules.
Source area and de"ination area may not overlap. If the source area and Ihe destination area are of different length" the trarufer is completed ollly up to the length oftbe shoner oflbe
\Vo'O

areas.
flU Dala Aru

6.3 A

System fullction SFC 21 FILL copies a specified, alue (source area) to B memo\)' area (dC'Slin,li on a~a) as often as required 10 fully overwrite the de>lination area . The transfer j, made in Ihe direction of a>cendlOg addresses (inerc-

'"

6.3 System Functions for Data Transfer

SHtom functlon. ror

d~' a

I ...."'r.. (LAD)
S FC 20

Network 4. Exampl e for SFC 20 BLKMOV

"'O

1--------1'"
PIIM 84 .0 BYTE 16 -

SRCSL K

R ET_VAL

f- FW 82

L ____C'O'o'c''e'''f-- PIIOB I24 .D8XQ ,Q BYTE 16 ~ '

N.twOrk 5 Example lor SFC 21 F' '""~-,,,;C;;------' _ ntact3 r SFC 2 1

f---------1'"
P#M 80.0 BYTE 1 -

eYAL

RET_VAL

f- FW 84 Bl K f- P#OB I 24.DSXI6.0 BYTE 16

s ." .,. function. for dot"

rr~",r<r

(FBD)

N work 4. .

Exa mple

lorSFC 20 B=',',.,o',O,,-,;;-__, ,
r
SFC 20
RE T_VAL D STB LK E NO "Input2" EN SRCBL K

""".'

f--

FW82

PIiM 64,0 BYTE 16 -

f- PIIDS I24.DBXO .0 BYTE 16

Network 5 Exampl. for SFC 21 Fill

-r=CC-o'oCCo,"'-----, '
"'nput3' P#M 80.0 BYTE I EN BYAL RET_VAL BLK

f- FW84

I- Pll'DBI2"DBX18.0 BYTE 16

Figu re 6.3

Exompl~.

for SFC 20 RLK1>tOV .nd SFC 2 1 FrLL

mentally). The following actual may be assigned:

paramet~rs

"" Any variables from the operand areaS for inputs (I). outputs (Ql, bit memory (M), anI! dala b locks (variables from global dato b locks and from instance data blocks) "" Ab.oluteaddressed data areas, requmng ,pecifi~ation of an A:'iY pointer "" Variab les from the temporary local data of data type Al\Y (special circum.'tances ap_ ply)

SFC 21 cannot be u8ed to co py timers or counters, to copy information from or to the modules (operand area Pl, or system data blocks (SOBs) , In the case of inputs and outp uts, the speci fied area is copied regardless of whether the addrc" es actuall y referenc e input or output modules Source area and destination area may not overlap_ The destination area is alway, fu lly overwri nen, even when the source area is longer than the destination area Or when the length of

'"

till: deStination area is not pn integer multip!e o f !h~ length oflh. S<,lur~c area. Example (Figure 6.3, N elwork 5): The contentS (If memory byte :\lli 80 is 10 b. copiffi 16 rimes (0 dala block DB 124, heginning DBB 16, 6.3.5 RcadlnE frum l .old Mf mory

addrts>~-d data area can be ~pi:Cjf;cd as A.'-Y pointer<;, e.l. P#DB1OO,DBXI6,O nYTE 64, in lhe parnmeters SRCBLK ,md n STD LK.

The S)'>ll~-m function SFC 83 READ_DRL read. d,,1.11 from" dala block pr..em ill load m~mory, and wrile~ Ibem ;"110 II data block preBent in work mcm()TY, TI,. Conlenl> of Ihe read data block are not chtln!'e", The " lock p"r.meter< arc <k!ICribed in Tabk 6.2 . The sySlcm funclion SFC 83 READ_ DRL "penlles ill ""y"ch.ronoullnode : you trigger <he read prucC50S with _i.gnal ~<ale ''I'' on parnmClcr RQ. You may only lCCes! <be read and "ril1cn data areas again when the BUSY plInunel('f has returned 10 Ihe signal ~tM le "0". A dala hlock is "sUlI!ly rresem rwice iu the ".er memory of a CPT.:: once in load m emmy ""dIh~ parr rele"anl to proc;:ssinl!: - in work melD_ ory. lfa dat.a block has the altrib",lc Unlinh>d, it is only pn.$<'nt in lmod memory (Figure 6.4). The StC 83 READ DDL only ream alue~ from L oad m~-mnry. The initial value5 of me dala C>penInds - wbleh may difT..,- from the IeNal value~ in wor~ memory - ar~ pr<>cnt Iter~ (see also CItaPler 2.6.S "BLock Handling" lmdo;-r '" D ata b lock< oftliue/onlinc '") , Complete data block~, e.~. nn 100 or "Redpc I'", variables from dal.l blocks, Or an abwlute

lIthe souree area is smaller than the target area, tht: <O\lr"U area i< written complw.:ly infO the t.aT~< area. The <~m"inin~ byt<,:$ of the IaJKeI area are not changed l fthc !lUTee area is lar&er than I~ UIl\'<.:1 area, Ihe target area is wrinm compll'tely; the Il'maining bytes of till: 'IOUl<'C an:a ~ ignored.
~,j.6

Writin g ioto Load j\.Iemor},

The i)litem function SFC 84 WRIT _DBL run. dala from a data block present ;" work memory, and wri\cl; them intO a dall block p1'CSC111 in load memory. Th" COllu:nI~ or lh~ read dala block""" nol ebangoo. The block Jll'ram~:e", ~ de;.cribed in Table 6.2 . The ~Y>'I~m function SFC R4 WRIT_DEL operales in asynchrooous mock you lriggcrthe read proce~~ with ,ignsl !tnte "I" on paramet~r R EQ. You Illay only "C"CSS Ih~ I"I'kd and writlcn dlla!lre"" aga ;~ whcn lhe BUSY pamm~tcr ha. mumC(j 10 the signal SIale "0". A o:bt~ block i. rn.ua.lLy pll'5em twice in the us...mt:JT>()ry of a CPU: once in load memory and lhe pan relennt to proceS~lni - in work memory.lh d" ... block has the anrihute U,,/inJ:l'd, il is only pr<;~nt in INd memory (fi!o:Ure 6.4). Tho; SfC R4 WRIT DilL only !\Cad., value. from work memory. The inil;,,1 value. of the data openll1ds - which may diffe< fr"m the o,IUIII , al""s in load memory _ aT<: pr.:<~m her~

16.

6.3 Sy"em FunclioM for Data TfUlSf....

UH' memO<)' of a CPU


Load ",.
08 11

WorI< m .m
A "normal " <!all block e",.ted u''''11 th~ P'<>grImminll devicc i. p.esml tv.; .. in ' be CPL". u"'"' m~' il i. com~l.tely pt ...,,\t in lood mommy, and lhe data ,.t.ti ,. 10 prc-:.S$inS or. pre=t in the work memory. i .. the data with which lh. Pr<li1"'lJn worh.

--- --~ --'. -1 :-...:::: I -- . ~


~DB 11

~~I

DB 12
\oj>

''01

"'''

""'01

A datI t>tock ere-aled U,inll the propnm1n& devlCC 000 ,,;th l~ s(lnbut~ (/nli~W is only "",oem in the CPU', load memory. Thi. data block doe> no< occupy .... y opacc in .... memory.

"'k

'" "
",,.,,

0813

).

DB~

------DB 14

-, --'
;-~I

A data blk crealed u>1II11 the SFC 82 CRF. ... DaL. i. prne!ll tn!oad m=><><)' and if u..li1l1:~ i.IIOIIC1".. ted .00 in w~'k m<nlOf)'. A data blk ptet.enl in ""'"' rno"""Y i,lbe template ac<:ordinll to which the " .... ""ta block is c, ,ed.

. ,

... dall blk cfealo<1 U.inll the SFC 22 CRE ...T_l)fI ur SfC 8S CREA_DB i. only pre"""t in ,I>.. CPU'. ,,'on: memo, y

(lee also Chap' .... 2.6.5 "Blocl: Handling" under "Oala blocks offitoelodine""). ContplL"1c data blocb . g. DB 200 or "Archive I"", variables from da\.o blocks, or an a~lule addrcncd da1a area can be specified D$ AKY pOinters, c.lI. PIIDB200 ,DBXO.O WORD 4. in the p~rnmcte" SRCBl K and DSTBLK , [fthe SQ urce Rre~ is smaller than the targM arell. the IO~1"Cf: are. i$ written completely into the 1.9.rget area. Tbe remaininll bytes of the target area ore nol changed. If the ""urce ""'" ;.. IA/'ier than

the tatyeI area. the large! area is ..TitlC11 com plt-Iely; tho: mnainmg ~ of lbe soun;e area are ia;non:d
Please OOIC: if you wrile imo a data bIO<.:I: in load memory (if the initial values arc changed), you change the checksum of the uier progra'''.

Please also 001: thaI the load memory usuully only permits a limited number of writ e opera tion! for pny.icai rcawn . Too frequent writing . e.g, cyclic. limit.> the .ervicc life of the load
~moiY.

'"

7 Timers

Timers

The timers allow software implementat;on of tim ing sequences such as waiting and monitoring time,. the mea,uring of inler>aI" or th~ generating ofpul,e,
The following timer types an; available, '" Pulse timers o
(> (> (>

cum.' " time value, whi~b you can fetch from 'he timer in eith~T bina!)' or BCD code .

7.1

Programming a Timl'r
Gcn~ral

Extended pulse timer; On-delay timers Retenti,'e on_delay tim"," OfT_delay timers

7.1.1

Rep reseutado n ofa

Tim~r

You can perform lhe following <.>peralioru; on a tim er:


:>

You can program a timer complete as box or using: individual program e lement>. When you start a timer, you sJX'dfy \he type of timer )vu want it to be and how long it should run: you can also rusct a limer. A limer is ~b;;ckcd by 4uerying its <lat us ("T;m~T running'') or the

Start a timer "'itb specification of the lime !l.c,,:t a tim<-r

"

-,. Cbeck (binary) limer sl8lUs


::>

Cbeck (di!<i tal) limer valuG in binary


Ch~c k

""
Tlmorbn' ( i n 'h~ .x,mpl.' pulse timor)

(d igi"'l) time value in BCD

LAD .repr.. s.ntation

feD

rcpwsentation;

, ='" e

r""", 0 1"'....00
S~P ULSE

Bm a

" r=

The box ior a ' imer contains the coherent repre,enta,ion of all timer vperalions in the fo rm of funct ion inputs and func'ion vUlput, (Figure 7.1), Above the box i, the absolme 0.- ,ymbolic a ddre of 'he timer. In the bo". as a header, is the timer mode (S PULSE mean, "S tart pulse limer") . Assignments f or th" S and TW inp uts are mmullltory, ",bi le ~ssigt\mtnts [Or th e other inputS and outputs 21X' vptional Indhidusl program elcmenh in LAD You can also program a timer using individual program ckf1)~ nts (Figure 7.2). The t;mer is ,hen stmt ed via a coil. The timer mode is in the coi l (SP - start pulse 'imer). and below the evil i~ 'he ,,,Iuc, in SHIl'.'fE fmmm. defining the duration. To reSe, a timer. usc \hc reset coil, and us. an NO or NC eont " cl to check the Slams of the t;mn. Fina lly. you ean ,,,ore the current lime va lue . in bins,), in a word opcr~nd using tbe "JOVE bo" ,

,
R

'-

Kame

D",a Type Doscription


B~c

Sta n inpu'
t mro,ion of linK- 'I"'cification

" " BCO " ,=,


,w

S5TLME
B~'

Ro.<t input Curren' time ,.,.I"e in binary Curren' ,ime ,-,u uo in BCD Timer .tatu,

WORD

WORD

7.1

~inllaTi.mcr

Stan u-.- by Of>'if,-ioa: ~ ( ...... coil " 'id> lim. mock)

----{SPri

"""", ,,,
TImer Dl*and

...

R.... rim., (I ..... roil)

""""""
~

--{R}---l
TImer operarld

Ch"d limor 1100UI


("0000'..". NC """,""")
Road lime at binory ....1"" (MOVE 1>0>:)

TIme< operllrld

II

~l ,ure

7.2 Individual Elemen .. of. Timer (LAD)

--'"
7.1.2

- 'N
'N

MOVE

'NO
OUT

Digital
opet1Ind

In d lvld u l l p rog ra m elemenu In }" BD

For incremental programming, you wilt find


the limen; in Ihe Program Elemenl Catuloll (wilh ViEW ..... O VERVIEWS [CIt! - K ] or Il'o"SeJl,T ..... PROGRAM ELE.\IENTS) under 'Timers"",

You can also program a timer using individual prOllram element' (Figure ;.3). The timer is
then ~ta" ed vin a simple box cornainin& the timer mode (SP - start pulse limer). Below the 'ooll is the value. in S~ T!ME fonnal. defimng the duration. To resct a 1imcr, uSC the reset 'ooll. You ean scan the SlalUS ofa timerdir~tly OT in ne,aled form wilb any binary ;npln. Finally. you can $tore the current time vabe. in binary. in word operand Wiing the MOVE 'ooll.

Sf. rting,. TImer

A limer stans when the result of the logic oper_ allOn (RiO) c hllIIie5 before thc itart input or before the rum coillbox. Such. si&IIB1 c hanl!<' is always requ~ to stan I timer. In the cascof In off-delay limer. the RLO mUst cllange from

s..rt timer by .peciryina limo (...rt ooil wi'" Llm. rno:xIo)


Duration
Reid tIn><r (reset coil)

TImer op&ralld

~ TV "
--i

I
I

,","-r operand R

Cboook Llmer ....... (d....,. or IICpICd biuty iopuI)

11....:1 ""'" tiS bt....,. ,...100


(MOVE bo.)

~"P"Iand F I~nr.

--'"
TImer opII"'nd

=:d

ON

Me" 0"' t- DigtIaI opet8nd


' NO

'N

7.:l Incli"d",11 hl.menu ofo Tim.r (FBD)

Ti",~""

" I" to 'W '; all "Iher tim~..,; .llan when goes from .'{)" to "I".

Ib~

Rl. O

Struct ure of the <lun do n nf time >lIlu e ImeIrullly, the dunltion i> composed of the time \lIlue and the lime base: durat;on - time "1I1ue >< lime base. Thc dunuion is the tim~ durini which a timer i, "cti",-, ("timer running"), The lim~ ,,.Iu~ rcpn:scnts the numl:><. of cydcs for .... "'hich (he timeri;; 10 run. Th'" time base dcfine~ Ihe in'e...."ol al which the CPU i! to cbange the time ",,1\10 (Figure 7.5). You can,.]>o build up I dural1l)11 ohime right in

You e .... shin. limer in on~ of five diff",,.,,nl mode. (fig ure 7.4). There is. h",' C' er. nO poinl il\ (, . ing any Irvcn timer in "'. ore Ihan nne

mOO,
7,1.3
Spe<:Jf)1 ng Ihe Du n don
ofTIID~

Tb,' limer ,wopls the value bdow Ibe coil!bo . or the v:tluc 111 ;npul TV as me duml.on. You (~n $p:cil'y Ihe durat;on as COD>taol. L. word operand, n. as vKri~bl . oflype SjTJME.

Spc<:i/ying Ihe durol;on u.t Constant


SH lMEl# lOs
S5T1!lm I Om~

a ",,,r<! oJX'nmd. The .I maller the time ha,c, the mo,"" ~ccuralC the mct .... 1J uration. f or c~nmpl~. if you" lnt 10 implement" ,luraIion of one second,
)'OIl

DU!"lItion of lOs Dunmon of 1 miD .... 10 ms

c1llt make one Df tbrc(: specificalions: Timc


~~

The dU,...~l;"n;1 .pc<;ifled in hours, minules, omb and rnilli"ccolK!J. Th", range exICO<.J, from SSTL\1Ell'I OrtIS 10 Sj'l"ThfElf'.h46mirI3o.I {which corn--sponds Il> 9990 'j. )ntcnnediate valu~'"S are roun ded l>ff In 10 II". Ynu Can u,e 551'1ME '" l>' SSTII' lO idcmify II constant.

""c-

Durotion - 20()] I>:~ J)uratiOD - IOIO""~ OurohOD - 0100t,,,,,

100m. TIme base 10 It1$


on~

Timcb>o~e

Th. lasl 01 Ihese is the prcfcmd ca,e.

;" this

SIHCI/Y;"K lire " .. ration (f$ Ql"'rand or '-orioble


MW20 Won! ""erand comai!1ing the duration Variable o f dala ty~ SSTIME

T he yaluc;n the word OJX'.and mUSI corre'pond to data type SSTL"'1F (sec " Structure of the dumtioo of time "tlue", btlo""),

When Slan ing II timer, the CPU ,dop!!; the pro!!rammcd (ime valuc , The opernlin;:: .ystem upd1IU Ihe timers at fi"ed irltcrvab and indepcndendy of the uscr program, thai is. il de..:remenb lhe I1me va!ue of "II active lllJ'IeB as per the lime b",e v,'hcn 3 timer rcachc. zero. it has run d""",. Th~ CPU then ",",s th~ timer St~lL!S (oi1O"1I1 state "0" or"' 1~. dependiDi on the mode.

"" " " S],,-xr


~

\0 r.tart the-

"",or os

&art .!gnal

Pvil< ,;"""
i!l<tcndcd pul ..

PULSE

F 1:=3
=

E
b 1----=1

,
~

"
"

Ot,deloy tun<r
R.... nti'e OlI-dd.y \"'10'

S_ODT
S_OOTS

M S_OFFO'J

on:.!<l'

I"".,

I=-- '

F- r

172

Th\4I vel ..... In ace

riffle base In Bee

2. 1 3. 10.

'-0.1 .
oh~

0.0\ s

Flit"'.

7.~ o..criplion of the

!JUI in

DlII'Ol;OO

or "typc", of timer) and drops nn funher activilies "nhlthe limer i~ !'CStancd. If)'Qu specify:l dunuion of zero (0 ms or W.l6aOOOO) when Slllrting" lim ...., the limer rt'mams .ctiv~ unlil lhc CPU has processed Ike Urn.,.,. and discov_ ered Ihat the time has elapsed.
Timers are updated Bsynchronously 10 the progrom ""an. As a rosull. it it possible thai lhe time sta rns at the beginning of a cycle is different tllan al the end of the cycle. If you usc Ihe timers a1 only One point in lhe program and in the suggested order (5 ~low). \he as)'nelLIe>nous updating will prevent the O<,:~ulTCl1ce of malfunctions. 7.1 .4 R... crtingA Timer

o r with an l\T contact, The resultS of a check with an XO contact or with OUtpul Q differ according to the type of timer (~the descriplion of the timer ty~s. below), All is Ihe case ,uth inpulll. for example. I check ""th an N'C C011l11Ct produces exactly the opp<)'>ite cbcck resuh as the one produced by a che<k with an XO coma.1. Output Q need not be used at the timeT 00" Chec k.lng the timer
~lRtUI

( FI:I[

LAD: A limer is reSe! when power flows in the resct inpul or in the reset coi l (when the RLO i. ","), As long as the limer remai ns I'l:SCI. a scan with an NO oontacl Mil return ''()'' and a scan with an NC contact will return -I ~.
FB[): A timer is reset when a MI~ is present at the reset input As IODi ., the timer remain.< reset, a dIrect scan of the timer StaTUs will reTUm ''0'' and a negated ~CB n will return "I" .

TnI' timeT s:atus is aVll.ilable at output Q of lbc timer box. You can alS<) check the timer ,!DIUS with, binary function input (com:sp< .lIIding to output Q). The remits of' timer d .eck depc:l1d on the type of timer invol\'ed (8 the dC'SCription of the timer ty~. below). Output Q need not he used at the timer box ,

C h ecking the time v.Jue OUI]NIS BJ and BCD provide the timer's time valU( m binary (AI) 01' bioary-coded decimal (BCD). It i. the value 'Umllt at the time oft~ 'hecJc. (if the timer i. acnve. the time: value ~ counted from (he set value down towards zero), The value is slored in the spe<:ificd operand (tmnsfer as wi1h a MOV E oox) , You do not need to use lhese outputs at the limer box,

Reffttini of a timer Jel' Ih8t timeT and the time base l<> zero, The R in put at the timer box need not be wired,

7. 1.5

C h..:king a Tlmtr

Direct checki"g ofa time Wi/lie


The time
~'alue

is "'8ilable in binary-coded

C hN k.lni Ib timer sta tu, (LAD) The timer staCUS i. found It outpul Q of the limer oox, You C3n also check t~ limer status with an NO contact (corresponds to output Q)

dlJIWIl. and can be ~trievw;n this form from the timeT. In.oo doing, the lime bru<c is lost and i. rq,laced with "O~. The \'8luc COTI'CCsponds 10

a positive Dumber !II N T fannat. Plea", note: it il the lime value thaI i. checked. oot the duT3.-

7 TIm .....

t;on! You can also program direct checking ofa time value with the MOVE box .

diately reset. The subsequent timer check wilt fail to dett !he f""l that the timer was started. 7.1.7 Timer Box In a Rung ( LAD )

Coded c/.cck;"g of a lime value


You can also retrieve the binary time valu~ in "coded" form from t h~ timer, In this case. both the time value and the time base arc available in binary-coded decimaL The BCD value is structured in the same way as for the specification of a time value (see above). 7_1.6 Sequ ence of Timer Operations You can cOnnect conta~ts in series and in parallel before the Start input and the reset input as well as after OUtput Q. The timer box itself may be located after a Tbranch and in a braoch that is dire<otly connected to the left pow~r rail. This branch can also have contacts before th~ start input aod it need not b~ the uppermost branch . You can find further examples of the rcpr~.en tation and a!Tangement of timers in the Ba,ic Functions" program (FB 107) o f the LAD_ Book" library that you can download from the publisher's W~bs;te (see page 8).

'When you program a timer, you do not need to use all the operation> available for it. You need use only the operations required to exeeute a particular function . Nonnally. these are the operations for starting a timer and for checking the timer status.
In order for a timer to behave", described in

th is Chapter. it is advisable to obsCI'Ve Ihe fol lowing ordcr when progranuning with individual program elemenl~:
1> 1>
1> 1>

7.1.8

Ti mer Bo,", In a L-ogjc Cir cuit (f BD)

Start the timer Reset the timer Check the time value or the duration Check the timer statu,

You can program b inary functions and memory functions before the start input and the resct input!i'l well as after output Q. The timer box and the individual e lements for starting and resetting the timer may also be pro_ grammed after aT-branch. You can find further examples for the repres,:nlalion and arrangement oftimcrs in the Basic Fum,tioru;'" program (FB 107) of the FBD_ Book' library thaI you can download fTom the publi.sMr's Website (sec page 8).

Omit unnecessary clements when programming . If you observe Ihe order shown abc,,'e Illld the timer is started and reset simultaneously", the timer will start but will be imme-

'"

7,2 Pu)""Tuner

7.2

Pulse Timer
puls~

much longcr the limer would have run had it not been prc-maturely inlcnuptcd. ReHnlng pulse limer The resening of a pu4<c time hM. 'l.alie effect. and takes priority over the Slanina of a timer
(Figu .... 7.6).

SIArling a

timor

The diagram in Figure 7,6 descri~5 the charac

teristics of a timer when it tS staned as pulse timer and when il is ~t. The <kscription applies tf you o~ .... c the order sltown in Chapter 7. 1.6 "Scquence ofTimcr OpcntlOns" wilen programming with individual elements (starting ~rorc rescning ~fQre cheekina).

<D

When the signal st~I" al the timer's ,Iart inpul changes from "0'" 10 .')"' (positiye edge). the timer is started. It runs for Ihc prolilrammed dunl1ion loll long as the si gnal state althe stan input is "1 ~. Output Q supplies signal "at" 'T' as long as lhe IImcr runs. With the stan VlIlue as Ihe staning poinl. thc time value is counled down loward zero as per the lime base.

Sigu.al.nate ~I~ al the reset input ohn ac\h'c timer resets that timer. Oulput Q is then "0". The rime v.lue and the time base arC alw set 10 zero. If the ,igna] stalc 81 Ihe ""el input g~s from '" ]" to ~O" while the signal stille al !he sel input is sllli "I ". the limer remains unaffected. Signal Slale "I" at Ihe reset inPUI of an in.eli\'e timer has no cffect.

(J)

If the signal.tate at the timer's start input changes 10 '"0" before lhe lime hali elapsed, !he timer 510)"15. Output Q tben iii"'" to "'0-'. lbc time v.lue shows how

If ~ signal state at the ~pn input g0e5 from "0" to " J"' (posilive edge) while the rcsel5iillal is slill presenl. the limer staru bUI is immediately "<'set (.hown by a line in the diagram). If the timer slatu. ched was programmed after the reset. the brie f Starti!lg of the timer doos not affect !he cbeck.

<D
SIgnal state at

,1
I , ,
I

<l>

\he SUlrt InplJl Slgne l .tate at


I ha Ruel inp ul

n
0

~ '-,

I
n
I

n
I I
I

I~d<n!>:>n

f lau .. '.6 &h:tvion.l Cb.ratlmllic. ",hell Slanillj and ROK1Iln8 _ Put.., Tun ...

7 Timen

7.3

Exte nd ed Pulse Timer


~:<I ~nd~d "nl.~

"hh Ihe prognunm<:d lime \lIluc (the tim_ er IS ""retriggcred"). It can be ~slaned any number nfl imes witbmIl finol elupsing.
Reutt!.n .: M n
u l~Dd \'d

Sf.rlhl&.n

l imn

The diagram in Figure 7.7 ~nbes the belLa,'ioml charnc"tC";~licl "f Ihe IUn<:T .ncr il i. >Iartcd nnd wh en il i. re<;et. The do<;cripliun applies if you obs<';C'o'e Ihe urder ~hown in CharI"'" 7 ,1.6 ""Sequence ofllmer ~rions" when pr~nuning " 'ith individual clements (tllIn_ ing befon: rescuing befon; checking).

p ub e l imn

Thc resenin g of an extended pulse lin.e-r ha. ~ 'tanc dfcci. and take. prinrity o\'~r Ihe srnnin& ofa limer (fib'UrC 7.7).

00 SIgnal stale "1" II the timcr'~ re.;et input


"hile the timer is n.nming resets the lim<:T. A chc-ck for .illnlt .tate "1" (Iimer stal\ll') retUrns a cllc-ck result of "Q" for a n:~et timf;!". Th~ lime \"l'I!ue and Ihe time base lite also reset LO 7em.

0& When

the si,,'flill "ale ~ I Ihe timers Slurl input goc~ from ""0" 10 ' "\"' (posilin

edge). the timer i~ slarted. It runs for thc I'fUKfl'mmeu d1l11ltion. c, en " hen the si&Dlil , tale at ll1e sIan input chan!,es back 10 "0". A che<::k fur , ign.,\ StlW,' ""I"" (IUncr Slalus) rew.ns a .hc.:: k result of .. ,"" os long as Ille lime-r i, runninG'
Wilh Ihe slsn valu. a.< slanmg poinl. the li me value is c" < ,,,led down IUI"am. uro us JX"T Ihe lime base .

o o

A "I" at the n:;Ct inpm of an


er hll.~ no e ffe<:l.

; nactiv~

lim_

If the signal stule a. the stan wpul goes from "il" 10 ""I" (positive edge) " hill' tb~ Timer is running . hc timer is reSl3r1ed

If the signal ~lllle "t the start input ~oc.'$ from -0-- w "1" (po:o!iti"e cd"...,) while Ihe rest! ~igna! i. presenl , th. limer is started bUI is inunedial~ ly rcset (indical~d by H Hne in the dia gram). If Ihe limer s"'luS cbeek is programmed after Ihe "'>cI. the brief staninJI of the lim .... ~ nol aff~'CI the timc"T clled:.

0
SigrwIltate 1tI.. Start Input

a.

" -1 - -

. ,
I

0
I

-"

r- r---.

Signal ,18 1<' 81 the A.aHllnp \ll

0 ,

""" """'""
(iI"\temsl)

,
I

I I

DO /

,
I

T imer status (check 10< "1 -)

I 0I , , , IP P I ,
0
/

I I

"
I

.;-'i
I
I

I p , I 10 I

I~
/

,
I

I I
1 PtogrIJIr)ItMd dunIJon

no

7.4 On-nday Timer

7.4

On-Delay Timer
tim~r

lim e value shows the amount of lime still


r~ m" m mg ,

St.rting a n on-delay

Rescttinl;:: aD

OD -dcJu~'

timer

The diagram in Figure 7 ,g de>cri~s the beh",'i"ral characterist ic, of th~ timer aft~r it is slarted and Wh~D i\ i~ m;~t, Th~ d~'~Iip\ioD applie. if Y"u oh<eF>'e the "mer sh own m Chapter 7.1.<5 "Sequence of Timer Operation," wh= programming with indiv idual elements (starting ~fore rc;eUing be rore "h."king),

The ,"""erring of an on-delay lim~r ha, a ,talic ~ff~ct. and takc. priority ovcr the starting of the
l im~r (FiJlur~ 7.~) ,

CD

When the si,,'11al stalC a\ \h e timer's Slart input changes from "0" to " I " (posi!in e<lge), the ti mer is started. It run, for th e programmed dur"tion, Checks for sign" l state ' 1" return a ehc"k res ult of "1 .. when the tim e has duly elapsed and signal ,me "I " is slill pre,ont at the start input (ondelay) , \"'i lh lhe sIan valuu as ,t.rung point, the lime v,<l ue is counted down {,,"ard, zero as per the time b ose.

Q);6l Signal ,tate " I -. at the resc{ input reset, th~ timer wh"u,er i{ is running or not . A check lor signal s!Ole "I" (timer , taru,) then rctums a check result of "0" , ev~n whe'n {he limer is n<>l running and si gna l stale " 1";\ still present at the start input Tim~ " alue and time base arc als-<> set to uro A change in the , ignal statc a\ the reset input from ""I " to ''0'' ",h , lc , igna! ,tate ' "I " i, still pre'~m at {he start inpu1 !"" no effe<: t on the timer.

(2)

If \he s ignal state at the Hart in put chang., tium " I" 1C> "0"" while th~ timer is running. the timer SlOp" . A check for si gn al state ' T ' (tirn ~, statu,) always remms " che~k result o f " I"" in such cases , The

If the signal Slme at th~ , tart input goes from "0" w " I" (positive ~dg~) while Ihe r~,el signal i, prc&ent, the timer SUtTh, but i~ immediately re.,el (i ndic at~d hy a line in tho diogram). Ifth~ timer siarn., che~k is programmed aIler {he ,"""el, The brief SIarting of the {imer does not aff~cl the check.

Sig na l state at the Start in~t Sil/nal state at {he Reset input

TImer running
( i n l~r nal )

-, ...: ..
'., -. , :J
P'OIll'!'l mmed d"I'!'ltion

Timer status
(d1eck fer ' j ' )

7 Time"

7.5

Retentive On-Delay Timer

Sta rting a retellli\"C on- dela,' rimer The diagram in Figurc 7.9 des ~ ribcs the hehav. ioml Characte risrics of the timer after it i, started and when it is reset. The d~s,:ription applies if you oh<erv~ th~ order shown in Chap tcr 7.1 .6 "Sequcn~~ ofTim cr Opera\ions" wh e t! prognunJlling with individua l dements (Statt. ing before re scning before ch"'-'king).

Tfth~ sig nal stal~ al tlle <taIl in pul changes from "0" to "I" (positive edge) while the limer is running . the timer restarts w ith Ihe progranuned time value (the timer is ",triggered). It can be restarted any number of limes witham firsl having to run d"wn.

Re,ctting a rctcntiYc on .delay timol' The reselling of a rctemive on-d elay timer ha. a static e ffec t, and lakes priority over the starting of the timer (Figure 7.9).

Of)

the s ignal state at thc timers Slart input goes from "0" to "1" (po, iti,~ edge), \he timer i, started. It rul)S for the programmed dmmion, C\"~"ll when thc ,ig' nal state at the smn input change. back to ''0'' . When th~ time ha< elapsed. a check fo r si gn al state '" I" (timer statu,) returns a check rcsult of ,. J" ,..,gardJe" of the sig nal stale a l Ih~ Start inp"l. A check resull of "'0" is not rernmed until the limer has been res~1, regardless of the signal :;Iate at the <Ian input. With the staIl value as slartin" point. the lim e value i ~ counted down towards zero as per th~ time ha<~.

Wh~n

00 Signa l ,tat~

"1" al thc re,et input Tesets th e timer, regard less of the s ignal <tate at the ,Ian inpm. A eheek for signa l stal e "j . (timer slams) then return.' a che<:k result of "0". The time value and the lime bas~ arc al,o ",t to zero.

If the , i~'Ilal state at the start input goes fr(>m "0" to "1 " (pos itive edge) while the I\."sd signal is present, the limer ,tam;, bul is immediately r,,,ot (indicated by a line in the diagram). Tr the tim~r statu< check is programmed aftcr the reset. the brief starting of the timer ha, no effe<:1 on the check.

0
Signal stale al Ih" Start inpul S ignal stat.. ,,, the Reset input T imer running (intemal) Ttmer status (check/or " t ")

i 'l
I
I

" rl--j H o I I I , , ID ,
I I I

n
D

p 'l
I

I 0

I
0

iI
I

I I

I
I

I I 0

I
0

" I "II n
I

I I

D 0, ,
I

PM;Jt8mmftd dum /ion

Figure 7. 9 Bohavioral Characteri<tks "hen Startiog and R ~. ottinl1 an R<tenrin On-I).lay Ti mer

7.6 OfICDclay Timor

7.6

Off-Delay Timer

staned onl y when there is a ocgalivc ,,,Ige at the stan input Resetting a n off-del ay Ilme r The resetting of an off-delay timer has a static effect. and takes priority over the starting ufthe timer (Figure 7.10),

Starlin): an off_delay d mer The diagram in Figure 7.10 d~scribes the behavioral characteristics o f the timer after it is started and when it is reset . The description appli~s i r you observe the order shown in Chapter 7.1.6 "Sequence of Timer Operati"n," when prognlIIlIIling wilh individual element. (,tart_ ing before reselling before checking) .

G:xl.J The

timer starts when the ,ignal state at the timer's start input changes from " 1" to "0" (negalive edge) . It mm for the programmed dumtion. Checks for signal state "1" (timer Statu.) return a check result o f " 1" w hen Ihe signal stale at Ihe stan input is " I .. or whet! the limer is running (off-delay). Wit MIhe start val ue as staning point. the time value is counted down towards zero as per Ihe time base,

Signal state "]"' at Ihe timer's reset input whi le th~ timer is running resets Ihe timer. The check remit of 8 check for signal 'tale" j" (timer status) is then 'ir'. Time value and time hase are also .,etto zero ,

(@S ignalstate ' l at thestart iopu(andalthe reSCI input reSets the timer's binary o utput (a check for signal state . \ .. (timer status) then returns a check result of "O). If the si gna l Slatc at the reset input now ~hange ' back to "0", the timer's output once agaio goesto "l ,

(D

IflMe signal statc at IM start input change, e from "0" to "I " (po,itive edge) "'hile the timer is running, Ihe timer ;s reSet. It is re-

If the signal state at the slart input goc. from" I " to "0" (negative ~ dge) while the resel signal is pre sent. the timer starts, hut is immediately reset (indicaled by a line in the diagram). The check for signal state " 1" (timer status) then rctums a cb~'Ck reo sult of"O" ,

Signal state at the Start inpUt Sig na l state al


the Resel input

r'I
I
I
I

,.

I
I

h r
n
dUr&tlOn

h
n

r'l
nl
n
I I
J
,

Time r ru nni"l) (intoma lj Time r status


(check 10<

-" j

I I
P~m_d

I I I

In

I D I

Figu ", 7.10 Behavioral Charaoteri" ie. when Slattin g and Reninl!" .n Off Delay T,mer

7 Timers

7.7

lEe Timers

Th~ IEC timcT'< a,.., integrated in the CPU's op;.;rating system as sy,tem function bloch (SFB~),

The full"wmg timeN are avai lable on ,ome CPUs :

Outp ut .10'1 supplies the durati on o f time fur outp ut Q. "fhi, duration begins at TOOs and en d, at th~ set durati on PT, When PT has dap~cd, ET remain' , et to the elapsed tim e until input IN goes back to " .T. If input TN goes to "0" before PT elapses, output ET goes to T#O. the instant PT d ap'cs . To rein itialize the timer, , imply start it with PT '" TOO., Tim e'r SHt 3 Tl' is active in START and RUN mode . It i. reset (initialize<J) when a cold "tan i. executed.

r- SFB J TP
Pulse timer
~

SFR 4 TON On_deby timer SFB 5 TOT' OfT-delay timer


~harac t~Tis

7. 7.2

On-Oolay Timer SFB" TON


th ~

Figure 7 ,11 sbows the b<:havioral tic, ,,[these timers

T he,e SFBs arc c"llcd with an in,rance data block or uS<."d as I<><: al in813nce~ in a fun <:tion block. Yo u will fit>d the imerfacc dcscripli on for offline programming in the standard library with the name Siandard Library un der the program Svslem Funclion Blocks , You wilt fin d examples tor the calt in funclion block I'B 107 ofthe "B a,i~ runctions" p rogram in the " LAO Book" ami "FBD Book"librarie, that you can download from tb~ publi ,her's Website (,c~ p ~ge 8)

Th e IEC timer SFB 4 TON has listed in Table 7. 1,

paramNe!'s

Th~ tim ~r stan< when the RLO at its , tan input changes from "0" to "I ". Tt runs for th e programmed durJlion, Output Q ;;how. s ignnl swte " I" wh en the time has elapsed an d a. long as the si gn~) state at th~ ,t<m input remains at " I ". Iflhe RLO at th e stan input changes from "I" to "0" before th~ time has Tun out, the limN i" n;set. Th e next positive edge '""<tan, the timer.

7.7. 1

P ulse Timer SFB 3 TP

IEC ti me, SFB:3 TP has theparametNs list ed in Table 7. 1, When the RLO at the timers stan in pUl goes fwm " 0" to" I", the timer is starred, It 111Il> for the programmed duration. r~gardless of any sub"'quent changes in the RLO at the stan io ptl1. The signal Slate at OUlpUt Q i, " 1. ~s luni as the timer is Tunning
Tloble 7. 1 l'aram<ters for the TEe TlIllers

Output ET ,uppli'" the duration "ftime for the timer. This duration b eg in' at T#Os atld ends at ,c1 duration PT, When PT h as elapsed, ET remains ,cl Io the e lapsed time until inp ut IN c hwges b3Ck to ''0''. If input IN go,,, ID "0" before PT e lapse8, output ET immediatdy goes 1D T,.o(ts, To
~
r"inil i ali~c th~

limer, simply start it with PT

TItD"

SfB 4 TON is adiv~ in START and R UN mode. II is T~set on a cold sinn.

7.7.3
Th~

Off_Delay Timer S,r B 5 TOI'

~.~",;~ D ooclaratioo
~''',~'.

Ue"" ripliG1l
S,~rt

TEe timer SF'B 5 TOF hu, the parame ters listed in Tabl~ 7 1
Th~

TN

PT
RP

INPUT INPUT OUTPL'T OUTPl'T

input

TL"ID

Pulse knl(th or delay durat100 Timer >taWS Elop=:i timo

ET

TlME

signal Slate at output Q is " )" when the KLO a( the limds stan input change, from "0" to " I" . The tim~T is staned wh~nthe RLO at the ,Ian input ch~ng~s back 1D "0' , Output Q retains . igItal ,tate "1" as long as the limer ru n . Output Q is reset w hen t;, e (ime h ao clap,ed. If \he RLO ,01 the stan inp ut goes back to " I"

7.7 lEe Timers

Signa l slat.. at the Stan inp ut IN Tim.., status a ol SFB3TP Tim er statu. a of SFB 4 TON Tim er statu. Q of SFB 5 TOF

,
I

, hr ,
I

.__ t ___

,, I .
tl

, ,

r't Prrx;ramm<>d duration

f:

,-

- ,before PT has clap >cd, output ET S""s to T#Ck .

~
;m medi a t~ly

Fi ~ur<

7.11 n.haiQra! Ch"",,teru.t iol of !he TEe Tir.lcr.

before the time ha.' elapsed, Ihe time i. resc" . and output Q remain, at <>\".
Output ET supplies the duration "ftime for (he limer. This duration begins at T#O. and ends a! set dur"tioD "PT. WhCt1 PT has elapsed. ET remain , Sel tn (he elapsed tim " until input IN c han&~s b ack to "1". If in put IN goes tn '" I"

Tn rein itial i z~ the limer. sim ply art the timer with PT = T#O,. Sfl:l 5 TOF i8 active in SD\RT and RL"N mode. II i, re,~t on a cold -"art.

'"

8 Counters

Counters

Countcrs allow you to use th~ CPU to perform counting ta.,h. The counters Can coull! bDlh up and down. The counting range extends over three decades (OOO to 999). The counters a,... located in the CPU', system memory: the number of counters is CPU-specific. You Can program a counter complct~ as box or using individual program clemel\ts. You Can scI the coum to a specific initial valu e or reset it. and you can coum up and down. The counter is scanned by checking the COunter Status (zero or non-zcro count value) or the cUITem count. which you can retrieve in either binary or hinary_coded decimal.

CBU Tl '<C

box

(inltte eutnple: updown countc:r)

LAD ",presentation

C ounter op ... and

S_CUD

=, =,
FBD representation

CO

00

Oy CV_BCD

,y

=
-

'" , =
00

Counter 0 . " SCUD

8.1

Programming II Counter
"Kar.lC

ev , =
OU

Cy CV_ BCD
Q

= -

Oat>. Type Description

You can perfonD the followin g operations on a coumer:


I>

Set counter. specifying the count value Count up

OD

'>

> Count down


I> I> I> I>

,y ey ey 'CD
RP

'OOC BOOC 'OOC


WORD

Up COlmt input

Booc
WORD WORD

Reset cOlUlter Check (binary) counter status Check (digital) coum in binary Check (d ig ital) coum in binary-coded decimal

BOOc

Down Count input Set inP<i' Pre"t v"luc Reset input Current nlue in bin"')' Cum""t Ya[ue in BCD Cou:,t.". statuS
Bo.~

FIgure 8.1 COUllter III

R<p.resentallOn

assignments for aU other inputS and outpUtS are oplioIlllI. Counter boxes are available in thl"C(' versions: up-dowI\ COuDler (S_ CUD). up counter only (S_ CU). and do .... n wunte r only (S_CD). The d iffC'nces in functionality are e~plained below For incremental programming, you can find the counters in the Program Element Catalog (with VIEw ...... OVERVU'WS [Crr[ _ K ] or I"ISERT ...... PROGRA.\t ELEME~' rS) under Counters.

Repres~nlat[on

of a counler as box

A coumerbox contains the coherent representa tion of all counting operations in the form of function inputs and function outputs (Figure 8 .1 ). Over the box is the absolute Or symbolic address or lhe coul\ter. In the box, as header. is the counter type (S_CUD stands for "up_down counter"). An assignment is mandatory for the first input (CU in the example) is mandatory:

'"

8.1

Prugr~mming aCmlll!er

C"unt "J> funetlon

CoUnteroperami

(wunt ur ooil)
Coon! 00"" fun< tion (COunL down coil) Sct = lcr with ,-Ill,," uf cum;nt oount (""t counle>" "eM) with c.-.un,)

---{W)--l
Counta< o...,...,.,,:L

---{co)--l
Coo,,"'r ope"',,!,!

---{~)--I Count VlI1u.


Courrter operand

R<t Cco.Ultcr (rcM:t coil)


(1)<4

---{R)--j
COLmta, """",00
Counter ope"",d

(NO """""'t, NC contact)


R""d coun L.. bi nary valu<
( MOVE box)

t""""" ".ru,

II
MOVE

~
'"0 0"'
Digital operand'

CountS< op""md
Figur~

'" "

8.2 Individua l Ilictn""" "fa C " untor (LAD)

R~pn:"entall'... of a couot.'r u'in~ indhidual elemenl< (LAD)

tacts before the inputs and need not he the uppcrmo,t branch. You can find flU1h~r ..,.amples of the repTcscntat;on and =ngcmcnt of ~ountcrs in the "'Rasic Function," program (FB lOS) of the "'LAD_ Book" library that you can downluad from the publi'her's Website (sec page 8).
Represen tation of a counter usill~ illdi~idulll ~J~m~"L' (l'II U)

You ean also program a counter using indi vidual elemem, (figure 8.2). Setting and counting mc then done via coik The set eo un tc-r ooi I contains the counting operation (S C - Set Counter); below th~ coil. in WORD formal. is the <.:ount va lue to be u,.d to sd th~ emmler. In the coil. for count ing. CU stands for count up and CD stand s for count down . U<e the rCSI't coil to reset a counter a nd an NO o rNC ooman to ch~ck the status of" counter. Finally. you Can tTan.f,T tlte current count, in binary. with the MOVE box Counter bus i.o. M run~ (LAD) You can arrange contact> in ,.,ries and in parallel ~fore the counter inplll', the stan input and th e reset input as well as a[kr OL/tp ut Q. The counter box maybe 1,laced af\~r a T_branrh ur in a branch that is directly conn~cted to the I~f\ J>Ower rail. This branch may also havc con-

You can also program a counter u sing individual elements (Figure ~.J). Setting and ~"unti.o.g are then done Vi3 simple lxl_<~S. The set COu"t~ box contains the countT in s operation (SC = Set Counter); at inpLlt PV i. tlte count valu~, in WORD format, is the count valuc to be w;ed to gct tlt c countcr.
In the boxes for countins . CU stand. fur coun t up and CO stands for count down. Use the reset bo.~ 10 ,""sct 3 counler and a direct or negatcd bin ary function input to check tbe status of a counter.

Finally. you can tr..", k r the current count, in binary, with the MOVE box .

'"'

S Counle"

Count up r"",tion (cuun' up coil) Count d,,",'n ruuc, i"" (couo' cIowo coi l)
S ct 0"000'0< with valuo of current count (set cuunter coil w ith count)

, Counter ope<a nd --1 CO ,


Counter opo;a n<!

--1

C"

Coomer op9ran<i c oum value

~ PV SC

I
I

Re",' counter ("""" coil)


Chee ~ counte, .tatu' (d ir"'t or nC"tc-..J binary inpu')

Coullt..,,- operand

--1
CoI.l nte, "pe ran<! Count".. o.p<j,and

==:d
r-

f-

Read oount .. binary v.lue (M O VE box)

COtlfl!", operam:!

'"
'"

MOVE 0 ",

Oigital operand

'"0

Fi\:u .... 8 .3 Individua l F I. men" "f a Counter (FIID)

Connt{"r box in

logic ci,-.,u it (V8D)

You can arrange binary fun~tion' and memory fun ctioll' ~ fore 1he counter inpU(s, 1he start in put and the reset inp ul as "el l as after oolput Q. Thc counter box and the individual e lements for counti ng, settin g a countcr and resetting a counter may also bc pla~ed afler aT-branch. You can fmd rut1her examples of the represen tation and arrangement oI counters in the "Ba"i ~ Function s" program (FB 108) of the '"FR D_ Book'" library that you can download fom' the pub lisher" Web , ile ('co pago 8). Sequence of co unt in g
op ~ra tlon s

{he coon1~r to it, initial count. down conn lin g, and checking lh~ "oumer stalU,. Tn order that a counter's behavioral characteristics ~ as descrihcd in th is chapler, it is adv isab le to ob,erve the fnllowing ordcr when pm gramming with individual program dements:
I> I>
[>

Count (up or dnwl1 in any ordcr)


S~\

cOunter

Re>er conntcr Check count Check countcr ,tatu,

!> I>

When p rogramming a cou nter. you do not need to use all I ~~ operation_ available for that COlm!cr, The operations requ ired to carry oUi the desi red functi" ", ore enough, For cxampk , to program a dmvn COumer, you need only program_ the operations for setting

Omit any ind ividua l e lements that are not required , if countiug , setting. and resett ing of thc emmtor take place "simultaneously" when the op<:ralion, arc progranun ed in tbe urdC'" shown, tbe Count will flfSt be changed accordingly before being reset by the re set operation wbicb follows. Tbe ,ubsequ~nt cheCk will therefor~ ,h"w a count of zero and counter statuS "0". If counting and ,etting takc place "si mu ltaneou,ly" when the operati ons are pmgranun ed

'"

M.2 Selling and Resetting Counters contact will return a check resu lt of "" 1". Reset_ ting a counter sets its count to "zero", The counter box's R input ne~ not be connected.
R e~ettin g

in the order shown, the count will fi t sl be c~anged accordingly before being set to the programmed count value. which it will reta in for the remainder of the cycle.

The order of the operations for up and down count ing is not sign ificant.

cou n t ers (FB D)

8.2

Setting and R ese tt in g C ounters

Settin g countH.
""{l"

A counter is sct when the RLO changcs from to '"1" bcfore set input S or before the .et coi l or set box, A positive edgc is a lways required to sci a counter,

A cOunter is reset when a ""I" is present atlhe reSet input. Then a direci scan of the counter status will return "0" and a negated scan will return ""I"' , Reselting a counter sets its count 10 "ze ro"' . The counter box's R input need not be connected.

8.3

Coun ting

" Set counter"" means that the counler is SCI to a stnning value. The va lue may have a range of from 0 to 999 . S p eci fyIn g t h e conn t I' alue When a counter is set" it aSSUmes the value at input PV or the value be low the set coil or sCI box as count value. You may specify the couni value as constant, word operand. or variable of type WORD.

The counting freque ncy of a eount~.,. ;s determined by the execution time of your progmm! To be able 10 count . the CPU must detect a change in the State oflhe input puhe, that is, an input pulse (or a space) must be present for at least one program cycle. Thus, the loug~'" the program execution time. the lower the counti ng frequency. U p c ou nti ng
A counter is counted up whcn the RLO changes

Speci!5'j"g the COllm \'a/ll" os COnStom


C#l00 W#16#0 100 Count value 100 Count value 100

The count value comprises three decades in the range 000 to 999. Only positive BCD values are pcnll issibl~; the counter cannot proce ss negative values. You can use C# or Wll 1611 to identi fy a constant (in conjunction with decimal digits only).

from "O"to "1"lJ.efore the up count input CU or at the up count coil or box. A POSilive edge is always required for up counting. In up counting, each positive edgc incremeuts the count by one unit until it reaches Ihe upper range limit of 999. Each additional positive edge for up counting then has nO furth ~.,. eITect. There is no carry. D own co u nting A counter is counted down wilen t~c RLO changes from ""0'" to "1" before down count input CD Or at the down count coil or box. A positive edge IS a lways required for down counting. In down counting. each pos itive edge decrements the cOunt by one unit until it reaches the lower range limit of O. Each subsequent posit;ve edge for down counting then has no further effect. There are no negative counts,

Speci!5'j"g the coum value as operand or ,""ri_ able


Word operand containing the Count value ""Count value!"' Variable of type WORD Resetti ng counte rs (L A D ) A counter is resel when poWeT flow. in Ihe reset input or in the reset coi l (wben RLO ""I'" is present) , When this is tbe case. checking the counter with an NO contact will resuh in a check result of "0". and checking with an NC MW 56

'"'

8 Counters

Di(f<'rl'nl cnunler boxes


The Editor boxe.:
pr\>"idc~

three dIfferent couDler

made ., a;lable by this operation i~ lh e one which is current at the time the cbeck iJ made .
The "aloe ~ 5Iored in the spec;fled OjX:TlInd (transfer as " ith a MOVE box). You nocd nO! .,,i!ch tb"", nutputs at lhe counter box.

Up/down counter

Up counler

ll<:>WD countcr
These coumer be:>:e. difTeT only in Ihc Iype and numlx,. OfCOIlnler inputs. Whereas S_CUD ha~ inputs fOT both eounl;ng directiOtU, S eu has on'y the up COllnt mput and S_CD only the down count input.
You mIL'! .. I w~y~ connect the 1i!'11 U:P\lI of .. COllnter be:>:. If you do nol collllOC, the second ;lIPLlt (S CD) o n S cun, Ihi , 00:>: wi ll lah on the same chBracleri~lics as S_CU.

DI1'eCI eh<'<"king of the

"""m

The COUIlt i. a vailnble In binary, Bnd can be fetched from the counter in this furm.. The value correspond.. In K pasn; ... number in DJT format Dire<."1 ched:i1l ofa counl can also be progm:nmed with. MOVE box.

Cod<,d d ,,,d-;n8 <>{llle counl

8.4

Checking a Counter
count~r

You can also fctcb the binary count from the in "coded" form. The binary-coded deeunal (BCD) valuc i~ slTUcNrffi in the ~ ";,y as for srecifying Ihe count (sec abo\'e).
C01.J"IleT

Chccklnj;\ the

,talUs ( I.AD)

11,c counter "T atus i. al OUlpul Q ofthc "ollnler box. Yon can also check !he counter statu." ith
an NO colllaeT (COfTCS.pooding :0 OUtput Q) or an N'C COIlUOel.
Qu tput Q iJ "1" (power n ows from the OIlTJlut) when the ~um;nl count is i'"C"lcr thnn :zero, Output Q i ,~ "0" if Ihc C"ITent count i~ equnlto zero. O\IlpuI Q does nol need 10 be connected at the CO\lnto;-r box.

8,5

I EC COUill t rs

The IEC count= Iffe integrated in the CPU operat"'& ~y'1em a~ system func tion bloc~ (SI'85). The folluwing CO\Jnl~n; are ava ilable in Ihe appropriate Cl'Us;
~

SFROCTU UpcounlCT

:>

SFB I CTD
Do"'n Cnunter

C b N"kinll: the counler

~IMtU1

(FUrl)

The counter ~I~ I U~ is at output Q uf lhe cour.I~T 00:>:. You c~n al ~o check the coun ter "ants directly (correspond . to OUlpul Q ) wilh a birutry function input, OT;n negated form. Output Q is "1- wben tb~ current count ;s great .... than 7.ero. Output Q is "()" "h~n tbe cur n:nl count i~ equal In ~~ro. OutPUt Q ne.:<inol be cnnncc\C<I at ,he counter h<J~.

.,.. SFB 2 CruD


l:pldown cuunter Vou eau call these SFB, with an in' tanee dMta block OJ" use thern lOS local inst.;wccs in a function block. You will find the tm~"'face de""ript1On fOT offi lnc pro;:rarnminll on stan dard library Slandard Lihrary under Ihe .sYstem F,are/ion 810.:1:.$

program.
Ch ..ddnll'h~ fUUDI valu r (L,\J) aDd FRD)

OU' PUI8 cV .. nd CV_BCD malo: Ihe counler's current count availablc in bmary (CV) or in binary-cO<lw <iedrnnl (BCD). The count va lue

Yuu will f",d samp le calls in function block FB 108 of tbe "Basi~ fUDClions" program in the "LA D_ Book" and "FBD_Book" libmie~ thaI .'00 can downlOftd from the publishc-r's Weh.ile (see page 8).

8,5 IEC Counters

8.5.1

Up Coumer SFB 0 CTU

lEe counter SFB 0 CTU has the parameters listed iJ, Table S, I , When the sisnal state at up count input CU changes from "0" 10 .. \" (positive edge), the current count is incr<:mented by I and shown at output Cv. On the I1rst call (with signal state " 0" at reset input R ). the ~ounl corresponds to the default value at input pv. Whcn tbe count reaches the upper limit of 32767. it is no longer incremented. and C U has no cffe~1. The count value is resel lO ~ero when Ihe signal slate at r<:set input R is "' I", As long as input R i< "I", a positive edge at CU has no effect, O utpul Q i. "1 ,. when the value at CV is greater than or equal to the value at pv. SFB 0 CTU executes in START and RUN mode . It is n;set on a cold ,tan,

The conn! is set to default value PV when load input LOAD is " I", As long as input LOAD i~ " I " . " positi ve edge at inpnt CD has no effect. Outpnt Q is "1" when the valne at CV is less than or equal t<1 zero.

SFfI I

exccutcs in START and RUN mode . It is reset on a cold s tart. Up/do wn C<1untcr Sn3 2 CTUD

crn

11.5,3

lEe counter SFB 2 CT UD h as the paramcters listed in Table 8. 1. When the s ignal s tate at up count input CU changes from "0" to " 1" (positive edge), the count is incremented by I and s hown at output CV, If the signa l state at down count input CD changes from "0" to "I"' (positive edge), the count is decremented by I and shown at output Cv. Ifboth inputs show a positive edge, the current count remains unchang~d,

8.!;'2

Down Counter S}"B I CTD

ICC counter SFB I CTD has the parameters listed in Table 8,1. When the signal state at down coun t input CD goes from "0" to "1" (positive edge). the C"rrem eo ...n! is decrementcd by I and shown at output Cv. On the firs t call (wi th s ignal state " 0" at load input LOAD), the CoUnt corresponds to the default "aluc at input pv. When the curren! conn! reaches the lower limit of -32768. it i. no lo nger de~remented and CD has no effect.

If the emn:nt count r~aches th~ upper limit of 32767. it is no lon ger incremented when there i, a positive edge at count up input Co. CU thcn has nO further effect. If the currcnt count rcach~s the lowcr limit of 3276R. it is nO l ong~r decremented when there is a positive edge at down connt input CD. CD thcn has no
e ffe~t.

The count is sct to default val"e PV when load input LOAD is "I'", As long as load input LOAD is " In, positive signal cdges at the twO count inputs have no effect

Table 8.1 P3nmetor< for the lEe Counter<

,;

"

g Counters Function des crtpt lon Pans are transported on a conveyor bell. A light barrier detects and counts thc pat1s . After a set number. the counter sends the Finished 'ignal. The cOunter i. equipped with a monitoring eircu;t. If the s ignal StalC oflhe light barrier does not change w ithin a spec ;fied amount of time, the monitor sends a signal. The Set input pass~s the starting "a lue (the number 10 be counted) to the counter. A posi_ th'e edge at the li ght barri er decrements the counter by one unit. When a value of zero is reached, lhe countCI>< sends the Finished signal. Prerequis ite is that Ihe parts be arranged singly (at intervals) on the belt The Set ioput also SetS the Active signaL T he controHer manito" a signal state change at the light barrier in the active .tme only. Wh en COUll1ing is finished and thc last connted item has exited the light barrier. Ac!il'e is reset.
In the active state. a positi,c edgc at the light barrieT starts the timer with the tim e value Dur(1tion 1 ('"Dura I") as retenti,'e pulse timer. If the timer', start input is processed with "0" in the ne;<t cycle, it .till cont inues to run , A new po,iti,. edge "",triggers" the timer. th,t is.

The count i, reset to uro when re.,et input R is "1". A~ long as input R is T. positive si!>Dal edges at the two cOunt inp uts and signal ~tate "I" at load input LOAD have no effect. Output Q U is "1 " when the value at CV is greater than or ~"<Iual to the "alue at PV. Omput QD is "1" when the value at CV is les, than or equal to zero. SFD 2 CTUD cx~"<:uteS in START and RUN mode. tt;S TCse! on a cold stan .

8.6

Parts Coun ter Exam plt'

The examples illustrates the usc of timeN and counters. It is program med w ith inputs. ompms and memory bits so that it can be programmed at any point in any b lock . At this poi~t. a function witho"l block parameters is used: the timer.; and counters arc represented by complete boxes. You will fwd the same example progmmmcd as a function block with block param_ eters aod with individual clements in Chapter 19 "mock Parameters",

T_ht.8.2 S)'mbol Table for the I'.n, Coon,..,. Examp le

8.6 rCSlan$ il. Th~ nexl positive edge to res.an th~ timer i~ generated when the light balTier signals a !legnt iv~ edge . The timer is Ihen staned with the time va lue DI/ralion] ("Dura2'). I f the hght banier is now eo'ere<! for a period of .ime eJCedi na Durul or free for a period of rime e xceeding Dura]. thc limer TUns down and signal F,wff. The lim time II j, activaled. 'he limer il ~tarted wilh .he lime value D"ral. S llI n. ", sym bols

P."" CouJller fua.mpl~

We wanl symbolic addressing. Ihat is. the operands are assigned namc~ which arc then used for progranuning. Betore ent~.,.;"g Ihe program, we create It symbol table (Tpb le 8.2) containin ll the inputs, outputs, mentory bi,s, timers, COUnters. and bloch. !' roarl m The prolP1'm is located in a function lhal you caU to the CPU in 0'1l3niza.ion bl""k OB I (tclec ted fro m the Progmm Illcmento enalog underFe Blocks"). During programminll, the a lobal ~ymbols can KI..o be u,ed with<>ut quotation ma"" provided Ibey do not contain any special ChaJ1lClcrs . If a symbol contains a special c haracler (an Umiaul (lr a ~pace. for instance), il mu.~1 be placed in qU(lIHli<>n marks. In Ihe C(lmpiled block, the Edilor sho~ a ll g lobal symoo ls wilh quotalion mllrks Fillurc ~ . 4 lind Figure 8.S show~ the program for the pans counter (Function Fe 12). You can find this program in the Conveyor Example pr<!ltf"8.m of .he "LAD_8ook and "FBD_ Book libraries , hat you can download from li>c publishcr"s Wcbsile (sec page 8).

The Sel signal aClivales Ihe CountU and . he monitor. Th e light barrier comrol.~ the counter, Ihe Uc'I\~ .I a.e, ""lcclion of the time value . and Ihe Slan ing (rctriggering) o f the mo",,,,ring lime vi .. posilive and n~galive edgC!!.
Evalull!ion of ,iIc posi.iv" and neaalive edge of the h g}1! barrier is required often. and temporary local data arc suitable as scnnehpad memory. Temporary local dalB are block -local variables: Ih ey arc declared in the blocks (not in Ihe symbol mble) . In the example. the pulse memorybils used for edge evaluation are stored in temporary local data. (The edge memory bits requ ire their si gnal sta'e" in the nexI cycle as well. a nd mustlbe..,fore nol be tempo"'ry local data.)

'"

x Counters

fR'

,
lbarr1

Network 1 Counter cont,ol

"'""' S_ CD
CO

Finished

~,

,
R

c' tCV_BC D

NOTI

( )---j

Quanllty -

""'"-'
N4twork2

"

I-

, ~
~

~
I

'" "
EM_ l B_ N

"" ~

Netwol1< 3 Select duration

lbarrl Du," 1 lba,,1


Dura 2

MOVE

#t BOOl

'" '"0 '" '" '"


00;
MOVE

)---j
III Durali<ln

'"0 00;

III

D u,~ tlon

N_o,k4

~
~

~
c'

I"

'M"
Fi\:ur. 8.4

""

IR

#I Duration

Pro~nmi""

fuample for a PlUb Coun{o. {l..AD)

8.6 Pam Counter Example

Fe 12

e" un '~r

t on",,1

Network 1 Counter control

Count
cv-

L barrt
5..,t -

CD

QuantltY:-=t';V~...:O:V:,'o'-9J-=_-<i':'":"M='j : Q Ackr>owl R _
Network 2 Activate monitoring

Dural

Lbarrl -<j"
Dura2
Network 4

,.

-b_-''''J------~L_J-'[~~J

Monitoring circuit

Active Figure 8.5 Prognunrning Example for a Pons Counter (FBD)

'"

Dilila] fUDctio""

Digital Functions

The digilal funCliuns procns digital values pre. dominantly with Ihe data types INT, OINT and REAL, ~nd thus extend !he functionality oflhe PLC.
TIle c(l nlpu l50n fu n.... llo ns fonn a binary U"sult from the comparison of two values. They lake acrount of the data types u\'T. DINT and REAL.

Vou l.ISC lhe a rilhmNk fu nctions 10 make cal. culations in your program. All the basic arith. melic functions in data types INT. DINT and REAL aU" avail ab le.
The m athem atica l fu ncd ons extend the calcu-

09

Com pariso n F u nctl ons Comparison for equal to. nOI equal 10, grealCT than. greale.- Ihan or equal to. less Ihan. and less Ihan or equal 10 A rithmelic F unCII(lns Basic arilhmetic functions with data types INT. DINT and REAL i" blh .... m atlc hl F un ctio n, Trigonometric funelion,; ;n"o:\"sc lrigon..... m"'lric functions: squaring. squ~.rool eXU"8ctioll, cxponentiation. and '\lia. mh"" Con""" ion Fu nc tionl Conn'\"l;ion from l>o'TID INT to BCD and ,'ice ,.....1"~a: con"ersion from DINT to REAL and vice, et$II with d, fferenl fonDS of rounding: one's complemenl. negation. and absolutc ."alue gcnerution Shift Fu nc tio ns Shifting 10 left and right, by word and doubkword, shifting with correct sign: roulling 10 left and right Word L ogic A}.'D. OR. exdU$i\'e OR; word and d oub1eword combinations

10

lati cm possibilities beyond the basic ari thmetic to include. for example, trigonOmet. ric functions.
funclion~

II

Before and after p<'rfonnina; calculations. you adaptlhe digital values to the desired data typo: using the con,tnlo n fun .... tions . T ht . hlft fun .... Uo u. allow juslificaLion of lhe contcnlS ora variable by shifting to the right or left. Wi!h " 'o rd l\lik. you mask digital '"llues by targetina; individual bils and ..... lting them 10 "I" or "0". The digital logic opc:ralions work mainly Wilh values slored in data blocks. Thesc can be glo. bal data blocks Or inslanee data block s if slat;c local datll are used. Chapter 18.2. "Block Func. lions for Data Blocks". shows how to handle data blocn and gives the methods of address. ing dIIt. operands.
IJ

12

14

192

9 Comparison Fuoction.

Comparison Functions

The comparison fum:lIOIlll cOtnplll'e t"o digital variables of data type INT. DINT or REAL for equ;ol to. not ~quallO. gr~at~r than gr~at"r than or equ~l t(l , I~," thllIl, Or less than or ~qual to. Th~ comparison rC"Uil is then a"ailabl e os binary va lu~ (Table ~.1).

compan~n ~tunds

performed (CMP -I. for imt.anl'e. for th~ compari.on of tWO IN,. numbers for equal to) .

You cnn arrange a comparator in a rung in plac e of a conta~t. The unlabclod input and lhc unla ~led output establish the conne<otion 10 the other (binary) progrdIIl clcmems.

9.1

Proce5sing 11 C lilUplIrison Function


to C-T)
CMPnl

Co,nl'Arl'OD .... , (," eumpl<; """,pariSO" for equo!

LAO 'OpAls"ntation:

='"' '"'
- 'N' 'N'
R~presentAtiuD

The "alue, to be compa~d are pt Inputs IN I and I>I2111Jd the cornpari~n re~uh is the output. A su~ccssful comparison is equivalent to a elo.ed Contact ("pow ..... nows through the comparator). If the comparison i~ nut suc~e&~' fu l, the comact is open. The <;oml"amlOr'~ out pul ",U$t always be imerccmncctod.
R~p ~$~ nl.tlon

FRD

CMP_al

The bolt for a comparison has two inputs, IN 1 and 1>12. ""d 1m unlabeled binary output. The "header" m the box idcnlifie!> the CQmparison performed (eMP - I, for namplc. stands for the compari.on of two J1'o.'T numbcn. for equal
(0).

LAD

In addition to the (unla~lcd) binary input. the bolt for a comparison function has two input;;. IN I and fN2, and an (unlabeled) binary output. The Mlleader" in tbe box identifi~sa cnmparison operation (CMP for compare) pod the type of
TobIe ~ .l (h'c'Ivicw of the ComparilOlll'unctio""

The vuluc5 \1,1 be compared are at inputs IN I and IN2 and the result of the comparison;" at the QUtpUt . Ifth~ cOnlpariwn is ~u= ful, the comparator output sho.",.~ sianaJ state "I"; <}lh o:rw..e, it is "1)". It mUSt always be intercon neetod.

,.

"

'"

\l

Comparison Functions

Uata types T he data type of the input' in a comparison nmcti"n ,kpend s on that function. For examp le, the input!; arc "ftype REAL in the comparison function CMP > R (compare REAL num bers for g", ater than). Variable, must be of the same data type as the inputs, When using operands w ith abwlulc addn:,scs, tbe operand w idths must accord with the data types . For ex amp le , you can use a ""oro operand fo r data type INT. You can find the bit assignments for the data fom )a!>; in Chapter 3.5.4. "Elementary Dal2 Types". A compari,on between REAL numbers is not true if one o r both REAL numhcr, are invalid . In a dd ition. :;tatus b ilS OS and O V arc set , You ca n find o ut h ow the comparison nmctions set the remaining status bi" in Chapter 15. "Status Bi,,"',

~ amples

Figure 9.1 provides an examplc for each of the data types, A comp arison functi on carries uu' " comparison according lU the characleristics spec ified .",-en when nn data types arc declared when using operands wilh ah solutc addresses.
In the cas, of incremental progrmnm.inl!'. you w ill find the comparison fundi"ru; in the Program E1cmcnts Cata log (with VIEW ~ OVER VIE>I,; [Crrl _ K] or L'ISERT ---; P ROGRA \l ELEME:"'TS) ulld<'f "Comparator'"

C om p aris on fu n ction in a run g (LA D) You can US<: tbe comparison function in a nong in place ofa contact You can C"fillcct contacts before and afler the comp ari",n fullction in series and in parallel. The comparison boxc, themselves can also be

Comp~r ls on

Aording

In

1"' 7

Memory b i' M 99 ,0 is reset if t"e n luc in memory word othe,""ise it 1> n<>t
CMP - - 1 M99 .0

~V

92 is equals to 120:

C MP --1

MW 9 2

Comparison a ccor din!/; to I) I<,-'T

'"

'N ' 'N '


.. ..

R)

MW92 -

-Globa l_DS-. CampYa l' -Global_DS-. Campllal2

.. fhe van"bl~ .. CompRc<ult in dam block G lobal_DB ,s Sct ,I vanablc '"CmnpVal l";,; less than CompValr ot h~rwi"e it is reset, "Global OS". CompResull C MP ~ D CMP< D "Global DS- , )f--I Compv;ol1 "Glab'!!_ DS-GiobaLDS", CompR" su lt IN1

..

'" ....

'" 'N' ..

M 99.0

Campva~ --L' ~N~'______f--'::C:~:S

'N'

IN2

If the V<ll1abl~ HActYal" greater than or equa l to the vanabk IIC"libm. #-Recah C omparison a ccording to Rt: A l.. i. ,et ' otherwise it is not
CM P IIActY"l _ jj Calibra
~R

#Recall

'N' 'N '

,)

CMP > R

IIActYal-

#Calib.-a

'N'

'"'

HRecali

FIgure 9.1 Comp.ri>oll Fuuctiuu Example.

'"

9.2 Description of the C<.>mparison


~onn"ctcd

Fun~tion,

in series or in parallcL In the case of comparison fun~tions connected in series, both comparisons must be successful for power to flow in the rung. In the case of comparators connected in parallel, only One ~ompare condition need be fulfill ed for powcr to flow in the parallel circuit. You can find further examples of the representat ion and atTangcmcnt of compari son func tions in th e program "Digital Functions" (function block FE 109) in the libmry LAD_Book that you can down load from Ihe publisher's Website (see page 8 ). Compa rison funct ion in a logic circuit (FBD) You can position the comparison fun~tion at any binary input of a program e lement. The resuit of the comparison can be subsequently combined with b inary functions. You can find further examples of the rep reselltatioll and arrangcment of comparison functions in the program 'D igital Functions (func _ tion block FB 109) in the library "FBD _ Book that you can do\vnload from the publi.hds Website (see page g).

with the data 'ype specified in the comparison function and checks to sec if the two values differ. The comparison is succes sful ("power flows through the comparator Output or the RLO is '.J .. ) when the two variables have different values.

If, in the case of a REAL comparison, one or both input variables are invalid, the comparison is not suc~essful. In addition. status bits OV and OS are SCI,
Comparison for grealer than The comparison for greater than' interprets the conten ts of the input variables in accor' dance with the data type specified in the comparison function and chc~ks to see if the value at input INI is greater than the value at TN2. If this is the case, the comparison is succe~sful (""power' flows through the comparator output or the RLO is 1),
If. in the case of a REAL comparison, one or both input variable s are invalid, the comparison is not successful. In addition. status bits OV and OS are set,

Comparison for greater than or equal to

9,2

Desnlptlon orthe COmpariso n


Functions

Compar ison for equal to The comparison for equal to interprets 'he cont~nlS of the input variables in accordance with the data type spe~itled in the comparison function and checks to S~e iftbe IwO v alues are equal. The compare condition is fulfil led ("power' flows through the comparator output or the RLO is '1) when the twO variables have Ihc Same value. If, in the Case of a REAL comparison, One or both input variables are invalid, the compari,on is not successfllL Status bits OV and OS are also sct. C om paris on for not equal to The ~omparison for not equal to" interprets the contcn" of the input variables in accordance

The comparison for great~'t" than or eqoal to" interprets the contents of the input variables in accordance with the data type specified in the comparison function and ~hceks to see if the value at input tNt is greater than or equ"lto the value at input IN2, If this is the case, the comparison is successful ("power' flows at the compar~wT outpot or the RLO is '1 "). If, in th~ case of a REAL comparison, one or both input variables are invalid, the comparison is not .uc~essfuL In addition, status bits OV and OS are set . Comparison for less than The "comparison for less tha n" intcrprets the contents of the input variables in accordance with the data type specified in the comparison fun~tion and ~hecks to sce if the value at input IN! is less than the value at input IN2. Ifthis is the case. the comparison is successful ('power' flows at the comparator output or the RLO is

,. IJ.

195

9 Comparison Functions If. in the case of a REAL comparison. one Or both input variables are invalid. the comparison is not successful. In addition . ' tatus bits OV and OS are set. comparison function and checks to see if the value at input IN1 is less than or equal to the value at input 11\' 2. !fthis is the case. the comparison is successful ("'power" flows at the comparator output or the RLO is "1").

Comparison for Ie.. than o r equ al to

The " comparison for less than or equal to" intcrpre1.~ the contenl> of the input variables in acco rdance with the data type spec ified in the

If. in the case ofa REAL comparison . one or both input variahles are invalid. the comparison is not successful Tn addition. StatuS bits OV and OS are sct.

10 Arithmetic Functions

10 Arithmetic F unctions

The ari thmetic functions combine two values in accordance with Ihc bas ic arithmetical opera ~ tions of addit ion, subtrJction, multiplication, ami division . You can usc the arithmetic runclions on variables of type INT. DINT. and REAL (Table 10. I),

output, OUT. The "he ader" in the box ident ifies the arithmetic function executed (AD!)_ I, for instance, stands for the addition o f TNT nnm~rs).

10.1 Processing an Arithmeti c Func-

tion
Represe n tatio n
A r i l h m ~t1< b o ~

(in <","npl~ : addition with tNT)


LAD repreSllntaUon

F8 0 representation:

'" '"' '"'


'N, 'N'

AO D_t ," 0 OU'

The values 10 be combined are at inputs TNI and IN2, and the result of the calculation is at output O UT. The inputs and the output have different data types. dcpending on the arith metic funClion. For example. in the case of the arithmetic function ADD _ R (addilion of REAL numbers). the inputs and the output a re of data type REAL. The variables applied must be of (~c same data type as the inputs or the ootput. If you use absolute addre ..es fo r the operands, the operand widths must be matched to the data types. for example, you can use a word operand for data type INT.

ff-

You can find a description of the individual bits in eac~ data fonnal in Chapter 3.5 .4. "Elemen tary Data Types".

ADD_I

I'u n cd on

="

OU, 'NO

f-

In addition to enable the input EN and the enable output ENO, a box for an arithmet ic function has two inputs, INI and IN2, and an

Th e aritiunetic function is executc<1 if "I " is present at (he enable input ("power" flows in input EN). Ifan error occurs durin g Ihc calculation. the enable output is set to " 0"; o therwise, it is set to "1". If execution ofthc function i~ not enabled (EN - "0"), the calcolation does not take place, and ENO is also " 0",

T. bl" 10 . t (ke,,'iew of A ritbmic Function.

ATithmctic function
Addition

With data type

Subtraction M ultiplication
D ivision with quotient os res ult D iv ision with remainder a. ,,:>ult

>NT ADD' SUB I MUC ,


DlVI

OINT ADO_PI SUO 01


MUl DI

REA'
ADD_R SUB R M UL_R
DIV R

'"

10 Arithmclic Functi{)ll5

IF EN "" '1 " or not wired THEN


OUT :. IN1

> Invalid REAL number in a REAL calcula"


ELSE
tion See Chapter 15. "'Status Bits". to Hnd out ll{)w the arithmetic functions Sel the various stalUs bil'.

:: '0"

Enmples Figure 10.1 shows an example for each data Iype , An arithmelic function exCculcS a calculation in accordance with the characterisl;c spec ified. even ifn{) data types have been declared when using {)perand, with absolute addresses.

If the MasterConlrol Relay(MCR) is activated,

{)ulpul OUT is set t{) zero when the arithmetk funeti{)n is processed (EN - 'T'). The MCR d""s not affect the ENO output.
The following errorS can OCCur during execu

tion of an arithmetic function:


I>

Range violation (overflow) in tNT ami


DINT calculations

I>

Underflow and {)verflow in a REAL calcu lation

In tbe case of incrc-menlal p[{)gramming. you win Hnd the arithmetic functions in the Pro" gram Element Catalog (with VIEW --> OVER' VIEWS [Orl - K ] or L.... SERT --> PROGRA~1 ELE" ~!E"TS) under "[mcger function" (INT and DINT calculations) and under "Floatin g-Point fcl. (REAL cakulalions) ,

Addition accnrdiog In 1r..'T

The value in memory woro Ivl\\' 100 is divide<! by 250, rhe integer result is stored in memory word M\\' 102.
DIV_ I

MW 100,~

Add.tIOn according to D1XT

..

'" '" '"


'N

'" 0
M

r-- MW 102

,
..

DIV_ I
-,"

MW1~ j IN2 :~1 250

0", '"0

r--

MW 102

The -.alues m vanables .. AnthVall and .. Anth\'al1 arc added and the r~sult stored in variable ,. ArithResult"". All ,'ariable, are stored in the data block.

..

ADD_DI

'"0
M

"Global_OS". MthVall "Gklba l OS". AI1thV"j2

- >N,

f-

"Glooal OS". AI1IhReSult

"GIobaL DS" , AI1\hVall "Global_OS" ,


At1IhV~1 2

ADD_ DI

'" >N,

0"' '"0

rIS

"Global OS", A,riIhResu ll

Add"'on accordinK 10 RI::AL

..

'"

The 'anable . Act\al and Factor are mulllphe<!. the prodnct " ,ariabte ii Display.

'"'

transferred to

MUL_ R

liActVa l liFactor

'" '" '"'

'"0
OC , #Oispay

MUL_R

liActVal #Factor

'" '" '"

OC, -

#Oispay

'"0

t"jgure 10. ' hample. of Arithmetic FUDcrio""

10.2 Calculating with Data TYJl<' II'.'T A r ithmetic fu nct ion In a r ung (LAD) Yo u ,",I'n ,",o nneCl ,",ontacts in series and in parallel before th,", EN inp ul and aCler Ihe ENO out put . The arithmetic box itself may be placed after a T_branch IlI1d in a branch that leads direcdy 10 lhe left power rail. This branch ewn alSO) ha"e eontlctS before Ihe EN input and il need not be the uppel1llost branch. Dire.:1 conneclion to the len po".er rail mean5 Ihul you can connect arithmetic boxes in paral_ lel. When you conned bo xes in purall el. you nd II coil 10 terminate the rung. If you ha'e not provided any error evaluation. assign a "dummy" op<..-rand to the eoi!. for example a temporary local dala bil. You can connect arithmelic boxes in series. If the ENO output of the pre.:edmg box lead5 to the EN inpul of the sub!lequent box. the subse quent box is processed o nly if the preceding box has been completed wilhout elTors . If you wan1to use the result from the preceding box as inpul value for the next box, variubles from Ihe lemporary local data area make ,",onvenienl inlennediate buffe!"!!. I f you ammge se,'ernl arithmellc boxes in onC Olng (parallel to the left power rail. then Further in 5eries). Ihe boxes in Ihe u~nnost branch arc pro<:esscd from left to rigbt. followed by Ihe boxes in Ihe secu",l branch from left to ri ghl. and su on. You can find funhe. examples of the rcpresenIlilion and arrangemenl of arilhmetic function. in the program "Digital Functions" (FB 110) in the library "LAD_Book" Ihal )'ou cM download from the publisher's Website (see page 8). Arithmetic funclion In a 1 0ile circuli ( fBD) If you want to proces s the arithmetic box in depend ence on specific ,",onditions. )'OU can arrange binary logic opera1ions before Ihe EN inpul. You can interconne<;1 the ENO outpUl with binary inputs of olher functions; for exam ple, you elin ammge arithmetic boxes in oe:ries, whereby the ENO O\Jtpu\ of Ihe precedmg box leads 10 the .'1 input of the following box . If you wanl 10 use Ihe calculation result from the preceding box as input value for a subsequenl box. v8ri"h le. from the ten'poraoy local data area make co nveni ent intcnn~-di ate buffers.
EN and
E~ O

need nOt be w ired.

You can find further examples oflhe represenI.IIlIon and arrangement of ~nthmelic fullCtionS in Ihe program "'Digital Funclions" (FB I to) in the library "H:JD_llook" Ihat you ""n download from the publisher's Website (see page 8).

10.2 C a l culating with Dilill Type lNT


L"'T additio n
The function ADD_I interprels lhe values at mpuls IN! and lN2 a!i numbers uf dala type INT. It adds the Iwo numbers a nd stores the sum III OUlput OUT.

ceo Ind CCI

After e.\co;ution of the calculation. status bits indicate whelher Ihe sum is negative. zero, or positivc. 5tot\lll bits O V and OS indicotc any range violations.

INT subtrwCllon

The: function SUB_I interprets Ihe values al


inputs 1..'1 I and ".... 2 as numbers of dala type L''''. h SublnlCIS the value .t 1N2 from the val"" alINI and Stores the diff~....::ncc in outp ut OUT.

ceo

After execution of the calculation. stat us bilS and e C I indicate whelher the ditTc", nce is negnt ive. 7.ero, or po,itive. SlUtus bits OY and OS indicate any range violoti(}ns.

1:-;1" multiplication

The funclion M UL_I interp~ts the values al inputs I},' I and TN2 95 numbe", of dala type INT. h multiplies the two nl1mbers and Slores the prodUCI in omput O UT.

ceo IUld eel


I,,"T division

After execution of the calculalion talus bits indicate whelher the product is negul iv e. zero. or po. itive. Stalus bits OV and OS indicate any INT mnge violtllion .

The function DlY_' interprets the values al mpu!:> TNI and 1N2 u numbcT"s of data type INT. It divides the \"Blues III input L 'll (d ivi_ dend) by Ille valuc ~l input IN2 (d ivisor) and supplies thc quotient at output OUT. It is the

'"

10 Arithmetic Fundio"s Oii," T dh1'lon "jth


'luo1i~nt

iDlcger result of the di vision . The qu()!i~nl is zero ifthc di,' id~'tld is equal to zero and the divi sor is not equal to zero or if the ab,ol ute ,alue "fthe dividend is Ie,s than the ab,olute value of the divi"or. The quotient is negative if the divisor is negativc . Aftcr execution of the calculation. status bits ceo and eC I indicate wb"l~er tnc quoti enl is negative. zero, of positive . Status bits 0'1 and as indi~al.C any range violations . Division by zen> proouces zero as quoti("1\t and 'CiS statu, hits ceo, eel, OV and OS 10 "] " .

u result

The fun~tion j)IV_ DI int~rpr~t' tbe va lue s at input' TNI and TN2 as nnml>ers of data type D INT. It di"ides the value at input L"I (divi d~ -nd) by the "alue at input IN2 (divisor) and ~tor~s tho quoti ~nt in output OUT Tt" the integer res ult of the division . n,e quo ti~nt is z~w i f the di vidend i, equal to zero and the d iyi,or is oot eqnal to zero or if tnc ab~olntc val ue of the di"idend is les, than the absolute value of the di \ i,or. Th ~ qll",i "" t is nq,;:aIiv~' i rlhe divi,or i, negali'e. Aft.r execution o f the calculation. starns bit, ceo and CCI indicate whether the quoti~D\ is nq:;aIi \'c. zero. or po;;iti ve . Stam, bits O V and as indicat. any range violations . Division by z ~rO produces zcrQ as quotient and setS status bil< ceo. ee l . 0'1 and as to " I ". DL,\"T
dl'" !~!on

10.3 Calculating with Data

T~'p",

DINT
011\, addition

The f"n~tion ADD _01 interprets the values at inputs IN I and lN2 as numb~'r:S of data t>pc DINT. It add, the 1"'0 num~rs and stores the swn in output OUT. After ex",", ut;on of the calculation. ,tatus bits CCO and cel indicate whether the ,um i, negat;ve, zero, or po,i live. Slalus hits O V and OS indicate Hny range violations. DINT subt r action Th e function SUH ])1 nHerp""" tn e value, at inputs INI and IN2 as numbers of data Iype O fKT. Tt ,ubtraclS th~ va lue at inp ut LN2 fTmn the value a\ inp ut TN ! and stores tne d ifference in output OUT After ex~U!ion of the calculation. , tatus hilS CCO and ee l indi cate whether the difference i, negativ~, ~cro> or positive. Status bits O V and as indicate any rnn!:" violations DINT multiplication fUIlction MUL_ Ol interpret> the ,"alue, al IN I and IN 2 as numbers of data typ~ DINT. It multipl in the two nnmber<; and ;;tores the produ~t in output OLT.
input~ Ib~

" 'lIh remaindu itS result

The fun~lion MOO_ Dl interprets the va l"", at inpnts TN I and DJ 2 as numixTS of data type D INT. It d ivides the valee a t input IN ] (d ivid~'lld) by tnc ,'aluc at input lN2 (divi",r) and sto,"", the remain der o f th" di " i,ion in output OUT. The r~mainder is what is le ft oWr from the dh 'is ion : it doe.' not eorresp<lod to the de<:imal p laces . If the d ividend is n egative, Ihe remainder is a lso negaI iv ~ .'uter execution of tbe eakulation, Slam, bits CCO and CC 1 indi~ale 1}. helher tbe remainder is negati"e . z ero, or positive . Starns bits OV aTld as indi cate any ran ge violations. Divisi on by zero produces zero as ,..,mainder and sets "aluS bits CCO. CC I, OV ami as to "I"'.

10.-1 C alculating \\ith Data Type REAL


REA L numbers are repre,ented interna lly as Goating_poi nt numbers "i'n tw o number ranges: One range with full accuracy ("norma lized-' floming-poinl n um~rs ) and one range with limited accurac y C'd~-n"rmali z ed" tloating _ point uumbe rs: al,o see Chapter 3 5.4, "Elementary Data Types"'). S7 -400 CPUs calculate in both ranges, S7-300 CPUs only in the fullaccuracy range. Ifan 57-300 CPU carries out a c alcu lmwn wbose resul! " in the limited -aeeu-

Aftcr execution of th e calcula,i un, "atl.lS bit< ceo and CCI indical~ whether th e produce is oq~ati"e, zero. or pusitiv ~. Stat u, bits OV and OS indicate any range yiolations

""

10_4 Calculating with Data Type REAL

riley range, zero is returned as result and a runge "iolation reported


REAL
~dd illon

REAL

mult lpll ~a t1on

The funetion ADD_R interpl"ClS the values"t inputs IN I and IK2 as numbers of dma type RI!AL It add<! the two numbers aDd stores the lIum in output OUT.

The funetiun MUL_R ;nterp("\~ the values at inputS I'll and JN2 as numbl.'TS of dala type RAL. It multiplies the twO numbto,... and sloreli 'he product in output O UT.

ceo and eel

After exccution of the calculation, status bits

Aner exccution o f the calculation, status bits eeo and CCI indicate whether !he sum is negative, "co, or positive. Status bits OV a"d as indicnle any range vio lations.
In Ihe cast ufan ilk sal calculati on (one oftne input vulues is an invalid REAL number or you "tempt to add +- and _), ADD_R returns an invalid val ue at output OUT and sets sunus bits eeo, eel, OV and as to "I". R EAL su blr _Cllon The function S UB R interprcts the value, at inpul s IN I and JN2 8S numbers of da1:1 type REAL, \t subtracts the n"mher at inpm JN2 from the n"mheT al input I", I and stores the difference in ompm OUT. After execution o f the c.leulatioD, 51atuS bils eC(l and eel indicate whether u.., difTerence is neaati,e. zero, or positi\'c, Statu, bits OV and as indicate any range vioimlions. In the C~ of an illegal calcul"ion (one of the input values is an invalid REAL number or yo" Kltempl t<l suhtract +_ from ...... ). SUB_R returns ~n invalid value at o"tput OUT and set> StatUS hi.,. ceo, eel, OV and a s 10 " 1",

Indieate ... Ilcther thc product is negative, ~ero. or positive. StatuS bits O V and OS indicate any range violations. 1n the casc of an illegal cal cu lat ion (one o f the input ,'aluc. is an invalid REAL tHunhcr oryou attempt to multiply ... and O), M UL R relurns an invalid ,'alue at output OU T a nd scI> "tatu.s bit$ eel, OV a nd OS to "I".

ceo.

REAL dl\l.oloo The function DIV_R int~rprc1.S the va illc, al inplltS IN] and 1N2 as numbeT:! of dala type REAL. It divides the number at input I~ I (dividend) by the number m input lN2 (dhisor) and .tores the quotient;n OUlput OUT. After execution of the c~lculatioD, status h i,", ceo and ee l indicate Whe~T the quotien l i.o nellati~'e, zero, o r posItive. Status bits ceo and ee I tndtclue any ran ge violations. In t he case of an illegal calculation (one of the input values is an im'alid REAL number or you attcmpt to divide ~ hy 00 or 0 by 0), DlV_R rctUnlS an invalid value at output OUT and ,ets SlatUS bits ceo, ec l. OV and OS 10 "I".

'"

11 Mathematical Functions

The following mathe matical function< BN: available in LAD and FBD:
~

Function The mathem:nical funcli,JO is cXCl.'uled if "I" is pTC!<Cnt &llhe enable input or if"po",-e.' nOW! In input E'1. Tf an error occurs in the calcula tion, the enable input IS sellO "0"; othe ....;sc it is SCI to "1". If CX~cullon of !he function is not enabled (E'1 the calculation dOC$ I\Ot take place and L'O is also ''0''.

Sine, co.inc, tangent rue sine, 111"0 cosine. arc tangent


E~ponential

c>

::. Squaring, 5quarc-roOl e"lntction


!>

function 10 base e. naNrallogarithm

"{n.

All mathe1TUlticai functio", procc, .. REAL


numhe~.

IF EN ,,- "1 - or not wired

THeN OUT ;.. Mfct (IN)


IF erro r occurred

ELSE

11.1 Procening Function


Rt pnsentulon

It

Mat ht'1II0tlc!l1

THEN ENO :" 0

ELSE

ENO :" 1"

ENO :- 0'

..-M Mf" .. _1><>1 1 _

The box for a mathematical fu~tion ba.. an input IN and an output OUT in addilion 10 Irn:

enable input EN aod the enable OUtput F'I10 The "rn:aJer" in the bo~ identifies the mathematical fu~tion exuted (for example. SI:" ~1.Ir>d.. for sine).
"a.h 1>0. (ia cumple: ,ioe)
!.AD rejlreHnltllion:

If the Master Conn-ul Rday (MCR) ;~ acti"e, output OUT is SCI 10 ~cro "'hen Tile mathemati , cal function is processed (J:::o. - "I"). The MCR docs oot aff..,t tile E"-"O. The follo,,;ng C11'OTS ~'\lIl occur in a matllemarieal function:
:> Range "iolation (underflow and o"ertl",,')
!>

'"'"0 '" =" ~ "" '" '"0 ~ ="


OU' OU'

:"0 vali d RFAL number as input value

Chpter 1S, "Stan.. Bils", e~pla;ns how the ma thematical fun~tions SCt Ihe SIRtu! bit s. Ex am ple. figure II . I soo'''!O three e~ amples o f matrn:IlllItieal functions. A mathematical function performs the calculalion ID accordance " ',th RE.-U even if no dau.typcs have been dlan:d ...hen uSlDg opc-rat>d. with ab.o]ute addR'cs. In the case nf increm"mal proaramming. you will lind the mathematical functions in the ProIP"'" Element' Catalog (with VIF.W ~ OVf.RVIE'" [Crr] - K ) or L'SJ:.IlT ~ PROGR"~ I En:'tESTS) und~r "Floating_I'olDt fet.".

The inpul ,-. Iue is al input IN and the resuh of 11\1; tnlIthernalleal funclioo is at output OUT. Input and OUtpul are ofdata type REAL. Operalld~ ", rel\.,,~ -d with albolu.c addresses must ... be double ... ord nrcrands. See ChnplCT 3.5.4. -'J:Jementary nata T)-p<:", fQr a d<;S(:ription of the bil S in REA L fOrTnal_

'"

11 . 1 Processinll" Mathemat ical Function

S in e

The value in memory doubleword MD 110 <:On,,,in. an anille in nldian m!l1lS\lTC. The sine of this angle ,5 senerated and ~tored in mcmvry doublewurd MD l(")oa.

I
S'ljuare
~,

MO 110

EN IN

'"

OUT ENO

MO '04

The .quare root of the value in variable ":-'hthValue l" is generutcd Hnd s10TC<l in the

variable 'MilhRoo!"".
SORT

'N
"Global_DB" . MathValue '

'NO
"G~al_OB .

MathRoot "G lobaL Oe". MathValuel

SORT

'N 'N

OUT ~ MathROOt

" GIobaII DB".

'N
The

OUT

' NO

Expo ne nl

~anable

"Re.llh conlalns the i>O"'oeT of e and

"E><~nt.

m
/tExponfInl
t"lgu~

m
' NO OCT
-

'N 'N

"'Reaull

"-'

'N 'N

OCT 'NO

#R ..~".. ~

11.1 Il umplci of Mathe-matiul Function.

l\h lhematlul fun e llo n In a runll ( LAD) YOII can connL"'1 contacts m series and in paral. le i before input EN and after output ENO. The mathematics box itsc lfmay be pl aced after a. T-branch o r in a branch that leads directly to t he left powcr rail. This branch can also have conlact s bef~ input EN and need not be the tlppenno SI branch. Thc direct connection to the left powcr rail a llows you to connect mathemati cs bo.~es in paralle l. Whell eonnectinll boxcs ,n parallel, YOII requ ire a coil to terminate the ranll. If you have not provided elTOr evaluation. as siSn a "'dummy" o perand to the coi l, for examp le a temporary local data bit. You can connect mathematics boxes;n series. If th e EN O OUl put of the prec eding box leads to the EN inpu l of lhe subsequent box. the subse " quent box is processed only if lhe preceding box hat been completed without C!Tors. I f you want to use the result from the precedillg box 95 the inpu t vulue Cor a subsequent box, variables from the telllpOrary lcx;pi data area make convenient intennediate buffers. If you alTllnge several mathematics boxes in one runs (pa rallel 1 the len power mil and then 0

!'uMher in series). the boxes in the uppcnno5t branch a~ the first to be proce!!sed from le ft to right. followed by Ihe boxC'< in the second branch from left to right, a nd so on. You can find funber examples of the representation and ammgemcnt o f mathematical functions in the program "Digital Functions" (FB 111) in the library "LAD_Book" thut you can download from the p ublisher's Website (s~ page 8).
) Ia th e milleal run et lon In a logIc circuit ( FBD)

If you want to have a mathematics box pro" eessed tn dependence o n specific conditions. you can program binary logic operations before the EN input. You can connect the ENO ou tput with binary inputs from o ther functions. For example. you can BrT"IInge the mathematic s boxes in serie!!. whe~by Ihe ENO output of the preceding box leads to Ihe EN input ortbe following box. If you want to use the calculation result of the preceding '00" as input "ai lle to u subsequent box. variables from Ihe temporary local dala a~a make good intermed iate buffers.
EN and ENO ne<:d not be wired.

11 Mathematical Functions

You can find further e~amples ofthe represen tation and arrangement of ma thematical func tions in the program ""Digiml Functions" (FB III) in the library "FBD_ Book" that you can download from the publisher's Website (see page 8).

a~ the inverse functions of the corresponding trigonometric functions. They assume a REAL number in a specific range at input IN and rerum an angle in !he radian measure (Tab le I Ll ).

11.2 Trigonometric Functions


The trigonometric functions

If the pcrmi%ib le value range is exceeded at input IN, the arc function returns an invalid REA L number and ENO - "0" so d sets stalus bit' CCO, CCI, O V and OS to "'I".

"N

COS

TAN

Sine, Cosine and Tangent

11.4 l\lisccllaneous MlIthcmatlcal Functions


The following mathematical functions n\'ailable

a"" also

assume an angle in radian measure as a REAL number at the input. Two lUlits are convemionally used for giving the size of an an gle: degrees from 0 0 to 360' and nodian measure from 0 to 21t (wh e"" II ~ +3. 141 593e+OO). Both can be con\'ened pro ponionally. For example, the radian measure for a 90 anglc is n/2, or + 1.570796e----00, With values greater than 2n (+6 .283185e+oo) . h or a multiple of 271 is subt11lcted unti l the input value for the trigonometric function i~ less than

SQR SQRT

EXP
LN

Compute the square of a number, Compute the square root of a number, Compute the exponent 10 b ase e and Find th~ naturalloganthm (logarithm to base e).

Computing the square The SQR function square. the value at input IN and stOres the result in output OUT. Example:
S~e

"

"Computing the sq uare root" .


~q ua re

Example (Figure 11. 2 or F igun: 11.3, Net" ork 4): Calculating the idle power p, ~ U' I sin{<p)

Computing; the

root

Table II.I Range of ate functions Functioo


P,rmi..ible
~ogo

Value Returned
- ,,12 to ""TtIl

"'"

I to + 1
I 10 +1

ACOS ATA.."

o to ~
,,1 to -~ ' 2 2

The SQRT function extracts the square root of the \' alue at input IN and stores the reslilt in out put OUT. If the \'alue at input IN is less than zero, SQRT sets status b its ceo, CCI, OV and OS to '1 " and returns an in\'alid REAL number. If Ihe value at input IN is ---0 (minus zero), ---0 is returned.

Full range

Example :

c - Ja' - b'

11.3 Arc Functions


The nrc functions (inverse trigonomelric func tions)

Figure II .2 or Figure 11.3, N~twork 5: First, the squares ofvariabks a and b are found and then added. Finally, the . quare root is e.~t,"cted from Ihe SUIlL Temporary local data are used as inter m~diate memory.
(l f you ha\'c d.-clared a or b as a local variable,

ASIN ACOS ATAN

Arc sine, Arc cosin~ and Arc tangent

you must precede it with # so that the Editor rec ognize, it a, a local \'ariable; if a orb is a g lobal variable . it must be p laced in quotation marks.)

,
,..-.:>ri< .. Calc u lation 01 ..actlva
MUL_R
~r

/NOItago "CUfT(lonl

'NO '"' 0"'I- Jtt..REAL 1 'N 'N'


MUL_R

itphl

'NO 'N '"0"' 'N

IIC REAL2

II'I_ REAL1 -

N e twork 5

'N 'NO r-#8_Powe, 'N' QU, IfLREAL2 'N' Calculati o n of h ypota nu ll


1- '0'

h~

II'I_REALI

"
"'-REALI
"'_REAL2

, , ,
Math~matical

FllU n> 11.2 Ex..mplu o f

Function. ( LAD)

Comput in g t he u pon., nt to bue

The EXP function compule> the c_~p<)JI"'lIial value!O base 2,7 18282e+OO) and the value al itlpll! IN (e ) and Slon:s the result in oUlpU! OUT.

The nanu-.llogarilhm is the inverse funcliQn of tbc ellponcnliai function: lfy - c'!hen x -In 'I. To find any logarithm, use the fonnufa log
b
<l ..

fJ-

!in.!! IOlilo
b

You Can calculate any expon=tial "RIlle the fannula

u~ing

whefC h or n is any base. Jf'lou make n " e, you can find a logarithm 10 any base using the nalllralloganttun:
IOlilb" _ In"

Finding the nalura l lo gatlthm

LN function finds Ihe natural logurithm 10 base c (- 2.718282c...oo) from the number m inpUt N and ston:os it in output OUT. Iflhe value al inpUlIN is leu than (Ir~ual to zero, LN sets status bill; ceo. eel. ov and as 10 'T' and returns an invalid R EAL number.

Th~

In the spec ial case for bllse 10, the ("nnuln ;, u follows: IS CI "

'" '

L~tO

- 0.43 42945 . In"

,os

II Mathematical Functions

...!:'ampk. of moth function.


Hetwort< 4 Calculation of r
cH~. pow~r

#Voltage -

MU L_R

<'

'"

OC;

I- ill_ REAL!

ftCurrenl

'"

<'0

"""
'0' <'
OC; -kt_REAL!

'" '"

""OCT
<'0

liLREAL2 MU L_ R

"
"CREAL ! itLREAL2

'" '"

O~

f-- #B_Powe,

'"0

N t twort< 5 Calculation of hYPolanu. .

,,-

<'

'" '0'

<'0

,
f-- #!_REA1.2

o c;
<'0

'" '"

#LREAL! -

ADD_R

<'

'"
'"

OC;

I- IIC REAL3
SQRT

/<LREAL2

<'0
lfCREAL3

<'

0 0; - " c
<'0

'"

Flgu,"" 11.3 fu.ampb of \fa,), om. tical Function. (FBD)

12

Conv~-rs;on Fun~tion,;

12 Conversion Functions

The conversion functions conV~"n the dala type of a variable , figu re 12 , I provides an overview of Ihe data type conversions de scribed ;n Ihis
~hal'lcr.

'CD
3 d ee.

'" '"
'"

~'NVI
INT

1.-/

NEGI

t 2.1 Prucessing

9.

Conversion

Function
Representation In addilion 10 the enable input EN and the enable output ENO. the box for a conversion function has an inpUl IN and a n OUlPU! OUT The header" in the box ident ifies the COnver sion flmction executed (for example. I_BCD stands for the convers ion of lNT to 8CD).
Con.-.nion bu

'" 0"

OINT

OOR lIRNO.. RND


REAL

RNO, TRUNC

0 '"
1

NEGR

Figure 12.1 Overview of the Convc-r.;on I'anctions You can find th e bit descriptions for the data forma'S in Chapler 3 .5 .4, "Elcmc"lllary Data Type"-

(in <",,"'plo: lNTto BCD)


LAD representation;

FBD represontaUon,

" , 'co
eN

I_BC D eN 0"' eNO

fFunction

'"

eN D OU,

The value to b e convened is at input IN and the resu lt of the ~onversion is at output O U T. The data type of th e input and th at of the ()utput depend on the eonv~"Thion fun~ tion . In the con versIOn functlUn OJ R (DINT 10 REAL). for in'l:mee, the input is of type DINT and the out put o f type REAL. The variables app lied mnSI be of the ",me data type as the input or the out put. Jf yon use operands with absolute addresses, the s izes of the operands must be matcbed to the data types; for example , you can use a word operand for data type INT.

The conversion function i, e xecuted if '1 " is present al the enable input (if ~urrent flows in input EN). If an CfTor oc~urs during ~on\'c,-,;ion> the enable output E NO is SCI 10 "0"' ; otherwise, it is set 10 "] ". If execution oflhe function is not enabled (EN - "0" ). the ~onvcrsion does nOI take place and ENO is also 0", IF EN "''' " 1" o r nOI w ired

THEN
OUT:" Confct (IN)
IF errO r occurred

ELSE

THE N
ENO ;= 0'
w,\b Con

ELSE

,"

END

"1"

ENO

,=0'

.. ""

"'<'"ion fun<ri""

'"'

12 Conve,..,ion Function,

Conwrtinll
INT
numb~ ...

The valu~ in memory double"ord MD 120 is interpreted as an [NT number and stored in memory doubleword MD 121 as a BCD nurnbel-.
I_BCD

MO 110 -

, . The \alue ,n vmable C"nl e"DlNT "lllterpreted as a DINT number and stored Convcrung UL\'T Dumber$ a rcal n umber in ,h~ van able "Con" ertREAL" ,
OI_ R "GlobaL OB" . ConvertD INT

'" '"

,"0

MO 122 MO 120

I_ BCD

0'"

..

'" '"

0'" '"0

r-

MD 111

~~

'"
'"

'"0
0'"
"Global_ OS" ConvertREAL "Global_OS", ConvertD INT

OI_R

Con-ertmg
RF;AL number.

. The absolute ~a lue "generated from 'anable I'DlSplay.

'" '" '" '"


'"

0'" ,"0

r-

"Global DB", Convert REAL

#Display

'" '"

'" '"0
0'"
#Display #Dlsplay

#Display

'"0

Figure 12.2 ExHIIlp1eS ofConn1"S'oo FUDclloo.

If the MaSICr Control Relay (MCR) i, ae,i,'c , output O UT is s~1 to zero when the convers ion function is processed (EN - " 1"). The MeR has TlO effN:t on output FNO Not all conversion functions "'\Xl" errors, An error oc~urs on ly if the permissible number range is exceeded (I_BCD. DIJ1CO) or an invalid REAL number if specified (F LOOR. C EIL, ROUND , TRUNC). If the input value for a BCD_lor BCD_ 01 con" yers;on contai ns a pseudo ' etrad, program cx~ cution is interrupted and error organization b lock OB 12 1 (programming errors) called, Chapter 15. "Status Bits". explains ho\\ the conversion funct ions s~t the ,tatus b its. Figure 12,2 shows on~ example for ~ach data type, A con"" .... ion function cOn'-ert, according 10 the <pcci tic characl rrislie tyen if nO ds,s types have been dttlar~ d wh~n using o!",rands with absolute addresses, [n thc C"-'" of incr~mental programming. you will find the conversion funct ions in the Program Elements Catalog (wilh VIEW......,. O VER-

VIEWS [Ctrl - K] or I"SERT """" P ROGRfuY! E LM.-"S) und er "CoD\'erter'",

Conn,,;on function ;n a ru n g (LAD) '(on can connect contacts in series and in parallel ocf""" thc EN input and a tter the b~O oUl_ put, The cooversion bo~ itsdfmay be placed after a T_branch or in a branch lhatlcads directly to the left \Xlwer rail. This braach can alS<l ~a,c con_ Iact, before input EN and it need not be th e uppermost branch. With the direct connection to the left po"er rail you can thus connect conversion boxes in parallel. \\'hen connecting boxes in parallel. yuu req,,;re a coiltQ terminate the rung. If you have not providM ~rror evaluatioo. assign a "dummy" operand to t~e coil, for instance a temporary local data b it. You can connect conversion boxes in ",ries. If the E~O output of the preceding box leads to the EN output of the subsequent box. the ,ubse quent bo~ is processed on ly if the pre ceding box has been completed w it hout errorS , If you

12.2 Conversion oflNT and DINT Nwnbcrs want to use the result from Ihe preding box as the inpul value for a subsequent box. variables from the temporary loeal data area make convenient intermediate buffers. If you arrange several conversion boxes in one rung (parallcl to the le ft power rai l and then further in series). the boxes in the llppenno, t bronch are proee"ed first from len to right. followed by the boxes in the sttOnd branch from left to right. ami so on. Vou can find funher examples of Ihe representation and arrangemCUt of conversion functions in Ihe program "Digilal Functions (FB Ill) in the library LAD_Book Ihal y(>u Can download from the publ isher's Website (see page 8). Co nversion funn ion in a togic dre ui! (FBD) If you wanl 10 process the conversion box in on specific condi tions, you can arrange binary logic operations before Ihe EN input. Vou can connect the ENO outPUI with binary inputs of other functions; for e xample . you Can arrange conversion boxes in scrics. w hereby the ENO output o f Ibe preceding box leads to the EN input of the subsequent box If you wa!\lto use the result from the preceding box as input value for a subsequent box. variables from the temJlO1""T)" local data area make good lemporary buffers.
d~'PC"dence

C ",n \"Hslun from I NT t o DINT The function I_ Dt interprets the value al input IN as a number of data Iype TNT and transfeIN it 10 the low-order word of output OUT. The signal state of b it I~ ( the s ign) oflhe input ;s trans ferred to b its 16 to 3 1 of the high_order word o f outpulOUT Th e conversi on from INT 10 DINT reports no e rrorS. Conven[on from [NT to BCO The function I_ BCD interprets Ihe value at input IN as a number of data type [NT and converts il 10 a 3-decade BCD number .. t output OUT. The Ihree r;g.h l-ju.,\ified decades represent the absolute va lue of the decimalnnmbec. The sign is in bits 12 10 IS. If all bils arc '0. the sigo is positive; if all b ilS are '"I"'. the sign is negative . If the INT number is too large to be converted into BCD (> 999), the I BCD function sets staIUS b ils OV and OS . The conversion docs not take place. Co nve roion from DINT to B C I) Tbe function DI_ BCD function interprets the ,al ue at input IN as a number of d ata type DINT and converts ;t 10 a 7-decade BCD number at output OUT. The sev en right_justified decades represent the absolute value of the decimal Du mber. The silP' is in bils 2R 10 31. Ir " 1I bits are '0, the s ign is positive; if aH bils are 1", the sill'l is negative.
If the DfNT number is too large to be convened to a BCD number (;> 9 999 999), status b its OV and as are Set. The conversion does not lake place.

EN .. nd ENO need not he wired.

You can find further c ~ amples of Ihe represenlalion and arrangement o f con version functions in tbe program Digital Funct ion~ (FB I l l ) in the !ihr.lr)! 'FRD_Book" that you can dOWTl load from the publisher's Website (see page 8).

12.2

Conversion of lNT and DINT Numbers

Tobt. I' 1 Con ___ ,..;on of TNT and DINT Numbers


D~I .

..

Type Cmwor_ '0<

Dat. Typ<: fur

sion

Porameter
~

Table 12 . t shows the conversion functions for [NT and DINT nwnber.. Variables o f tbe specified data type or ab solutc.addressed oJXrands of the relevant si~e must be applied to the inputs and outputs of the boxes (for ex..mple a word operand for data type lNT).

TNT to DIl,a
Th'T to BCD DrNT to BCD DlNfto REAL

, m
I BCD

~, ~,

OUT DINT
WORD DWORD REAL

DI_lICD DINT

D>R

DIN T

""

12 Conwn;ion Functions Con version from BCD to DL'IIT The function BCD_ DI inlCIprelS the value al input N a. a 7-decade BCD number and convens it to an NT number at output OUT. The ,e,-en right-justitied d""ades represent Ih" absolut" value of the d~cimal nun:bcr. The siS" is in bits 2~!O 31. If these bils are "0"-, the sign i, JXI,itivc; if they an: '1 ", the sign ;,; negative. Only bit 31 , ~tah-n into account in Ih" conyer ,ion. If th. BCD number ~ontain. a pseudo tetrad (numcrical valu(: 10!O 15 Or A to F i" hexadecimal), Ihe CPU s ignals a progtammi"g error ,md cal ls organization b lock OB 121 (synchm ni~ali on error), If th is block is ~ot available. the CPU go"s to STOP. The function

Conversion fronl ol:\"T to REAL The function DI_R inle",rel' the valu~ at inpul IN a. a number o t data type DINT and eon,'crt' it to a REAL number al output OUT. Si nce a number in DINT fonnat has a higher accuracy Ihan " number in REAL fOmlal, rounding mak~ take plac~ during Ihe con,crsian. The REAL numb~r is tben fOunded to (he next imcgcr (in accordan"c wilh thc ROU}.,'TI
Iiln~li on).

The Dl R funclion dm's not

r~porr

errors,

12.3 Com'ersion of BCD Num hers


Table 12.2 shows lhe fun ctions fM con,e't ing Hen numbers, Variable, of the specified type of absolutc-add,""ssed operand. oflhe rel~"ant ,ize must be applied w the inpul and o utput, of the (for example a word opcrn.nd for data tYl''' 11'< 1).

Hcn

I scts nO S\aluS biN

00"",

12,4 Conversion oCRE.A,L l"llmbers


Th...,.~

Tabl~

12 2 Co."",,ion o f BCD :-.Jumhers

IJMa 1'ype nmvo:r.,~

""
BCD_ l

[}at" 1'ype for

Paramete,

BCD 10 l"'T

"

OUT

WORD

lNT

are sev~ral functionS for eonv~rting a numb", in REAL fonnm to DINT tonrul1 ("onversion of a fraclional va lue to an integer) (Tab le 12, 3). They diff~r as regards ronnding, Variables of Ih~ sJ"'C ifi~d data type or absolutc addr~s>Ni doubleword operands rnllSt he applied 10 Ihc inputs and outpul S of the OOxes. Tabt. 12.3 , Com'GIS10DofIlEAl" om t C'T ' (DINT" ombe 0

]JCD t{, DtKT

HCrl_Tll O\VORTl Dm

Conversion from J)CD to I.:-IT The function BCD_l inlCrprctS th~ ~aluc al input TN a, a J - dccad~ Bcn number and conTh~ verts it to an [NT number at output three right-justified decades repr~".,nt Ihe absolule va lue oftbc dec imal num~r. Th~ sign i. in bils 12 to 15. If these bits are "0", th" sign IS JXlsilive; ilthey ar~ .')", the sign is n ~gat i 'e. Only b it 15 i, taken inlo account in the con\' ~r Slon.

nota Type ConvCT_


';011 ,,"'ilh Rounding
1'0 "." h igher

'"'
CHI. flOO R ROUND TRu'lC

Data Tyl''' for


P...-.-wxl~
~

0""
DINT
D~"

om.

RFAl
~

ial<ger To no,-l lo",.,. ,n '''ger To nD.. l inleg,'T


Without TOundinlj:

me REAe
intq:~r

O~"
DINT

If the BCD numh~r contains a p.eudo telrad (numerical value 10 10 15 or A !O f in hexadc~ imal) , the CPU ,ignal. a progra1llllllllg ~".(U' and calls organ ization block OB 121 (synchron i ~.a.tion error) . If thIS bl ock is not a\'ailabk, the CPU g""s to STOP The funCiion BCD_l sets no >talus
bil~,

R ounding to the

nc~1

higher

The function CElL inlervrels the value at input IN as a number in REAL fOmlal and comerr, it 10 a number in DINT format al output OUT. CEIL r~tums an inle ger that is greater Ihan Of equal to lhe number to be convened

12.4 Conversion of REAL Numbcni


T~bl~

12.4 Rounding Mooe, forthe Conversion ofll~.i\ I _ Number<

If the value al inp ut IN exceeds or falls short of the range penui"ihle for a number in DINT fonnat or ifil does not corre<pond to a number in REAL format, CEIL sets staNs bi t. OV and O S. Conversion do~. nottakc place.
Roundin~

If the "alu~ ar inpul IN exceeds of falls shon of range penni.sible for a oumber in DINT rommt or if il Jocs not corrc'pond to a numf>er in REAL fonnal. ROUND scts stalUs b ilS OV and OS. Conv~'TSion docs not take placc.
!h~

to the n ex t lower integer

:"0 0 Touod in!:

The function FLOOR imerpr<: ts the valuc at input IN as a number in REA L fonnat and con_ vert" it to a number in DtNT fOIDm! aT OUlpU! OUT. FLOOR returns an inleger lhat is less than or ~<iual (0 the number to be convened. I f the valu~ at input IN ~xc""ds or falls shon of Ihc rang~ permissible for a number in DINT format or ifi! d<>cs n<J! correspond 10 a number in REAL format. FLOOR SCI>; ,talu, bils OV and OS. Conver.;ion does not take pla~c.

The function Tl~UNC inlcrpn;ts the value al input IN as a number in REAL format and con"erts il tn a number in DINT format at nurpur OUT. TRUNC relUn15lhe inr~gercompon~nt<Jf th~ number to be convene<!; the m.ctional component is "truncatcd" ,
If the value at input TN cxcce<ls or falls shon of
th~

Ro unding t o t h e ntll t integer


The funcri"n ROUND interprels the value al inpul TN as a number in REAL format and .onv~rH it to a number in DINT fonnat at output O UT. ROUND Tcturns Ibe nexi inl~ger. If the result lies exactly betw~en an odd and an even number. Ihc cv~n number is given preferencc.

range p.:nnissible for a number in DINT format or if ir docs nOI COIrcspond tn a number in REAL format, TRUNC s~ls slatus b its OV and OS Conv~"",ion docs no! lake place .

Sum mary of con' erslo ns from R E AL


to D IN T Table 12.4 shows the differenr eff~cts of the func\ions for convening from REA L tn DINT. Th~ range - I to ! I has been chns~ll as examp le.

12 Convenion FunCiioru;

12.5 M iscella n('Ou5 Con v('n ion F un c tions


Other available conve",ion funct;O!I$ are onc's eompkme!l1 generatIon, negation. and absolutevalue lIeneration of a REAL number (Table 12.5). Variables of the spedfied data Iype or absolute. ftddrcss ed operand. of Ike rei evant ,ize IIlUSI be applied to the inputs and out pUIS of thc boxes (for example a doubleword operand for dna type DJNT).

Table 12.5 Misc<:lhme<>UO Con"mion rLlnCllOlll=,-_

One's complement D!l'o'T

O nc',

cump~ment

I"'T

The function !NV_[ negatcsilie value II inpul IN bit for bit and ....rites ilto output OloT [SV_ I replace, the 7.C"fIXS ,,~tb ~s and \~ce \"trY. The function [NV_ , does nO{ signal erron. O ne', eon' plement DINT
The function INV _01 negates the value II input IN bi t for bit and writes illo output OUT. INV_ 01 replaces the zeroeS with Oncs and vice versa. The funclion !NV_01 does nO! SIgnal errors. NEG_OJ i~ identical t<l multipli'lItion by - I. The function NEG_DI sets StaNS bIts CCO. CCI.OVandOS. Negatio n REAL

Negatio n INT
The fUnchOn NEG_I interpret. the \'alue 8t input IN as an TNT number. cbanges the SIgn throuih two's complemenl generation. and ...Titt'S the converted .-alue to OUlput OUT. NEG_' i5 identical to multiplication "'nk -I. The function NEG_ I iClS italUS bilS cco. CCI. OVandOS.

The function NEG_R interprets ,he va lue at input IN II.> a REAL number. multiplies this
nl,llIlber by -I. and "Tit~s 11 to outp ... t OUT. NEG_R ehange. the .ian of the manti$511 even <In an in"alid REAL number I'EG_R docs not ,ignal errors.

Neltllion DINT The function NEG_D1 inlerprccts tke value at inp ut IN ai a 0 Th.' T number, change, the .iin through two' ~ com plcme!l1 generation. and writes the eonvened value 10 output OUT.

The ABS function interprets the \'8.1ue al input D' ., a REAL number. generates the absolute n lue from thi, number. and writeS It to OUlpUt OUT. ABS sets the sign of the mamina to "0" e,'en on an invalid REAL number. ASS doe. not signal errors.

13 Shift Functions

13 Shift Functions

T he shift fu nctions shift Ihe contelll. of a vari able b il by bi t 10 Ihc left Or right. The b ils shifted olll arc either lost or are uscd 10 p a d thc oth~r side of the variable. Table 13.1 provides an o verview of the shift fu ncI;',n .

13 .1 Processing a Shift Fuuction


Repre.entation In addition 10 an enable inpul EN and an enable outpu t ENO. the box fo r a shift funct ion ha, an input IN, an input K, and an Olltput OUT. The hcader" in the box identifi es the shift function executed (for examr1c. SHL_ \V 'tands for shifting a won! v" ri"ble 10 the left).
Shin bQ ~ (i" oXH",]>le : .hi ll ", len
lAD , epresentation
"'~rd

p lIl have differen t data types depending on the shift fun~tion . For ex ample, input and OUlput atc of typ~ DWORD for th~ ,hill fun clion SHR_ DW (shift a doubl eword variable to the right) . Thc variable, applied most be of the .am e dala type as the inp ut Or output. If you use opelands with absolute addresses . the operand SiZC8 must ae~ord with the data lypeS; for instance, you can l'-V a w ord operand for dam type INT. lup ut N has data type WORD filr ev~ry shift fu nction . See Chapter 3.5 .4. "Elem~nmry Data Types" for a d escription o f the bits ill ea~h data fom,a!. FUBction The shift function is Gx<:cukd ,rI' i. present at [he enab le input or when power" flow, through input EN END is Ih en " I . If ex ecuI;on of Ihe function is 1I0t cnabled (EN - "0") . the shift does not lak~ place and ENO is a lso IF EN == -1 " or n ot wired THEN ELSE
OUT :- Sfet (IN, N)

by word)
SHL_W

,.
F BD representation ;

.'

, .. j -,'.

'" =," '"' = 'N


W N

,"0
OC,

0.

_W

oc, f-'"0

END:

.,.

END: = "0"

wi,!, Sf", ..

,\Un rune ';""

T he value to be shifted is at inpu t LN. the number of plac es 10 be sh ifted is at input N. and the ",,"ult is at oulPllt OU T. The input and the Ollt Table 13 1
Ov~rvicw

When Iho Ma<ter Control Relay (MCR) i. acti vated . output OUT is set 10 zero when thc shift function is proce ssed (EN - "I"). Tbe MCR does not affect OU!Pllt END. Chapter 15. StalUS BilS'"
e~plain.

uf Shift Function, Double"'Ofd


Variah l.
V~ri~bk

how the

shift functiOn> set the starns bits.


Ess ml'le<

Shift Fw>cti"IlS Sh ift left Shi ft right S hift w ith silfll \(otat. left I{otat. right

Word

'"' '"R
,~

SIll._ [JW
,,~

DW

hgnte 13.1 gives one example each for var ious shift functions .
In Ihe case of incl\.'IllCn lal p rogramming, yo" wii! find the shift funct ions in the Program Ele men ts Calalog (wilh Vlt-W --> DYFRVlFWS [etrl

SliR 01

. .

ROC OW
ROR OW

13 Shift Func tions

Shiftin!: ",ord ..ari_bl ..

The value in memory word MW \3 0 is ' hifted 4 position, t() the left and """,d in men'o,), word MVi D2.
SHL_ W

'" '" - '''' "


MWl30 -

'"0 0"' : - MW 132

MW 130

W11161J4

='" '"
-

SHL_ W

" ' "0


SHR_ OW "G lobal DB". ShiltOff-

0"'

MW132

Shifting doubleword
variabl~.

" Th~ value ill ymable " Sh,ftOu " lS , lufted fight by " SluftPos p'"",on. ancl stored in Shiftoft'

SH R_OW "Global DB". ShillOn: G IoI:>..I_OB".

ShifI?os

'" '"0 '" 00' r-"


SHR_ I

"Global DB" . Shil!Off-

"G lobaL ShiftOn

". '"
" "

00' ' "0

" (;lo.,.,I_ OB". . ShiftPo.;

Shifting with sIgn

The , an.ble I"ActVal" shifted. wnh SIgn. 2 posmons to {he nght ancl tmn,rorred (0 the vHriabl. liDi'pla," .

I>ActV,,1 -

W#16#2

'" '" "

'"0 00'

r-

JtDispl;>y

#Ac!VaI

W# I 6#2

='" '" "

SH R_I

00' ' "0

Jt Dlspiay

Figure D . l hampl.. of Sh ift Functions

" K ] or I:'SERT -) PROGRAM H EM[YTS) under


"S h i ftlROla {~".

Shifl function in

rung (LAD )

You ~aTl e mlTl e<:t contJ{\S in s~fies and in parnl leI be rore input EN and after output END.
T he shift box itself DllIy be plac~d a fter a Tbranch or in a bnm ch IhHI Icads dire<.'1ly to the le ft power rai l This branch can also rune conlaC," before input EN and it n~~d not be the UPl"'ffilost branch . The direct connection 10 the left pow~r rail allow. you to connect shift boxes in parallel. When co nne<;ting boxes in paralleL you requir~ a coil 10 tenn inatc the run g. If you have not proy id ed error cva lual;on. a.sign a dummy' ope<md 10 lhc coil. for example a teml"'rary local dala h it

You can connect shift boxes in sC"rics . If the ENO OUlpUl from tb. preceding box leads to the EN input of the s~bscqm;m box. Ib~ subsequent is ~l,,"ays proc~ssed. If you want It, use lhe r",uh from the pr~~cding box as input valu~ for a ,ub,equem box. variables from the tcmponry l ocal data area make a con,enienl imcrm~diat~ buffer. If you arrang e several boxes in one rung (parallel 10 Ihe kft pow" rail and then timber in series). the boxes in Ihe UppermoSl bran ch are rroce"ed r;"" 'rom left to right. followed by the box~s in the second branch rmm left to right, and '0 on. You c~n iind furth~r examples "flhe re presentation ,md arrangement of shift functions in the li brary Dib~tal Fun~tioIlS program (.FB ll!) in Ih~ library '"LAD_ R""k"' that you can down_ load from the publi'h~r'~ W~hsi {c (see page 8).

1).2 Shin
S h ift fORCll0 4 in a ru nlt ( FIlD)

If you want the shift boJ( processed in depen_ dence on specific condinons. you can arrange binary logic operations before the EN ;npln, You can connecl the ENO ourpU! with binary input. of olh ..... functions; for instance, you can arrange shift bo~es in series, "'hereby the EBO
output oflhl' """,OOing bo~ leads 10 the EI'- out_ put of the jub.~equent i>Ql(, If you "'am 10 use the re~uh from the preccrl'"lt box as input valuc 10 a subsequent box. variables from the Temporary local data area make coovenknt inlcnne<li

The shift number al input N :spccitle$ the num_ berofbit position. by which the contCn!S Ire to he shifted. It can be a constant or a valiable. If the shin number is 0, the function is not cxe, <:uled: ifi! is !>fcuter than 31. the outpUt variabl e contains zer(l following execution oflhe SHL_ ow fUOCl1on. Shift word ,"ui ab lc tn !h e r ight The shift function SI!R_W sb ifts the content . of the WORD variable a! input TN bit by bil to the right the number of posilioos lipcdfied by the .}nn number a, input N. The bil positions ~d up by the shift are padded with .tCroeS. The WORD variable at output otrr contain. the result. The .bift number at inpul N SJl'C<'ifies the n ~m ' ber o rb;1 positions by which tl>e contCllts are to be shifted. [I can be a COlmant or a vmiable. J( the ,hift number is 0, tbe function is nOI executed: ifil is gn:at.,.. than I !. !be OUlpUt variab le contains lero following execution of the SHR_ W !Unclion. Sh irt
dnubl~"'ord

ate buffen.
EN and ENO nc'Cd not be WiTN.

Yo u can find funhcr examples of the fepre!en_ talioll and RlTtiogernent of shift fu nction. in the

program "Digital function," (fB 11]) in the library ~FBD_Book" thaI ),OU can do ....TIlo,ad
frorn the publisher'. Wcb:Slle (sec page R).

13.2 Shift
S hift word VII r t. hle In the len The shi ft function SHL_W sh ift. (he conlents of the WORD variable at input IN b i! by buto the left Ihe numocrofpmitions specified by the shift number at input N. The bn posiliQllll ~ed up by Ihe shIft ace padded with :t~s, The WORD variable al outpUt OUT contains the result.
~hin number at inplll N specific. Ihe numberofbil pO.ilion. by which the COll!emS are to be shific:ci. 11 can be a Con~t.anl or a \ariable. [f the shin number IS O. the function is nQ! executed: ifi! is grealcr than I!, Ihe OUtput variable conta ins ~eT"Q foltowin!! execution of the SH L_ \'1 function.

... ri. bl~ to t he right

Tbe .hift function SHR DW sh ifts the COntentS oflhe DWORf) variahle &1 input IN bi! by bi lla the ria:h! the number of position. specified by II>e shift number at input '-'. The bit positiOn! freed up by the iihif't are filled wilh "eroes. Thc DWORD variable at output Otrr conla;ns the result. Tbe shift number al input N specifies ,he num ber ofbi! posi!ions by "hieb the contcnlll are!o be shifted. It can be. constan, or a vanable. If the .shift number is 0, 'he fUnclion is oot executed: ifit IS grcatertban 31, the output variable contain. zero following eXl'<:ution of the SHR_ OW funclion. Sh tf! word ,'. n able ..Ilh .ign The sh,ft function SHR_I sh ifts Ihe COntenl1 of the TNT vuiabk a! input IN bit by bil 10 'he ri ght the ~umbcr of positions spcci tled by the shift number at input N. Thc bil positIons freed up by the ,mil are filled ".. ilh tbe signal state of bit 31 (wbich is the sign of em N T number), thai is. with ''1)- if tbe number i. positi.e and

The

S h ift doub lf ..o rd n rl . ble 1 Ibe 0

1~f1

The .bift funClion SHI.._"W shifts the comenls of the O WORD variabk a! input IN bi! by bit to lhe left the number of positions spcd fied by the s hift number 81 input N. The bit positiQllll freed up by the shiA are padded with zeroes. 11le DWORO vanable at OUtpul Otrr contains the !"<."Suit.

13 Shift Functions

with "I " if the numb..r is negmiv~. T he I:"IT variable at output OUT contain< th~ result. The shift number at input N spec ifIes the numher of bit positions by which the contents are to he shifted. It ~"n be a ~(mstant or a variable. If the shift numb<:r is 0, the function is not executed: ifit is grual~T than 15, all bit pos itions in the output variable comain Ihe 'ign following e"ccution of the SHR_I fun~ tion. For a numb..r in data format tNT, ,hifting to the right is equivalent \0 division with an exponenti.,! nWIlhcr to ba.e 2. The exponent is the shift nLlmber. The result of snch a divi,inn ~"rre _ 8ponds to the integer rounded down.
Shift doublew'lrd ,'ariahle ,,;th s i::n

J 3.3 ROfale
Rotate doubleword varIable to t h e left

The ,hift function ROL DW shifts the content, of lh~ DWORD variable Bt inpu\ IN bit bybi t to
Ih~ left thc number of po, it ions sp<.'cificd in the shift number at in put N. The bi\ positions freed up by the shift are p added with (he bit position, that were shifted out. The D\VORD variahle at ompu l OUT ~ontains the result,

The 8hift function SHR_ DI shifts lhe ~ontcnls ofthc DTh'T variahle at input ll\ hit by bit to the ri ght the nu mber of positions srec1fi~d by tile shi ft numher at input N, The bil positions freed up hy the 'hift are padded with Ihe s ignal state of'bit 15 (whi~h is the sign o[ The DTh], num ber), that i,. with "0" if the number i, po" it ive and with " I" if the numbcr is negativ e . The D[NT variabk at oU lput O UT conta ins the re suit , The shift number at input N spccifi~ s th~ num ber of bit positions by wh ich tb~ contents are to be "hift~d. [t ~an be a conSlalll or a variable. If th~ "h,1I number is 0, the function i, not c..'\c cutcd; if it is greal~r than 3 j, all bil positions in !be outpnt var iable contain the si gn [ol1o"ing e )(ccution of the SIIR_ D[ funct ion. For a number in data format DINT, ,hi fting \0 the nght is equivalent to d ivis ion with an e .~po n .. -n\iaT number to ba , e 2, The expon ent is \.he sh m number. The resuit of snch B d ivision corresponds to Ihe integer rounded down

The ,hit[ nnmber at input N sp"cifie s the num her ofbil positions by which Ihe content, are to be shifted. It can b<; a constan! or a variable , If the shift number is 0, the funnion is not ~x e cuted: if il i.' 32, the Contents of the input variable me reta ined and the status bilS are ,el , If the shift number is .>3 , a Ihift of one position is executed: if it is 34, a sh Jft o f two positions is executed, autl so on (shining IS carried out modulo 32 ).
Rotat~

duublcword va rIable to tb. right

Thc sh ift fu nc tion ROR_ DW shills the coments o fthe DWORD variable at inl'nt TN bit byhi! to the right the num ber of positions srecified by the shift num\>er at input N. The b il po,ition, fre ed up by Ihe sh ift ar~ padded w ith the bi( positions thaI were shilled out , The OWORD variable at outrut OUT eonwins the resul\, The shift number at input N specifi~:l the num_ ber of bi t po,ilions by which Ihe con(~-ots are to) be shifted . h C,m b.. a constant or a variahlc . If th e sh ift number i, 0, the function is not ex e cuted: if iI' s 32, (he eonte1l1s of the input variable aN: N:lained and Ihe ,tatu, bit' are sd , If the shift numb~r is 33, a ,hift of one position is cxec1l1ed: if Ihe ,hift number is 34. a shift of two pO., ilions is exc~uted. and '0 on (shifting is ex ecuted modulo 32) .

'"

14 Word Logic

14 Word Logic

Word logic combine, th .. valu es of two vanabIes bit by bit accordmg to M'D. OR. or E"dusive OR. Th e log ic o!,<,ration may be applied to words or doubl='ord <;. The available word logk operations arc listed in Table 14, I.

TobIe H.l O,-eryi.w ufWor<! Logi c Opcnuion5


Word logk "P"ratl<>n
With.
w~

variable A-, D "


"'iAND_ W WO' W WXOR W

ooubJewurd v"';able
WAND_ DW WOR - OW
WXOR OW

0'
14.1 Processing Il \Vord Logic Operation
Repn~~entation

Exclusive OR
Fun ction

In additi"n to the enable input EN and (he enable output ENO, the box for a word log ic oJ)<Oralion has (wo inputs, IN! and IN2. and one outp"t. OUT. The "header" in Ihe bo" identifi es (he word logic operation .x~cUled (for .>:campIe. WAND_ W siands for word ANDing).
Word lo~i' bu (in cnmp le; 1\.'/0 operati"" "'oro b)' "otll)

The word lo gic operation is executed when I " is pre<~nt m the ermble input (when power flows thrm,gh the inpu( E"') _If e"eeu!ion of the operalion is not ~-nabled (EN - "0"). the open!tion does not take p lace and EKO is al,o "0"
IF EN ". "1- or not wired T HEN ELSE
ENO:" "0-

OUT:" lN1 Wlog lN2 ENO: - -' "

LAD representation;

WAND_W ENO EN

IN1

OUT

'"
FBD ,"presentation;
WAND W

"

If Ihe !>1aster Control Re lay (MCR) is active, output OUT is ,ello zero wben the word logic o!,<,nllioD is exec utcd (EN - " I"), The MCR docs not affect the ENO output _ Word I"Sic operation. gene['~tc K result bit hy bit. Bit 0 of input INI is comhined w ilh bit 0 of inputlN2. and the ",suit i. stored in bit 0 of output OUT. The same is done witb b it I. bit 2, and so on, up 10 b its 15 and 31, Table 14, 2 shows the result formation for a ,ing]e bit. Chapter 15, --Starns Bits", explains how the word logic operation' set the SlatuS bits ,
E~amples

INl

OUT
ENO

lN2

The values to be combined are at inputs IN1 and IN2. and 'he result of the operation is al outp"t OUT, The inputs and the " utput have different data types. dependin g on the operation : WORD for word ( 16.bir) o!,<,rations, and nWORD for doubleword (32-bit) op erations, The applied variables m us t be of the same data type as the inputs or rhe output, See Chapter 3 .5.4. "Elementary Data Types". for a description "f the bits in the vari ous data form ats.

Figure 14.1 show. one example for each word logic o!'<'ration. In the cage of incremental programming, you will lind the word logic operations in tbe Pro-

14 Word I.ogic

Tlo bl~ 1~ . :

R~" II Funn.1OI11n Word Logic Openl1 C u'"


ContC1lf>< ..finput TNt

C:..."enllO nf ,nrut TN2 R~ull w ith AND Knulr wi,h OR Reo"l, wi lh EM'\u.ivc OR

0 0 0 0 0

, , , ,
0

0 0

, , , , , , , ,

lMCIS before inpm EJ\ and il need not be the UJ'PCTl'"I'OSI brnneb .

The direct connection 10 the left power rail allowo you 10 connect won.! logic boxes in par alld. When conne<:fing bo"c~ in parallel, you require a coil to \erminate the ruog, If you have 1101 provided ~lTor .. valu&\i011, "S~'1>Il " dummy" operand 10 lhc coi l. for ex"", plc a temporary local data bit.
VOl' can e<mnect word l<>gic boxes in .cries. If the E:'-IO ompu! from the prcccdinil tx.>x l~ads t<> thc EN inpm of the subsequent boA, Ihc subo;c quem 00.' is alwaY" processed. If you w&nl '0 un the resuh of the prcceding hox as input value for a subsequent box. "art&bles from thc temporary l<x:a l data an:~ make con"enient mlc n m:diate bulf~Tll . If you ammge several ,,ord loak 1>u"~">1 ;n one rung (paraUd \0 the left power rniland tben further in series), the bo~e" in the uppennoS! branch are proceo.,ed firsl from left to riiht. fol

gram

meme~! ~

V! ~WS

Catalog (wilh V!EW...". O VER. LCn! KJ or INSERT ...". PitOl.iMM Ell! '

Mr:NTIl) uodC>" " Word Logic".

Word IoKie In a rung (LAn)

You can ammgc COOlatts in ...ric3ltDd m paral


leI before input EN and a1ler output 1"0. The "oro logic bo~ Llsclfma y he p lace<! a fter a Tbranch or in a branch lbal1cads dirlly 10 lhe len pow.". ",;t . This brancb can alS<.> bave con

The four high.".<kr b ttl of memory word MW 140 arc .1 10 .-0"; Ihe ""u l, ;.
stored in m<;OlOrv w o rd :>.1W 142 .
WIIND_ W ENO
O~ f -

OR

MWI40-

W.,6011FFF
IOIl:I~

'N 'N ' 'N'

MW 142

- 'N J.tw 140 _


W1f16/l"FFF

WANO_W
O~

Van ablcs wtoglc'\al l and \\ LoglcVal2 al'<' OR~d bu Cor bu lind tbe ",.ull oretl in W1.Oj;ICRCi lt'.
WOR_OW

..

..

..

..

'" 'NO I - MWU2 '"


WOR_OW

"Globio l OS". 'M..oglcVal j .

"

'"0
"GlObal DB".

"Gk>l><!ol OS" , lNloglcVall "Global OS". WLOQIeVal2

~~v~r

'N ' 'N'

0"' I - WLogkReall

"

'N' 'N' 'NO

0"' f-

"Glob31 OS"

WLOQIcRestl

t: ,du.h 'e-QR 'oglc

The ,,due i!C11<"I'lO,e<! by comb inin.l! n riabk.,. "lnpuI &nd I/\fask with Exclush e..()R is w ' "8riabl c ~ ~uff.,.

I c-~----1 EN WXOR_W t ENO+-- - - - - i


" /l'lropul tIM. .k
Hgu~

iIIflput ll'Masl< -

INt lN2

OUT I-- #Su".....

'N
IN1 IN2

OUT
ENO

I-- /ilSuIIer

14.1 Eumpko of Word toll'<' ep.ro.t;ons

14." Description oftbe Wurd Logic Operations spooding bit in both values tn be combi ned is
'" ]"

lowed by the boxes in the second branch from left to right, and so on. You can li nd timher ex~mplcs of thc r~pre,en tation and arrangement of word logic operations in tho program "Digital Function,' (HI Ill) in the library "LAD_ Book" that you. ~an download from the publi sher'. W~bsite (see page 8). Wo rd lo gic In H lo gl~ ci r cuit (FBD) If you. want to have the word logic box processed in dependence on 8pccir.~ condition s. you can arrange binary logic operat ions before the EN input , You can connect the ENO outp ut with binary inpms from other functions; for example, you can arrange word log ic box., in seri es, wbereby the ENO output of the preceding box lead, to the EN input of the .ubsequc-nt bo" , If you want to u,e the result fmm the preceding box as input value for a .ubsequent box. variables in the temporary local data area make convenient intcnnediatc buffen. EN and E:--JO need not be wire d. You ~an fLOd further cxamples of the repre,en tation and amtngement of logic operation. in the program " Digital Functions" (FB I I I ) in the library "FED_ Book" that you can download from the publisher'. Web site (see page 8) ,

..

Since Ihe b its that are "0 at inp~t IN2 also .et the eorre'ponding result bits to '0" regardl e~s o f what value thc,e bits have at input IN I , we also refer to these bits as being "masked", Masking i. th e primary use for the (digital) AND operation. OR ope r Rt lon OR combines the individual b its oflhe v.lue a l input [}.II with the corre'ponding b its of the ~alue at input!N2 according to OR. A bit >sult word OUT will be "0" only if the corre'pooding bit in both val ues 10 be combined is "0". Since the b its that are ., I '" at input IN2 also ,..,t the corresponding result bits to " t " regardless of what value thcse bits have at input INI, we also refer to these bilS as being "masked", Masking i. the primary use for the (digital) OR operation , EIcl u slw OR oper a tion Exdusi\ e OR combines the individual b its o f the \'aluc at input [)-ll with the correspondi ng bits of the value at inpm IN2 according to Exclusi, 'c OR. A b it iu result word OUT will be "1 '. only if tbe corresponding bit ;n only one of the tWO value, to be combined is .' I" . If a bit at input IN2 i. "I", Ihe corresponding bit in the result i~ th~ reverse of the bit at the sam e posilion in IN!. In the result, only those bits w;th opposing signal statCS in IN I and IN2 priOT to execution of the digital Exclusive OR operatio n will be " I ". Locating bits wiih opposing signal states or '"negating"' tbe . ignal states of indiv id ual bit. is the primary use for the (digital) Exclusive OR operauon.

14,2 D escription ofthe Word Lo gic Opera tio ns


AN I) operat io n AND combines the individual bits of the value at input TK I with tbe corresponding b its of the val ue at input IN2 according to AND , A bit in result word OUT will be " 1" only if the corre-

Program Flow Control

Program Flow Control

LAD nnd FIlD provide you with a variety of options forcomrolling the flow of the program. You ~an elt;t linear program eltecution within a block or you can Sl!ucture the progr"m with pn:!.vammable block calls. You can affect pr0gram eltecution;n dependence on "alues calculated at runt in",. or in dependence on process parameters, or in accordance with your plant st"tu.s.
TIle Itatuti htU pro,'ide information on the result of an arithmetic or mathematical function and on errors (such as a range violation during a ca leulat;on). You can incorporate the signal sUItes of the status bilS directly in your proaram usinjj: contacts .

I!I

You ~an usc Jump function. to branch unCOnditionallyor in dependence on the RLO.
A funher method of affecting progrllm execution is provided by the Muter Cont rOl RelA Y (MC R). Originally developed for relay comactor CQIIIrOIs, LAD and FBD offer" solW-lIre version of this program control method.

SlalUS Bits Status bits RLO, BR. CCO, CCI and overflow; setting and evaluating the stat us bin; using the binary result; ENIENO Jun,p Func thms Jump unconditionally; jump in dependence on the RLO Mint er Control Rday MCR-dependence; MCR range; MCR
=~

16

17

You can USe block functions to struCIlU"e your program. You can U$e function s and function block5 ag8in and ag5in hy defining block panmeter . Chapter 19. "J31ock Parameters". contains the examples shown in Chapter 5. "Memory Functions", and Chapter 8. "Counters". this lime programmed as functiun blOCks with block panllneters. These function blocks are then also called in the "Feed" example as local instancC$.

18

Bl ock Functions Block type . block caU. block end; stalUS local dalll; data block TC,ister, using data operand.; handling data blocks Block Pa rametcn Parameter declaration; formal parameters, actual parameters; passing parameten; 10 called blocks; Examples: ConveyOr belt, pans counter and supply

19

no

15 Status Bits

The status bits arC binary "flags" (condition code b itsj . The CPU usc, them for controlling the binary logic opcralioru; ami sets them during digital proc essing. You can check these statuS bits or act upon specific bilS. The slatus bit, ",e combined into a word, the SlaWS word. Ho,,ever. you csnnot scces. this slatus word wilh LAD or FBO.

LAD to the fm;t contact in a network , an d HlD to the first binary function input.

Ln

A bitlogi" st~p e nds w ith a binary value assignment (e.g. of a 'ingle coil or an a-'Signme nl) or w ith a conditional jump or a block change. These SCI IF C - "0". Hesu lt of the logic o p era tlon (RLOj

15.1 Description of the St utu s Bits


Table 15.1 shows the available status bits. The CPU uses the b inary flags for controlling the b inary functions ; the tl igital flags indicate mainly results o f arithmetic ami mathematical functions. Fi rst c heck T he fFe status bit 'lc~'TI> Ihe binary logic wi th;n a logic control system . A bit logic step always starts w ith /Fe - "0" anti a binary check instruction, Ihe first check. The firs! check sets /FC="I " T he fLr>! ehcek eorre,pondsin TK bie
1 ~. 1

The ItLO ,talu, bit is th" intcrmediate buffer in binary logic operations . In (he first check. m e CPU tran,fer. Ihc eheek r~sult to the RLO, ~ombi nes Ihe ch eck result w ith the Storctl RLO on cach subsequent eh~ck_ and stores the rcsult. in turn, in the RLO.
You can store the RLO with thc SAVE coi\Jbox in the binary ..."ul\ BR. Mcmory functions . timers and counters arc conlrolled using the HLO and cenain jump functions are execU1ctl. Thc RLO corresponds in LAD to the pow~r (lowing in the rung (RLO = "I"' is the sarnc as " rower tlowin[).

Slams il its

Bina ry Flags

!Fe
RLO
STA
OR BR

first Chock Re<uit of logic


0r><r~tion

Slatu,
Stat u, "it OR

StatttS bit STA ~orrespontls to th~ signal ,lale of Ihe che~ked binary operand . In the case of memory fttnctitms_the value ofSTA is Ihe , a me as the writlCIt ,a!ue or (if no wrile op"ration takes place, for cxarnpJ<: ;fthe R LO - "0" or th e MCR is acti , 'e), STA corresponds to the val ue of the addressed (and unmoditi etl) binary operand.

Binary ""uit

Dlgltol F1a ~. OS Ston."<i o,crflow


OV

Overflow

In rhe ca,e if cdg, evaluat ion' FP or fN, the \'al"e of the RLO prior to the edge evaluati on i. ,(orect in STA. All Nher binary f unctions ,et STA = " I",
The STA status bit has no effect on the processing of thc LAD or FRO fun n iortS.

ceo
CC I

Condition code (itala,) bil 0 Condition code ("atu,) bit t

nl

IS Stalm Ilits Status bit OR Status bit OR stores the re.ult of a fulfillw series circuit o r a fulfillw AND condition and indicates to a subsequemly pX:cs,ed paJ"llllel circuit or OR function that the ~sult bas already been determined. All other binary functions ,eselthe OR status bit. O verflow Status bit OV indicates a range violation or the use of invalid REAL numbers. The following functions affect the OV status bit: ArithmetIC functiollll. mathematical funclions, som e convers ion functions, REAL comparison functions.
1 ~.2

Setting the St al u S Bits

ThI: digilal functions affect statm bit. CCO. CCI. OV and as as shown in Table \5.2. You can check. tbese StalUS blls immediately following thc function box.
SIRI uS bits in INT gil d DINT calcu la tin n. The arithmclic function.; with data fnmllll$ INT and OiNT set all digital starns bits. A result of zero scts ceo and ce l to ''O~. ceo - ''0'' and CC I - "1" indicates _ positi~"C" result, CCO"1 ~ and eCI = "0" indicalts a negative result. A range violation ~I S OV and OS (please notc tbe Olher meanina o f CCO and Cel in Ihe casc of overflow). Division by zero i5 indicated by all digital status bits being set to "1 ". Stat us bits In REAL ukul. rio ns

You can c heck Ihe OV status b,t directly.


Srored on, rn ow

The OS slatus bit Siore s a sci OV Status bit: Whenever the CPU sets status bil OV, il also scts status bit OS . Howcver. while the nexl properly e~ecutw operation !"!:Sets OV. OS remains SCI. This provides you with the oppoTtunity of evaluatina a range vioillion or an operation wilh an invalid REAL number. even al a later point in your program. You can checlc status bit O S directly. A block change resets Ihe OS status bit. Sums blls CCO and CC I (condition code bits) Status bilS CCO Bnd CCI provide infom18tion Oil the resull ofa comparison function, an arithmetic o r mathematical runction. a word logic o peration, o r on Ihc bit shifted OUt by a shift function. You can check all combinations of CCO and CCI direclly (s~'C' below). Binary
r~SQ II

The arithmetic functions wilh dala formal REAL and the mathemalical functions sct aU diaital slatu" bits. A result of7.cro setS CCO and CCI to "0". ceo - "0" and CCI - ..... indicaleS a positi\"C" result. CCO - . \ "and ce I - "0" indi_ catcs a ncgative result. A range violalion '1:\5 OV and as (PlellK note the other meaning o f CCO and CCI in the case o f overflow). An in\"ahd REAL number is indicatw when HI! digIta l stams bits arc sel to "1 " . A REAL number is rercrred to as "dcnotma lized" ifit is repreuntcd with reduced accuracy. The exponem is {hen lero; the absolute value of I denormalizcd REAL number ;" Ie" than 1.17!! 494 x 10.18 . 57-300 CPU, rrcal denormalizcd REAL Illlmbcrs lIS though they were 7.cro (also sce Chapter 3.!!.4 , "Ek"1llcnlmy Data Type,"). Slal u$ bits for co n"enlon ruu ctio ns Of the con\'ersion functions, the two'S complements affect all diaital stams bits . In addilion, the following conversion functions set SlalUS bils OV and OS in the event of an error (range violation Or invalid REAL number):
I>

LA D and faD usc 5tatu.5 bit BR 10 implemelll the EN/ENO mechanism for bo~es. You can abo set, re~Ct or check SIatus bit BR yourself.

I_BCD and DI_BCD: Conversion of It-.'T and DINT 10 BC D CEIL, fLOOR, ROUND. TRUNC: Con"crsion o f REAL fO OU>.'T

:>

222

15.2 Sel1ing tile Statu S Bits

T"b.llo 13.2 S otting the Statu. B it>

I..'OT calcul.tion
The ",.uit is:

DIl'iT c alculotlon

ceo

CCI

< 32768
(ADD_ I. SUB I)
<

32 768(MUI.._I)

" ,
0

- 32 768 to

, "
0

, , , , ,
0

ov

The ,ult i.
<

CC"
0

147483648 (ADD OJ. SUB OJ) 21 4 7483648 (MUL 01) 2 147483 648 10

<

"

+110 + 32 767

>+32 767 (ADD I. SUIUJ ,. +32 767(MUL_TJ


)2 76H{OJV I)

" ,
" " 0 ,
0

( )65 536 Division by Uco

, " , , ,
0 0

" , , , , , , , , , ,

"

-1'0-2147483647 >+2 14 7483647 (ADD D J. SUB 01) >+214748 3647

(MUL DI)

2147483648(DIV_ DI)

H " 194 967 296


Di v i,ion by >:oro (DlV 01. MOD 01) Comp. ri.on

, , , , , , " , " " " , " , " , , " , , , , , , , , " , , , ,

ce. ov

0;

0 0

JU:AL c.lculation

The ,e<uit is:


+ DOnnalized '" denOrrn.'l1ized " zero nonnali,ed

ceo ce. ov

+ infinite (divi. ion by

~ero)

infinite (division by zero)


-to

imalid REAL number

" " " 0 " , , " , , 0 , 0 , , , , , ,


0

, " 0; , ,

The rult;s:
equal

CCO

ce. ov
0
0

0;

t<,

0 0

gre aler than


1 5 than
in,..lid REAL number

, , , , , ,
0
0
0

The resuh is:

Cotlnrslon

ceo cu OV

+ 1 to"'32 767 - 1 to 32767 ( )32768

"

"
0

0;

The .e>ult is:


0

:-a"c -D

CCO

ce. ov

0
0

-1 '0+2147483647 110_2147483647 ( )2 147483648 Word logic

0;

0
0

, " , " , ,
0
0

, ,

0 0

. Shirt function
The shifted out bit io: 0'. CC" CCI
0
0

"
0

, ,
0'

OV
0

0;

Th., result is:

Co> CC,
0

OV
0

t"
with shift nOln be. 0

" , "
.

"ro
not zero

223

15 SlatUll Birs Slatu. bit. for comparison functions Thc comparison funCliom set the CCO and CCI st alUS bil S. The flag' arc set independently of the e~ccutcd compari son function. Status bIts ror shm runctlon, In the case of the shift functions, the signal Slate of the wI bit to be $hifted OUt i. tmnsf=d to suuus bit CCI. ceo and OV are reset. Sta tu, bib for .. ord IUlle

15.3 Evaluating the Status Bits LAD : You can usc the nonnallyopen (NO) and the nonnallyc1osed (NC) contact 10 chk the dillital status bils "nd Ihe binary result . Figure IS.I shows the check with a normally-open contact. The check wilh a normally ..dosed conlacl relums the negalW cheek result. You can handle Ihe NO and NC contaCI5 for e\wuating the Slatus bits in exaclly the SAme W3y as lhe "1I0\"T11.11.1 contacts. You can find c~amples of evaluating the SlalU!; bi ts (FB II S in the Pro .. aram Flow Control"' program in Ihe "LAD Ilook" library Ihal you cnn download from the publisher's Website (sec palle 8).

If the I"Csult of the word IOllie operation is zero (all bits are "0"), CC 1 is reset: if at least one bit in Ihe result is " I" , CCI is sel. CCO and OV arc rcsc\.
LAD lalion >0

FRO
rcprewnlation

A cu=nt OOW$, o r the check

is fulfillw wben

-1~
> 0

-H~

--I f <0

=:-I~
<>0

--I f "0

--I f UO

--I f ov

--I f -

" --I f --I f Ftau"" 15.1

'R

I fI fI fI fI fI fI uo fI Ov fI " fI 'R f>0


0 <0

Resull gn:ateT th"" zCTO (CCO=O) & (CCI - I)]


Result greater Ihan or equal to zero [(CC()-())) Result less than ~CTO (Cc()-l) & (CC I-o) Result less than or equal to zero [(CCI-o)J

..0

<>0

Result not equ.llo zero [(CCtFO) & (CCI- !) ,,(CCO J) & (CC I=Q)]
Result cqUai lO zero [(CCD-O) & (CCI-o)] Result invalid (un~) ( CeO-I ) & (CC I" I)] Overfiow I lO V" ]] Slored overnow [OS- I] Binary result (SR- I]

Evaluating the Statu. ail<

'"

15.4 using the Binruy Result F OO ' Direct or ncgalC<.i check ing of the digital stan," bits and the binary result is pos> ib le. Thi s is shown in Figure 15.1 by di ..... checking tor ",t "igTlal "ale "1". The check fo r signal 'tat~ "0-returns the negated check r~sult. The checks for evaluation of the 'taN.' hits Can be treated el<aclly the same as the '"nonnal'" ch~cks for binmy operand,. You Can fmd e xam pl e, of uvaluating th~ status bits (FB 115 in th e pro. gram "Program Fl ow Control"') in lh ~ "FBD_ Book" libr"ry that you C~fl download fro m the publisbds W~b, it~ (see page 8). In the case of incremental programm ing, you will find these ~hccks in the Prul,'Tam El ement ' Catalog- (wilh YTFw ~ OVER\ll"T'WS [Ctrl - K ] or iKSERT -+ PRlX",RA .'1 ELEMENTS) un dC"T" "Stalus Bi t~" ,

program an a" ign box without binary opera11ds . P leas e note that tbe SAVE box docs not KTIninate a logic op~ra tion (starn, bitlFC is not se t to "0") . The next netwurk thus bugins with an "upcn" logic operation . The SAVE bux is not pennitled afte r a Tbranch, Controllinlilthe blollry
r~"ull

LAD and FB I) affect ev en the binruy resu!! in order to control the ENG output (i-' igurc 15.2). If cnabk output ENO is wi,..,d. il> signal ,tate i. the same as that of the BR. In certain cases (""OR corresponds \0 fWl~tiun"), \b~ LAD or fBD fun~tion executed sets the bina'Y result a, follo ws: HR,- "l" for MOW<. for the sbin fimctions and for the word logic operations
>

15.4 Using the Binary Res ult


15,4,1
Su !n~

S~ttjng

the Binary Result BR

OR := OV for the ari thmetic and mathemat;c,,1 fune_


I; on~

th. blnory ",,"It

LAD representa tion; FBD represenlaliorl

:>

BR :- OVor"I" for th e ~on version function s BR ;- BR of the called bIod,- in block ca ll s


th~ ~as~

------1 SAVE I

t>

of

SAVI': co il in a Fung (LAD) You store the RLO in the binary result using lhe SAVE c,,;1. Ifpown flow, into \h~ SAVE coil. BR is set, otherwise it is ",set. You program the SAVE ~"j] in the same way a~ II " ,ingle " cOlil without binary operands. l'lease note that the SAVE c'o;1 does not termi11atc th~ log ic op"ation (the !FC staw s b it is not set to "0"). Thi, means that the log ic operat;"" p receding 'h~ SAVE coil is also th~ preced ing logic operation for lh ~ next network. SAV E coil cmmot be programm<Od in conj unction with a T-bran~h. SAVE hox in a logk cir cuit (FOO) "\\'ith the SAVE bo" . you Save the RLG in the binary rcs"lt. If 'he RLO is "I" bdore the SAVE box, OR i, se t; othenvise, OR is resel. You progntm the SAVE hox \~c ""me way you
Th~

15.4.2 Main Rung, EXIE:"oIO Mecbani.m In programming hmg"ages LAIJ and FHD, many boxes h"ve an e nable input EN and an enable output ENO . If the enable input is "1", tk fun~tion in the box is proces;wd. Wben the box is process~J correctly. th e enable output also has signa l state " 1". If an errOr OCClIn< d"ring procc," ing ofa box (for example , overtlow dtlring execution of all arithm~tic fllItClion). .ENO is s~tto "'0" . IfEK h"" sigtl al ,tate "0", ENO j , a),,, 'ct to "0" , These chamcteri<tics of E'-I an d ENO can be uscd in o rder to connect se,eral boxes together in a cha in. wilh the enable output leading to th~ en able input oftb" n~x t box (Figu", 15.3). 11,i. means. for example. that the entire chain can be "disabled" (no hu~c, "rc processed if input I 1.0 in the ~ xample has signal ,tate "'0") or the ,..,s( of the chain is no longer p rocessed if one box signals an erro .

225

15 Stall>.' HilS

Is ENO switched?

v",

'"
'"

NO
Is EN switched 7

Is EN switched ?

NO NO

m
Is EN - - "t " ?

NO NO
BR :- ' 0' BR not a ff9CtBd

Is EN "1"?
BR corr ... SPOMS to tunc-

'R

,. "0 "

tion Fi\:" r.
1~ .2

spo nds to func lion

BR

corre

YeO BR ,. "t "

(jeneral Schellliltic for SOIling lk Binary Kosuh

The input EN anu thc outpllt ENO are not block parameter> bUI Si.<Hemcm sequences that th~ Program "Editor it<elf g.en erates plior to and fol" luwing an boxes (81~ o in the casc of [unction, and function b loch) . The Program Editor usc, lb e binary result 10 ,lore the ., ignal ,tate at.EN while the hlock i. being proc essed or to ch,'ck the error /lag from the box.
1~.4 .3 Ca~e

propnly processed; "0" jf an erro, has occurred during process ing of the block), All SYS tClI1 block> aho ~ignal group errors via HR .
b~~n

YOl' contro l the ENO output with the binary result BR. The ENO output has lbc same signal state that BR has when the block is ex iled.

ENO in th<' Block.

of \)s~rwrittc n

The Prow-am .Editor provides the call of your own blocb wi lb Ihe enablc inpm EN and th e enable outpu t E).IO. YOll ~an u, e the enable input EN to ~a11 the block conditionally. You can use the ENO output, for example, to 'ignal a group error (signal st<ltc " ' '', if the block ha s

1m,

For examp le, I3R coul d be set to " I"> at the ,tan of a block. It" an error lh~'!! o ccur> during pro " ce " ing of the b lock, for ~xampl~ if a result exceeds the tixed range "0 that further process ing nlU,t be f'1"Cvcnted, 8et the binary result to "0" with the SAVE ~oiLlbox and j ump to the end of the block w h ere th~ b lock w ill be =ited (in the event of an e rror, the condition mu,t supply sign"l . tme "{I"), Plea,c notc lhat the RET coi li box sets the BR to" I" i f you ~X il block via coiL-box ,

we

-it"' H - - '" ~ MD"1)}.;:::' 'N1 -, -.tOO-.,, . - 'NO ;~'.., -.I.i!~'

,.... ,.

OIV_ R

ROUND

Coo Utett

"

'"0 0"' f-#CREAl


#\ R EAL

'" "

'"0
OC;
iiLDINT

---'

EN IN

MOVE ::ioliO ~ ENO . H l OUT '.MO 3~;

c; ~~H~~--:;' "
E ND HIt"rc 15.3 Eumpl e fo, the Series Conn"" ,ion or.t;N and ENO

-" --

. '.:

'"

16 Jump Functions

16 Jump Functions

You can usc jump functions to interrupt the lin _ ear flow of the program and continue at another point in the block. This program branching can bc executed un~ondit ionally or d ependent on the RLO .

lowing comp ietion of the jump operat ion. The box w ith tbe jump label must be at Ihe stan of a network ("LABEL" in tho f>rogram Elements Catalog) , In the case o f incremental programming, you will find tbe jump functions in the Program Elements Catalog (with VIEW ---). OVERV!IlWS [Orl - K J or I,SEl'I,T --;. PRQGRA)'-! EU:.'fENTS) under "J ump.,".

16.1 Processing a Jump Function


Representation
LAD
rep r esenta l lo ~

JumpifRLO - " ]"

Dest ---{ J MP)------l Dastn ---(JMPN}-----j

Fu nction
A jump is e ither always executed (absolute or unconditional jump) or ;t is exeeutcd depending on the re sult ofthc logic operation (RLO) (condit ional jump). In the case of a jump dependent On the RLO , you Can de<:ide whether the jump is to be executed if the RLO is " I" or if the RLO is "0"

JumpifRLO - "O"

Entry, Jump

Jab~ 1

FBD representation

JumplfRLO - " ] "

Jump

iF RLO - "0"

Eotr}'. jump h,b.1

You can e .~ccute botb fo","'ard (in Ihe direction of program processing; in the direetion of ascen di ng neN.orK numbers) and baCKward jum ps. The j ump can take place only within a block. that is. the jump destination must be in tbe same block as the jump function . If you use the Master Contro l Re lay (MCR), the jump lahel must be in the sam e MCR zone or in the ,ame YlCR area as the j ump function , The jump destination muSl be designated unam biguously. that is , you muSt on ly assign a j um p labe l once in a b lock. The jump destination can be j umped to from several location s. The Program Editor ,tores the names of the jump labels in tbe non executable seetion of the rel evant blocks on the programming device's data medium. Only the wi dths of the jumps (jump displacement) are ,tored in th e CPU's work memory (in the compiled block). When program modifications arc made online to blocks in the CPU, these modifications m ust therefore always be updated on the program-

A jum p function consists o f the jump operation in the form ofa coil (LAD) or box ( FED) and a jump label d esignating the program location at whi c h proccssing is to continue aller Ihe jump. The jump labe l is above the j ump operation .

Jumps ~a!lllot be programmed in eonj UIl ct ion with aT_branch


A jum p lahel cons is" of up to 4 characters that csn include letters . digits, and the underscore . It begins w ith lclter, A jump labe l in a box d esignate, the network that is to be processed fol-

16 Jump l' unctions

ming d<:vicc's data medium in order to retain the original label lUlmes_ If thi. update is n ol made, or ifblocb are tnm,ferred from lhe CPU to the programming device, th~ nOll -e x~Ulable bll"". scc, ion< will b. oven,/riucn or del.:ted. On the di<play or the printout. tIle Ediwr then generates replacem<'-'TIt symbols for the jum p la bels (Moo l , MOO2 c'te.).

whose eoil is connect ed to the left power mil (LAD) or whose box ha< no preceding logi c operation (FBD) . This jump function is a!wa:,-s ex ecuted when encout\tcrcd in the program The CPU intcrrupts the linear fl ow of the pro gram and con (il1\Jes in lhe network d.signated by the j ump labe l.
E~ample (ri gure 16. 1 and Figure 16.2): In Ne(work 3, there is an unconditional jump (0 jump label M2 . After th is Tl ~twork has be~n proce"ed_ {h~ CPU cont inu"s program e:xecution at j u",p labe l M2 in Network 5. A jump from anothcrprogram location is required in order to ptoees. Nctwork 4 .

16.2 Unconditional Jump


The uncondit;onal jum p> which is the j ump that j, alwoys executed, is jump funclion IMP,

'~~Ork 1 Conditlorlal Jum p 1

If RLO

:i" '~---1 I t/compVall - (N1


I

.:,':

'

CMP~I

~-----{JMpH

Ml

tiompval2 -1.""~' '

___--1

: !'I.~.qrI( 2. Jump to "'II (5 not execut"d

1/-" ~lAcl f-I___________ (


. ~!,rk

iH

.,

.,

3 Uncondttlona( Jump

l~:+;;~~~~ ,_~-----------------------4(~~H ~~ .
CondlUon ltlJump 11 RLO _
"O~

"
Entry- 01 "'1 2

Flgu ," 16 .1 Jump FunctiOn< Exa mp le (LAD )

228

16 .3

JumpifRLO ~ "I"'

16.3 JumpifRLO="I"
The cond itional j u mp if RLO - "1" is jump func tion J.MP, whose coil is not directly con nected to the left power rail ( L AD) or whose box has a preceding logic operation (FED). The logic opemtion preceding this coil can be implememed in any way. If the RLO = "1" (if th e preceding logic operation is fulfilled). the CPU interrupts the lin ~ar flow of the program and continues in the network designated by the jump label If the preceding logic operation is nol flllJ11led. the CPU continues program e.~e cmion in the next nelV.ork. Example (F igllJ"e \6.1 and Figure 16 .2) : If the compare condition in N~1work I is fll lfiUed, projj:tam "x""ut ion eontinlles in Network 4. If the compare condition is not fulfilled, the next network. which is Network 2. i ~ processed.

16.4 Jump ifRLO

"0"

The ~ond itional jnmp if RLO - "0" is jump function JM:I'N, whose coi l is not directly connected to the left power rail (LAD) or whose box has a preceding logic operatioo1 (rBD). The logic operation preceding this coil can be implemen ted in any way. Iflhe RLO = " 0" (iF the preceding logi~ operation is not fulfilled), the CPU interrupts the linear tlow of the program and eontinll""s in the network designated by the j nmp label. Iflhe preeeding logic opera. tim1 is fulfilled. the CPU continu~s program ex .... cmion in the ne"'tn~twork . Example (Fig"re 16. 1 and Figure 16.2) : If the adder in Nero.ork 4 signals an error, the jump to 1','ctwork 6 Uump label MJ) is e X""\l\ed. If no error is signaled. Network 5 is the ne~t to be processed.

Network 1 Condittonat lump tf RLO.


CM P IICompVal2
*~ I

~ 1~

#CompVall

~=l'; ;'~ N IN2

__J___[jM~''e:J
JMP

N.twork 2 If jump to M3 Is not . " e cuted OutputO & InplllO

----l

Network 3 UncondItional Jump

Network 4 Conditional jump if RLO. "0"

#AnlhVa l1 _-l~'N;',--"O~';'}r-_~'~A~;~,"~R~'~'~____[i9M~'E: ' #ArithV,,12 IN2 ENO JM PN


Entry of M2

Ne twork 5

~ ~
.'t~ u r.

Input1 - 1

I {=='=:}______-{O="~"~'J'I
&

Network e E ntry of M3

Inpu12-1

I {=='=:}______-{O="~'''~OJI
&

16.2 Jump Function. Exam rl e (FBD)

17 Mo..ter Control Relay

17 Master Control Relay

In contact control systems, a Master Control Kelay activates or deactivate. a section o f the control system thaI can consist of one or more nmgs.
A deactivated rung
!>

w, EMERGENCY 0,..,.. or safety fUd/ity! Treat .HaSler Conrroi Relay switching in ",':aClly Ihe samC \i'ay as switch ing with a memory jimc1ion!
Wilh I,ICRA and MCRD. you de,ignate an area in your program in wh ich MCR dependency;" to take efteet. With in th is area. you use MCR< and MCR> to define one or more ZoneS in which th e MCR dependency can be enabled and disabled. You can also nest the MCR zone . The result of the logic operation (RLO) immcd;at~ly preeeding an MCR zone enables or disables MeR dependency wi th in that zone.

dccoergizes all non_rctentive contactors and retains the states ofrctemivc contactors .

!>

You C3lllot change the stale of the contac(01"$ again until (hc Master Control R~lay (MCR) is active.

Please nOle thai deenergiz;ng ",ilh the "soft",.are " Master Control Relay is no SIIbslilUtejar

17.1 MeR Dependency


"'lCR dependency am:ct8 coils an d boxes, If MCR dependency is enabled (corresponds to Master Control Relay disabled)
!>

LAD representatkm
A.Uv.te MeR .",a

a singk coiior assign box and 3 midline out-

Open ;I.(C(( .one


t>

put sN the b inary operand to signal state "0" (following the midline output. the RLO is thcn - "0", that is, power no longer nows) a Set and re set coil or box no longer affect the signal s13te of the binary operand ("freeze it") an SR 1lOd RS box no longer affect the signa l state of the binary operand ("freeze it") a ln1Il,r<:ropcration write s zero to the digital operand (every function OUlput ofa box of digital data type then writes zero to the operand Or to the variable)

Cluse MeR ,one

t>

FBD

r ep'a~entat i oo

t>

A.Unt. MCR o",a

-------l MCR< I
IMCR>I

Additional to the direct innuencing of an oper~ and the RLO is then "0' (power no longer flows) behind a midline output and aT-branch . Some LAD and FBD function. use tn.n,rcr statement. (inv isible to the user). Since a transfer statement write8 the value z ero if MeR d~pendency is swi tched on, the corresponding function Can no longer be guaranteed

Deoetlva l>ICR aITa

IMCRDI

17.2 MC R A rca

Yo" m'lSl exc/ude Ihl.< /hllm"'ng progra m ., ee_ litm.. / i-om MeN dependcn<y at/Wlldse the CPU ,1'111 go 10 STOP or "nde/in"J nmlim<! bd'''''io r <'un occur.
r>
I>

[eLrl - K l or b ' SERT --> PROGRAM ELEMENTS) under " Program C"ntrol" .

Dlock call s w ith block param eters Acce sscs to block panlII1eters that a ", pa_ ram"'"," types (e.g . BLOCK_ DB) Accesses to b lock parameter. that ar~ ~om pon~"Ilts or eiemetlt< or ~ompl ex data types or UDTs

17.2 :\'ICR Area

r>

You enable MCR dependency in a zone ir th~ R L O is '0" immediately priOT to op ening the zone (analogou, 10 disabling the MaSler Cootrol Rday ). If you open an MCR z one w ith R LO" I ( M a'tet Control Relay enabkd). p ro ccssing within this MCR 7.0n~ take, p lacc wilh_ out MCR dependc n~y . .\1CR dependency is cffccti v~' "nly within an MCR zon~, Tn ' hc case of in~r(:menta l programming. you will tind the MCR nm~tions in th e Program Elements Calalog (with VIEW --> OV.I'RVlI'WS

To b e able to "se the characteristic fearnres o f Ihe Master C omml Relay. ddin~ an MCR area \>"ith NlCRA (start) and MCRD (end of the M e R area), MeR depcn(kn~y i, aClive wiLh in an MCR area. but not yet ~nabled (F igure 17. I ).

TtIc MCRA coil/box and the MCRD coi!Jbox a lway!, ,'ann alone in separate n etworks .
If you call a block within an MCR aTca. M CR
dependency is deact ivated in the block callcd. An MCR area on ly Starts again with \hc MCI{A co il/box . Wocn a block is c xited, MeR dcpen<Jellcy is ,et as il was before the b lock was called. regardless of th ~ lI.ICR dependency w ith wrnch the callc d "I ,,~k W",", cx i ,~d.

Bh><:k 1

Block 2

Block 3

MCRA

MCRA

MeRA

Bloc+< call

BlocJ(cali

MCRD MCRD

B lock end

Block end

Bloc k en d

Fi\l:"'" 17.1 MCR Arc. in the Case "f Block Change

231

17 ;"1 _ Conlrol Relay

17.3 MeR Zone


LAD : You define an MeR ;wne with tbe MClt < coil (~tart) and tb~ MCR> coil (cnd of doe MCR zone). The MCR< coil r~u1Tl'~ a preceding Ingic opcl'mion: the MCR> coil is connected directly to the left power ra il. Both coi l. tcnninlite a rung. Within this zone, you control MCR dependency wilh thc RLO prior to the MCR< coil: If power flows inlo the e",1. _ \.tCR dependency is di~abled (,n onna" Prlx:es.in.j); if po" cr docs not flow inlo the coil, MCR d<.-pendcncy is cnahlcd.

You can open lID MCR !.OlIe within llllOth~ MeR zone. The nesting depth for MCR !.Oncs is 8; that is, you can o~n a lone up to eig:itl timc.~ hefon: you close a ZOne (Fililure 17.2).
You control the MCR dqx:ndency of a ne~ted MCR zone with tbe RLO on opening the lOIlC. However, if MCR del"'ndcncy ;'; en~bkd in a 'supraord inat e zone, you cannut disl,bJe MCR dependen~y in a ',ubordiMlc" MCR zone. The Master Control Relay of th e tiTSt MCR wne controls the MeR .lc-pendency in all nestll'd,

"'8D: Youdcfine an MCR zone with the MCR< box at the beginning and the :\fCR> boll .1 Ihe end oflhe :\1CR zone. The MCR < ho~ rcquin:s a precedi ng logic opcnu;on; the MCR> ho~ stands alone in a network. Within this zone . you control MCR dependency with tite !U.O preceding the MCR<box: If it i. '"1", MCR dependency i~ disabled (,"normal' proce~sln il); i f il is "0, MCR dependency is ~nabled.

A block call witbin mn MCR !.One ~s not emnie the nesting dc-pth II f an MCR zone. The program in the callII'd block is lIill \1\ the MCR zone that was open when the block was called (and is controlled form here). Ho"<c\er. you must reactivate MCR dependency in a called block by opening the MeR area.

In Fill"'" 17.3, memory bit~ M 10.0 and M 11.0 eontrol the MCR dependencie,. Wi t~ memory bit M 10.0, you can enable MCR depe ndCIl CY in both zones (wi lh "0') fCllard-

L&d

representation:
(MCR.4}-l

FBD rep' .... nt-'Ion '

I HI
t

! MCRA!
, 1.1

/MCRzon.

I,

(MCR<H

---l ---l
2J

MeR"'!

S"';Id:.ing QD ),liCk dopoJODCY III

MCR."""" I and Mt:R...-2

~1 .;

'I':' .rl< 2} 'ifMC"!hpn" ,.. , "t',


0

I ..

(MCR<H :

(MCR z_1J
t 1.1

MCR<!

S"'i<chi"" "fMC,,,
.wi t, ~e<I

~""Y


0 0

ill MeR ;:QIl' 2 ooly if MCR


deponden<:y in MCR rorlO T il

S-;,'l,il..

.~

"

{J..teR zone

otf

I I I

(MCR>H ,:
(MCR~H {MCRoJ-i

I MCR> I
! MCR~ !

I MCRO !

17.4 'ktlin& and R..~cuin& UO B;I>I

,.
MCRA

I I
[MeR zone '1

I MCRA I
[MCR zone I I

F-{.''"<f-{\ M 10.0 --i


[MeR zone 1]

MCR< I]

IMCR

ron&

[MCR

zone 2J

BlOCk call

MCR>

MCR>
MCRD

I MC RD I
" Iluft 17.3 MCR Zone> in Ihe Cau of llIod Change

le55 of iM C sig nal 5Iale of mem ory bit M 11 ,0, If the MeR d"pendency for zone I is d i, .. bled WLlh M 10.0 - " \", you can coutr"l the "feR dcpcudency of zone 2 With memory bit M 11.0 (T~bl c li.I).

to be COntrol led arc: in the pro~~ ss_i mage OUlput table or II procc,,-imaIlC output I" ble ha.~ b""n defin ed for the UO ar"a to be oontr"UeJ.

17,4 Setting aDd RC5C1 t1ng 110 Bin


Despite enabled MeR dependency, yuu can .et or rc~"'t the bilS of an JlO I'll'a with Ihc syslem
functions. A requirement for Ihis is Ihat Ihe hits

Th" syst"m function SFC 79 SE T is a vailable for :settin g and S FC 110 RSET for =<<!tting Ihe 10 bilS (Table 17.2). You call Ih"'" syslCTll f"mehons in an MCR :/;on". The system functions are on ly df<!{:ti"e if MeR d"pcm.lcncy is ennbkd; if MeR dependency i~ disabled. callina these SfCs has no effect ,

TMbk- 17.1 \1CR [kpcndcncy in Lbe ea.., of':'e.<tru MeR Zo...,. (Example)

MILO '" I ~

7.<>r>o 1

One :l

''0''

!>OO MCR dep..--n<knr;y Nn MCR dc-pendenC)' MeR dependoonc)' enabled

MCI!. depeodency """bled

17 MasterCODlml Relay

T~blc

17.2 ParamctCT< of the SFC. fo' Controlling the 1/0 Hi" P"""ncter
N

Decl ..... tion

D.ta Type
~ ,

m
N

VAC

INPUT OUTPtIT

on
POlJ'.'TER

"
<A

""'U,

OUTPUT

INT

RET_VAL

OUTPUT
OIJr ~UT

en
POINTER

A",isnment. Oc>cription Numh,,- of bit< to I>e .et FITor information Pointcr to the first bit 10 l>e set Number ofbi" to l>e reset Error information PUll"''- t~ the first bit to be res<:t You call rmd examples of the Master Comrol Relay and of the SystCID functions SFC 79 and SFC RD in function b lock FB 117 in the libraries "LAD_ Book" and "FBD_Book" in the rrogram "Program Flow Control" that you can download from the publisher's Website (see page 8).

Setting and res~t(in& I h~ VO bils aho simulta neously updales the process-image OUtpUl table. The 1/0 are affeet~d byte by byte , The bils not selected with the SFC, (in the tirsl and in th~ last byte) retain the signal stat~s as they arc currenlly availablc in the procc" image.

18 Block Fuocriom

18 Block Functions

In th .. chapter. you will learn ho" to call aDd terminlLtc code blocks and how to work with operands from data bloch. The n"xl chapter then deal~ wilh using blo;;k pl,ramctcrs.

conditions) is permissible. The block "'ml futM;~ lion RET always requi:, .. preceding logic ope..al1on. In additi"n to Ihc block change. Ihe cal l box alw contll;n. the tmnsfer of block parameters. Whtn fonclj<m blocks are called. it als<> opens the instance data block. Th .... CALL coilJbo~ is 00 _ than a change 10 anoth~"T block and is oruy muningrul (and pcnnis.sib1c:) in the case of functions and sy.l~m functIOns. After a block has been lenninatcd, and follow ing the call function, (he CP U contin"," pro_ !,Iram execut ion in the blO<.:k tbnt made Ihc cal l (tbe ...... block). If an orgnni:r.ation block is terminated, the CP U returns 10 the operat;ng $y$tem.

18.1 Block Functions ror C ode Blocks


Slod. functions for code blocks include instructions ror call;ng and terminal;ng blocks (F;gure 111.1). Code b!<xl;" (111: called with the cl,ll box. If functiollS or system functions havc no block parameters . they can also he called willl the CALL roil Or with tbe CALL box. In both cases. a pre<:edinj; logic op.,ration tnablina a conditilHllll call (call dependent on

nina

lAO rapr. .en !.lOtion


C.11InK on f8 or SFH whh d... bl""k a. 1"".1 instanU

D'.

Callin/( an Fe M STC with CALI. t><>. with CALL ooil

HI...... nd

["'ponde"t on RJ.n

".

OLn.me

IN' - '"

-- 'N OUlI -- IN'


,"0

'NO

OU"

,C.
'N
ENO

--{ RET}----i

IN'

mm

IN'

au"

.,

IN'
IN2

OU"
OtJT2

FBO "'prflSflntation:

C.III"iI an FB or SrB
with <13 ... bl""k ., 1"".1 'nS\8lnce

ComHi on Fe or SFC
wi!" CALL box

with .;m , "'-' r.; -",~""C"C .C---


CAlL OO~

,C.
EN
INt IN2

-1

'C.

o.."p<"do,,! on RLO

CALL

OUT1 OUT2
ENe

-IL-'c:'::.T-,

FIKure t8.1 Rlocl: Function, fnr Cod ... Block>

18 Block Functiom In Ihe case of incremental pn)~lullming, you will find the CALL coillbox and !be RET coill box in the Progrtlm Elemems Cata log (with
VtEW --J>
OVEll.VIEW~

[Clrl K 1 or L'SlRT--J>

rROGRAM I::LlMENTS) under "Pro~ Con-

Irol"; you insen block calls with caU box..,. mlO your progrnm when you select blocks from --FC/
J'H/SFClSr H bl<.><.:u", '"Multi ple In.tunces" or "Libraries".

.".

of Ihe call box that CO il or the called bl"d: (here: Fe 10). the enable inPUt [;N, thc enable OIltpul ENO, and any block puameters. Following proc~ingoftbc ~"Il function, the CPU OOnlinues progrHm cxec\U;on in the called block. The block is procc"ed to the end or IIm;1 a bloc k end function is cn~oumered. The CPU the n rerums to the calling: block (here: 013 I) arid
A block c"U

consi~t~

hlins the

ad~s.

cominucs proccssiull this

hloc~

alkr the call

If a code hlock i~ 1<\ be processed. it must be "call ed"_ Figure I R.2 g:ivcs an example for caUing functi on FC 10 in organiz"tion blo.>ck OB l.

C_Ili_1l b .... k. ~ .I. "'11_. 1... 11,," block O BI NetwoJ'k pIior to


~od< ca~

.. .
"

The infonnalion the CPU requires to find iiS way back 10 the euUing hloci< III stored in the block stack (lI sUlek), With every new blod:: enll. a new ,t"ck elemcnt is c""mcd that

N"twor1<: blOCk call wiII"I p"'ameteo"&


~ -- ~

, ,

1 1-- -1"" HH""


,, ~

Fe 10

'"0' -- - -1 '
r
04.0

\"1 _ 0

... --,
"ro<~,sin!l. oj"blod 1"''''mOl.... CO'ro!sIJQ",h ' ,,, p1W~,,;n/( of Ih. ~cl""ll'/zr;abl~., durinj{ "'"""'~

Ii

'N'
C..l1ln K bk><:k.
~ .~

,, ----C"lIfn~ rIt~ Mod M;'~ ""tfPI"",n <If 1M ",,=nt ""rlabl~1

a 'll" nt.",llon b lock O B I


ca~ pa~

i'Q

th. blocio: P''''''''<'''~'

Networl< pnor to bJod<

Netwo<t<.: DIOdo: caW with

--

Fe 10

;,
FiJ:;"'"" JIU Exampl. n( a Rlock Call

I g. 1 Block Functions lor Code Illocks

includes Ihe retum address, the contents of the data block register and the address o f the local data stack of the calling block. If the CPU gocs to thc Stop state as a result of an error, you can usc the programming devic e to sec from th~ contents of th e B stack wh ich blocks were processed up to the error_ You can transfe r data to and from thc called block for processing. These data a rC transferrcd via block parameters . With th e call box, YO ll can also call blocks without bloc k paramcters.

or ENO. You can only insert a call box in a paralld rung if it is connected directly to the le ft po"'e r rail.

rBD, You Can connect call bo~cs in ser ies by connce ting the ENO output of onc box with the EN input of the next. Th~ E N O OUtpUIS of~ev eral boxcs can be combined with AND or OR
.\-1eR dependency is de_activated when II block

18.1.2 Call Box You use the call box to call FBs, Fes . SfBs aDd SFCs_ (You cmmot call organization b locks since they nre event-driven and arc stancd by the operating system.) You can U the EN input to make Ihc bl o ck c all sc subjec t to conditions. If the EN inpul i, connected dirCCI to the left power ra il , the call i, absolutc: it is al ways ~x~cu:ed. If there is a log ic operation preceding EN, th~ block call i, only executed if the prececting logic operation is fulfilkd. The EI'O output has thc s ame s ignal state as the binary result BR on e xitin g the called bloc k. IF EN "''' "1- or not connected THEN Called block is processed IF called bloc k return s 8R = 1" THEN ENO :- "1 " ELSE ENO :" "0" ENO := "0ELSE Ca lled block is riot processed

is .allcd. The MeR is di,Hblcd in the called b lock regardless of whether the MeR was e~ ab led or disabled prior lu Ihe block call , Wl'en ex ilin g a block, MeR dependern;y asmme, the same setti ng that il had priur to the block call Depe"ditlg on thc block paramet~", you can modify Ihe ~ontcnts of thc dala block registers when the b lock change is made _ If the called block is a function block, the instance block is always opened in Ihis block v ia the DI rcgiSlcr_ If the calling block is a fu nction block, Ihe contents of the D l registcr (thc in stan ce data block) are retai ned aftcr thc block caU , The contents of the DB register depend, amung other things, on Ihe block paramct~rs that w ere passed, Calling function block. You call a fu"ction bl ock by .electing the rele"am func tion block from the Program Element.< Catalog under "FB Blocks". Pr~n;qu;sitc is that the function block to be called mnst a lready be in th~ u ser program_ You write the ins!an~c dala block belonging to the call above thc box. Both b locks (function blo<,k and in'tancc data block) can ha,c abso lU!e or symbolic addresses.

You lobc l th e parameters of the called block w ith thc absolut~ or symbolic operand current for the call. If a parameter is of data Iype HOOT... precede this parameter with

In the case of func tion blocks. you do nOI need to initial ize all block paramet~rs at th e call. The unin it; aH~ed block parameters rela;n thcir currenl value. However. b lock parameters saved..,; po int~rs shonld 21 least be initialized when called for the first time so that m e ,mingful values are ~ntered here (,ee Chapter 19.3 , "'Actual Paramclc," '").
You can also c all function blocks with multip le instance capabi lity" within other "'functio" blocks w ith multiple in'tance capability"' a, loc al instance , In doing so, the called function block uses the instance data block of the calling function block as the storc for its local data. Prior t(l the call, you declare the local instance in the static local data of the calling function

> a contact or a rung (LAD) or > a binary variable Or II binary logic operation
(FBD).
A Boo lean output parameter cannot be combined funhcr, LAD: You can arrange several call box~s in scri cs, connecting th cm with each other vIa E~

18 Block Functionl block (Ihe hlock you arC ~urrenl ly programming). The local illstancc " called by 5e1eClin g one o f the available local ill' tances under 'Multiple Instaocel' in the Program F.le-mctU5 Catalog; it is nut D~'CC;;:;aay to ,pecit)t an instance data block (~e also Chapl.r 18 1,6. "Slatic Local Data''). CalliDl:
functl"n~

You Cllll , I'Dr ~x amp lc. ~cle~t a sy.tem block frt)tn Ihe Program Elemenls Catalog with thc moo<' and drag it to the block c urrently being procnsed block. wbc-re it i~ then called. AI the same IUnc, this bl"ck (or. runIC precisely: ils inl4Tfac~ d.,scllption) is copied imo the block contninec. Hlock
~~JJ,

in

5equtn~~

(FRD)

You call a function by seleeling the relc"anl function under "Fe Blocks in the Program Elements Catalo~ The function C1lO have an ab.olute or a symbolic ndru-.,ss.

When you call functions . you available para11lete l"!l.

mu~l ini(ializ~

all

Calling runetions with a function value tab, exactly the.same fonn >IS e~l1ing fimel;on->' with no function value. OnLy the fml OUtput panuneter, corresponding to the functioo valll" _ has the name RET_VAL. Call in g 'Y"ltm blocks 'fhe CPU U]X'l1It;ng system cOIll~ills system Cunctions (S~C$) and system funclion bloch (SI'Bs) thai you can u.'<C. The numbe.- and type of.ystem blocks depend., on the CP U. You can call all system blocks with th., call boll:. VOII call a .~ySlc m function bl""k in the 5ame way 8., 01lC you have wrinen yourself: . et up the associated instance data block in the work memory with the !iIIm.. data type as th~ SFB. You call a system funct'on tht: "ame "'y "-~ a function you havc written you~elr. only in th~ C PU or>eraling ~Yl'tem. If you wont to call sy~t~m bloch during offliIll> progrnmming. th~ PTolP"m Editor oeeds a description of ~ call imerC....:e 1O ;1 can initiali~", thc ]lIllIll~t""'. You will fmd t/lli; interface ~pt;nn under S)slf~m Function Blocks on the librnry namc-d Sumdard Lihra,},. From here. the Ptogram Ed,[or copies the imerracc description 10 the omine hlO<'k colltA iner when you ~,,1L a ~y~tcm block. The interface description thm ~'Opied then appeDnl us "nor,nal" hlock objCCI. Syotem The Prognun Elc-men!..'! Cataloa provides the s)">tem blocks eW'T\:nt!y available ;n the u,,-,c pmgram WIder "SI'C BI""ks" or "Sfn Bloch".
hlock~ cx;~t

If you COnnect block boxe. in sequence in 1"00, and ha'e to "paSs 00" binary signals from one OOll: 10 tbe nell:l. you must observc the pr<>C<:SiI_ ing s..quenee of the binary logic operations by tbe program editor, The biruuy operand ~ and logic operation, arc initially processed prior to the bolt inputs, starting with the "last' block boll; the intermediate binlll)' results are saved in the temporary local dalu (not shown). FolluwLog this, the pmgnutl edttorproces.es tbe boxes thc-lIl.dves and th~ir binary ompulS , commcncina "ith the "fmil" box. Figure 18.3 c1ar:itie~ the processing S/: q\l~l1 cc. The OR box wilh the Ihn;c input~ i~ inittally procnsrd prior to the rialll block. then the OR boll: "'ith the twO inputs, followed by the left block call (~"Ontrol of Pumpl) and CID.1I1y the righl block eaU (l'um(2). Tile t=>porary local ~arilIble ",_PI Faull wauLd IherefOlre be scanned [lTSt (DIl Ihe OR box Wilh undelincd ~igna l state) and Ih ~n ~et (at lhe hinary o Ulp\\l of the first block caU). Thi~ could result in fo !sitlcation of thr result Olf the log;c operation. &:medy: ust' a globlLl '-ariable- (e .g. a bil memory Or a data bil; ",Ihi. ~HSr. a chang~ in status al the output of the til'!ll 1>10<:1<. would only be conSidered in the next Jlrngr~m ~yde "t the input of the ' econJ block) for pa,;,ing on the sisnal, or divide tht block calls bcl"een IwO nct" orl<,;.
18.1.3 CALL Colll8o'l:

,n

You cnn ~all functio!l~ ano.! system fu!letion~ using the CAI.L eoWhol<. II is a requiremet\l tbut 'he ,~ll~d bLock.s have no bLockpammrters , You eM use th., CALL enillbox if a block is 100 Jona or not clear .,nougb fOf you by ~;mJ'lLy llreaking down"' the hlocl into sections and calling the stttiOIU one aftcr Ihe other. One sinIIle CALL coiL or bolt is permit1cd per network.

23l'1

18.1 Block Funelions for Cotk Blocks

~ -.:, -:::J[==l~::-::.::. :j:;.;-~_""C=;- ~=.:~{:-~'-;'-..'.'.~ . =-~':~


I ....,.. - - '- '1""-" --

.. ......
-''-

.. _

H'

.. _

,- -..

........

..... " ' -

~. -

Fl~u""

18.3 Block Call. in S<><tunce (1'80)

eo;1 is connected dircetly to the call is always ex<'<:Uled (unconditional call). Ifth~re;s a logic operation precedmg Ihc CALL coil. Ihc call is only executed if Ihe preceding lo"ic Operation is ful filled. Ib ~t is, if power flows into the CALL coil . If the prc<:eding logic operation i~ nOI f,d filled. th~ call is nOt cxccll\cd and the next ne{ work is processed_ FBD : If there is a logic opention preceding {he CA LL box. the call is executed only wh<-n the preceding logic operalion is fulfilled. lhal is. when Rl.O" "1 '" is pr~scnt at the CALL box. If the precc>ding logic operation is nOI fulfilled, the call i~ not cxttuted and Ihe nexl nctv,o,k i. immediately processed. When a block change is made. status bit OS i. re$Ct: starns bilS cco. CC I and OV are nO! affected. MeR dependency is deactivated when a block i5 called. The MCR is disabled m the called block reprole.s of whelh~r Ih~ MCR "as enabled or disabled prior 10 the block calL When H block is exited. MCR dependency Hssumcs the .ame selling il had prior 10 Ihe block cnll. Calling a block with the CALL coilibox sa\-es thc data block regis!e", in the B stack: Ihe block end restores their contents "'hen Ibc called block is eXlted. The alobal datil block tlllTCtlt prior to th~ block call and Ihe instance data block are also open following th~ block call. If no datD block was open prior 10 tbe block call (fnr example. no instance UBlH block in OB 1).

LAD: Iftb~ CALL Ih~ I~ft pOwcr rail,

no datD block is open following the block call cuh~r. regan:ll~s of which data blocks may be o pen m the called block.

18. 1A Block End Function

You can tenninate processin" in a block prema. Nrely with Ibe block end function RET.
Condtlloul btod' ud LAO rOpnl!lenta\ion;

FeD

~Mntation:

--1

RET

Thc block ~nd fune{ion is rc-pre,;<;:nted as II coil or box requ iring II precedin" logic operation . Th~ RET eoiVbox muSI be olnn~ in II nelwork.

If the preceuing logic operation is fulfilled. thc block is eXiled. A return jump is made to Ihe
previously processed hlock in wbich Ihe block coli look place. If an organiul ion block is ler minated. th~ CP U .-c:lums to the system p rogram.
Iflb~ preccding logic operat ion is not fulfil1ed, the next nctwork in tho block is processed.

IF preceding logic operation .". "'" THEN ELSe


The block BR :"' " , "

t. ex ited

The next n elworl< i.

processed

BR

:c '0"

18

OI~k

fWKTions Thc temporary local data an:: stOred in lite L stack order of their dcclaTl'tion in accordance with their data type. Sy mbOlic add", lng of t~mporary local d ata You reference tempomry local data "sin~ their <ynlholie names. You lI.sign the se nameS in accordance w ith the rulc~ ror blocklocal ,.ym. bois.

The R ET roilJbox simultaneously StO~~ the RLO (whelher power flows or not) in binary 'Suit RR, ~~ardICl!s of whether or 001 the lo~i~ opcrt!iOl1 was fulfi lled. The binary ~ul! " decisive far coturol1ing the ENO outpUt at the call box (set! also <- bapter 15. StaIU. lilts'"). " 18.1.5 TCnlp"ra ry Local I)ala You usc the Icmpomry local data to buffer ~su1t~ Brisina during processin~ of a block. TemporlU)' lotal data are available only during bloc k proct'llsing; onCe a block ha!l been pT<). eessed. your buffered data a", lost, Temporary local data are opcnwd.< wbieh lic in the local darn stack (L .taek) in system memooy. The CPU's Qpcraring systcm malu:s the tempo. rary local data for a code block available when thaI code block is cal1e-d. When a block i. <':1, II<:d, Ih<,: value. in the L stack arc virtually ooineidenta1. In onkr to be able to ,"ake nnsi ble u<c aflhc local data, you ruu.t f1rst "rit~ them priQr 10 reading. When th e block is lenni n.,tcd. the L stuck is aS5igned to the next block ca ned, The number of temporary local data bytes a block require~ is in the block header. Reading the header lel1s the Op"rating sy.tem how many bytes have tQ be reserved in Ihe L nad: "ilen the bl()(:k is calk-d. You. too. can tell from the entry in the block header just how nuony local data bytt'llthe block requires (using the Editor, wilh the block open, by invoking F"u.E -+ PROp DtT1r~~ or in the 51MATlC Manager ","ith EDtT -+ OIlJECT PROPI:RTIl;S, in ea<;b ea.se on tab "Oencnd Part 2").
I)t~larln8 tfmpo~ary

All operatiO<)l; al10wcQ for bi! memo!), arc also allo","ed for tempol>Q)' local data. PJea;;c note, llowever, tbat a temporary local data bi t is I10t suitable for USe a. an edge memory bit because il does not retain its .ignal stDle oU!$'dc the rei e"ant block.
You Can address the tcmP'lRry local data for a block only within thai block (e)Cecrotion: the Icmpor,u), local data for the cRlling block can he accessed via block PlU1lmeters.)

5i,.e "f the L <tack


The 10tal size 01 the L ~tack is CPUspecific. The availahle number or tempornry local data byles in a priority cl as., that is. ;n the progrum ofan organi7lltion block, is also prcQelem'incd. On on 57300, the number of WI11pQRry local data bytes i. fc<~ for example Ihere II~ SIO bytes per priority ela~~ on Ihe CPU 314. On an 57-400. you can specify the number QflC1llpo. nuy local data byles you w,1I need wh~n you initialize the CPU. These bytes mUSI be: shared by the blocks called in Ihl: relevant organi~ti{ln block as well as by tbe block~ which Ihey ca ll. Please nOle that the Editor also uses temporary local data, for in'tan~c for pussillg hl<>ek param~ters. a fact which gocs unnot iced ou the pro~g inlerfa.e.
Decl.",,;""
STNtO
LB>~~

local dlltll

You deelarc the tcmporary local data in the dec


I..... tion """I;on of the c<>de bloc k:
I>

under"temp" in the case of inc",meDlDI pro gramming, or bet",""n VAR_TEMPand END_ VAR "'the ~a.sc of:wu",e""";eDled programming,

Data Type

A .....

I>

ARRAY [1..201
BYTE ARRAY [1..1fiJ l.IYTE

"

Figure 18.S shoWl' an e)Camp'c for th~ de<:lara. lion o f leffiP'lrary local data. The variable dif fen:nce li~s in the tL"IIlPOI1U)' local datu and is o f data type TNT; the variable b"ffe~ is of data lype REAL.

"1.0 20.0

"t .O

.'tgure 18." Example oflhe l),;..clar.... ;on otTcmporary Local Data


in an Orgonizotion Block

'"

18.1 Hlock Functions for Code Dlocks

Start in for ma!lon \\'hen an organization hlock is cal1e<!. the CPU operating system passes start information in !he tempomry local data . This start ,nformation comprises 20 byles for every organization block, and is nearly identical for all OB<. The start infonnation for the variou, organization blocks is describ<-d in detai l in Chapter, 20, "Main Program", 2 1. ""lmcnupt Handling"", 22, "'Stan -up Characteristics" and 23. "Error Handling". These 20 bytes of infomlation mUst always be avai lable in each priority class used. IfyOll program" routine for the evaluation of synchronization errors (programming and access errors). you mu,t set aside an add itional 20 bytes at least for Ihe start information of these error organization blocks, as these error ORs be long to the same priori ty cla". You dedare the start infonnation for an organization block when you program Ih at block. Tbe infoonation is mandatory. Sample declarations in English can be found on the Standard Libra/")' undCT Organization Blocks. If YOll do nOI necd the stan in formation, simply declare the f1r5120 byte, as something else. for example as an array (as shown in Figure 18.5). Absolut e add ressing of t~mpo rary loc a l data Nonnally, you reference temporary local data by their symbolic names. The use of absolute addresses is the exception. Once you are familiar with the way data are stored in lhe L stack. you can comput~ the addresses of the static loca l data yourself. You w ill a lso sec th~

addresses listed in the variable dedaration table of the compiled block . The operand identifier for temporary local data is L; a bit is addressed w ith L. a byte with LB, a word ",ith LW, and a doubleword with LV. Example: You want 10 rc_,erve 16 byte, oftemporary local data for absolute address ing, and you Want 10 reference the va lues in these bytes by both hyte and bit. To do this, creale an array at the beginning of the local data area so that addressing b~gins at O. In an organizat ion block, you wou ld place this alTay declaration immcdiately b~hind the dedaration for the stan infotmation. in ",hich CaSe addressing would begin at 20

A \'ariab1e in the temporary local dala can although this is an exception - he declared as data type ANY. You can use this fearnre to mooify the A;'o/Y pointer at runtime (sec Chapter 24.2.5 ..... Variable .. A.'1Y Pointer"). 18.1. 6 Slane Loeal Data Static local data are operands which a function b lock stores in its instance data block Static local data are a function block's " memory". They retain their values umi ll hosc values are changed by the program.just l i~c data operand, in global data blocks . The number of static local data bytes is limite<! by lhe data types of the variables and by lhe CPU-spedfk lcnb"h of a data block.

D",,\arat;on
IN

OUT 'N OUT


STAT
T~

Nao'e Man on Switd Length Total Sctpoint Difference Buffer

Data Type

Addrc"

Initial Value
FALSE

ROO'
H~'

'"

0.0 '.0

FALS E
0

<NT

INT DINT INT


REAL

'"
0.0 0.0

" .0 '.0

0 1.#0

Comment inpul parameter Output parameter UO paramoter Static local data Temporary loc,.l dala

~ll,l u. ~

111.5 Example of the Declaration of1.ocal Data in a Functioo Block

I ~ lJlock Functions

Ded arl ng static local data


You declare stalie local dala in Ihe declaration <ection ofthc runction b lock :
t> t>

In our lillie example, (h. data bloc k is named Totali::erData and Ihe data opcrand is named Tara!. The "ppli~"ble "ece .. instructions might be as follows:

under "<tat" in the grammmgor

~as"

of in~remcntal proMOVE "Total izer DaH!" . Total

belween VAR and END_ VAR in Ihe CaSe of source_oriented programming,

'N 'N

'NO

MWW

figure 18.5 in Chapler 18.1 .5 , "Temporary Local Data" shows an examrlc of a vari ahle declamtion in a function block. The block patameters are declared firsl, then the static local data, and finalJy Ihe temporary lo~al <uua. The .tatic local data are stored in the instance data block behind the block parameters in th~ order of Iheir decl arations and in accordance wilh their data lypes . Symbolic addressing of .tutic local dal a You rcference Slal;e local data wi lh symbolic I13mes. You assign th e.e name. in accordance with the rule. for b lock-local symbols. All the same oper,nioru; iliat ~an a ddress data operands;n glnhal data blocks can a lso address statk local data, Example: T he function hlock '''Totalizd" a<.Ids an input value to a value Siored in the static local data and then stores the t01a1 in th e static local data . A t the nexI call, the input va lue is again added to (his total, and '0 on (Figure I S.ti above).
70/"/ is a variab le in tb" data b lock "TotalizerData", the instance data block for the "Totalizer" function block (you can define Ihe names oCali b loc k< yourself in Ihe Symbol Table_ but you mu,t stick to the upplicable rule, when doing so). Th~ instance data block h", the data struclure o Cthc function b lock: in Ihe example. it contains tv,'O INT vm;"bles with the name, 1n and TOlal.

W C
MO~

"
o
Loc ul io"a nces

'NO

r- "Totalize,
Deta",
'o~

'"

ou,

When you call a function block, you nonnal ly specify the instance data b lock for thaI call. The function block then stores its b lock paramclc," and it' 'tat ic local da la in this imtance dala block Beginning STEP 7 V2 , you can generale "multiple inSlan~e"', that is, you can call a function b loc k as a local instance in another function block. The static loca l dala (and the hlock paramCte'"J of the function b loc k called arc thm a mb,et of th e caHing block's static local data. Prerequisile is that both lhe calling nmelion b l""k and lhe called function block huve b l",," wrsi<.Jt1 2, that i" tbat both have "mult iple in >tance ~ arabi lily". Thi, allows you (0 " nest" function block calls \IP to a depth of ~ i ght. Example (Figure 18.6 belnw): In the static local data of Ihe function block "Eva luation", you dccla", a variable Af",,,,ory that ~orrespon ds to th~ function b lock "Totalizer" and has its data sttuclUre . Now you can call the function block < "Totali/.er" via th~ variable Afemory, bUI w ilh_ out specifying a data b l""k bec ause th~ data for Afemory are stored "hinck_locally" in the <tal;c loca l data (,\Jl'mory is the loca l inSlance of the function bl"" k "Totalizer"). You a~ CCSg _ 4emory'. slatic local data in th e p rogram in runction block "Evaluation" the same way you would aeees~ slrueture components, which is by sp~ c ifying Ihe structure name (M~",ory) ,md the component name

Accessin g .ta tlc data nuhide the fu net inn block As a rule, the sta lic loe"l d"ta are processed only in the function b lock it>;elf. Because they are stored in a data hlock, however, you can access Ihe static lo cal data at any time with '"[)a/a Block Name".Operand Name j ust as you would a variable in a global data block.

(To/an.

'"

18.1 Block Fuucl ions for Code Blocks


FB "Total iHr" 08 "TotaolizerD8t&"

LAO representatIOn:

AOO
Olin onot.-

,
ENO

~ 0;;"
L.
F8 liTo\a1

'" '" '"

f - lITolal

In 'he Data "i~", Ih. (!~J~ M"'-'k , hm,'.' ul! ,n<llvi"",,/ mriabkJ '0 'hat 'h~ variable, <> a 1 local i''''alJc~ OPE'''''' ,.. II" Jh,i, ji,1I "am" . Simulmneousl)', you su 'he < """"".)i,,;: "" ab~ol"u addre5SS OS " EvaluaUonOat&"

"'"

ENOf-

" Ev elu8 ~on "

LAO ,epresentatk>n:

'!~&j I

#EM Add
''V''lue~'

"'Memory

I'

'N

'NO

I ~e l ete

#EM~O'"

'"
MOVE MOV E

I'

' N

'NO

0.Memory. Total ---, IN

OU ,

"ResullZ"

'" "

'NO
OU, f - .Memory,Total

1
, ,

' :"';'~

FBD fa <l$<Intation:

-"
#Oelete

"M,

'"0
"ValueZ" -

II'Memory

, ,
"

#EM Del

'" '" '"


'N

'"0 l-

"
MOVE MOVE

0-

'"

#M .. mory.Total -

,"0

f-- "Rasu lt2"

'"

0" f'"0 I--- #MemoryTotaI'

F12ur. 1H.6

E~amr l e

of Sialic Local D"a and Local In"8nc<s

18 Block Functi(ms

Th e instance: duta block '"EvaluationData" thus contain, the variables .\femory.]n a"d Mem ory. ro/al. which you can ulso ad<.lress as global variables. for example as "Evaluation_ Data .Memo"y. Total. You can fmd Ih is example of the use of a local in,llmee in function bloch FH 6, FB 7 and FB 8 ;n program "Program Flow Control" in the libraries ""LAD_Book'" an d "FBD_Book'". [hat you can download from the publi,her'. \\febsite (sec page S). The " Feed" example in Chapter 19.5.3. '"Feed Ex~mple" contain. additional usage of local instanc",. A b .olute addres>fng of .tat1e 10e.1I duta As a rule, the slatic local dala arc addressed symbolically. Absolute addre%ing is the excep_ tion. Within a function block, me instan~e data block il; opened via the Dl register. Operands in this data block. and this includes the ;;latic local data as well as me block parameters. therefore have DI as Op<.-rand identifier. A bit is addressed with DlX, a byte with DID, a word with DIW. and a doubleword wim DID. Once you know JUSt how data are stored in a dall. block, you can compute the absolute addre ..e< of the static local data yourself. You can also find me addre,s~s in me compiled block in the variable declaration table . But be very ~areful' These addresses w"l' addll?3ses 11.,,1 are relative 10 the slart of Ihe illSlance. They apply unly when you ~all me function block with a data block. If you call th~ function block as local instance. the local in'tance's local data "r<: located right in tbe middle of the call_ ing function block's instanc e data b lock. You can view the absolute addreoses, for example. in the compiled instance data block wh ich contains all local in.tances. Select VIEW --> DATA VIEW when you want to read up on the addresses of individual local data operands. Using our example as a basis, the "mable Total in the function block '"Totalizer" could be uddresscd with DIW 2 if function block "Total ;~er'" were called with a dala block (also lee the operands in me data block "'TotalizerData"'). and wim DlW 6 if function block "Totalize,'" wC1"C called as local in!tan~e in function block '"Evalu"tion'" (also sec the operands in data block '"Eva)uationData").

18.2 Block F unctions

fOI"

Data Blocks

You ;;tore your program data in the data bloch. In principle. you can also use the bit memory lm"'a for storing data; however, with the data block;;. you have s ignific antly mOre po'isibilities with regard to data volume. data stnlcmring and data types. This chapter shows you
I>
!> !>

how to wone with data operands. how to call data b locks and hew to create, delete and test data blocK. at nmtime

You Can use data blocks in two version." asglobal dala blocks that are not aSiiigncd to any code block. and as Instance dara blocks mat are assigned to a function hlock . The data in the global data bloc"" are "'free" dma thaI every code block can make usc of. You yourself determine thcir volume and structure directly through pro!,,'ramming the global data block . An in_lance data block contains only th~ data w ilh which the asso~imed function block works; this function b lock then also detemtines the stru~ and storage location of me data in "i ts~ instance data block.

The numb..r and length of data blocks are cpuspecific . The numlx'ling of the data block begins at I: the re is no dala block DB O. You ~an use ea~h data block either as a global data block or as an instance data block. You muiit rm;t Create (""!el up") the data bhx;kli you use in your progr~m, either by program_ ming, such as code blocks, or at rumime using the systcm function 5FC 22 CREAT_ DB.
R.~bt~rs

18.2.1 Two Data Bl,,<k

Ea~h 57-CPU has two dala block registers. The,e registers comain th e numbers of the Curr<:nt data hlocks; these are Ihe data blocks witb whose ope rands processing is currently taking place. Before accessing 8 data block operand, you muS! open the data block containing the operand. If you us~ fully-addressed :leeess to data operands (with specification of the data bluck. see below). you need not be concerned ,vi!h opening the data b locks or with th~ contents of the dala block rcgis tns . The Editor gen -

'"

18.2 BI<xk Function. for Data Bl<xks erntes me necessary mstru,;tions from your specifical;on5.
The Pr08T11tn Editor usu the firsl (lat" block register preferably for accessing global dala blocks and me second data block register for ac"",,,sinll inSlance dma blocks. For th;s rclLSon. these reglster~ arc given the names "Global (lata block relPster" (DB register for short) and "Instance Data Block Register" (Dl rt'gis[er for short). The lIanuling ofthe registers by the CPU ill absolutely identicaL J:;ach data block can be opened V;A one ofthc two regi,tcrs (or al.o via both simultaneously).
"0 come 10 the essential point

Symbolic access to the data op<.'f'lUlds in g lobal data block~ requires the minimum system knowledae, For absolutc acccss or for usina both data block registcn. you mUliI ob8crvc tJw.: nores beloW.

I[ is recommended that you addrelIII wua <>pl'fands symbolic.lI)' ,,henever possible. Sym bolic addressing
~

first: You can affcet only the DB regISter with LAD or FBD. If you open a data block wi th the OPN coilibox (sec be low), yo u always open it via the DH register, In LAD and FDD, the instance data block is always opened via the Dl regisler: this happens with Ihe call boll when the block is caUed.
\VIIen you load a data word. you must spe<:ify which ofl1le two possible open data blocks contain. thc dalll word. If the data block has been opened via the 1)8 register, the data word is called DI:lW; if the d.1l1 word is in Ihe data block opened via the \)1 register. il is called J)IW, The other datu operands are named accordinill y (Tab le 18, I).
Table 18.1

makes it easier to rt'ad and undeBtand the program (if meaningful lCTtllll are used as symbols), reduces "rite errOr~ made d.u:WII programmini (the ProifWll Editor compares tlte terms used in tbe Symbol T.. ble and in the program; "number-switchi ng errors" such as DaB 156 and DaB 165 that Can occur when using absolute addresses ctinnO! occur bere) and
does 001 require programming knowledge at the machine code level (which data block bas the CPU opened currently'!),

0.,. Operands

Symbolic addressing us"'" fully-addre.'lsed access (data block t0i<'ther with data operand). ~o that the data operand always hn a Imiq ue addrc . You detennine the symbolic addren of a data operand in lWO 5tep.!:

[)atab~

Olay

0.[. wurd

1)

A~signmem

oflhe dala block in lhe Symbol

Table Data blocks are Jobal data Ihat have un ique addres~ within a program. In the Symbol Table. you assign a symbol (e.g. MOlorl) to the ab$Olute addres~ oflhe datD hlock (e.g. \)ala Operands

111.2.2

Atcu~lng

DBSI).

You can use the followina methodS ing data opcrnnds;


~

rOT .ccess-

Symbolic address ing with full addressing. Absolute addre"';na witb full addreuing

"od
:>

Absolute addressing with partial addressing.

2) A.signment ofthc dala oper.:md.5 in the data block You define the names of the data OVC,",,,d8 (and thc data type) during programming of the dala block. The nalOe applies only in thc 'lSSOCiated b lock (il i, "block-local")_ You can also use the ume name in .. nother block for another "anable.

I ~ 1I 1oc~

Function.

Fully-addressed aeeHS to data operand . In the case Df fully_addre<sed acee". YDU specify the data b lock together with the data operand. This method Df addressing can be symbolic or HbwlulC '
"M7!"OR l- . ACIVAL IlB 51-DBW 20

18.2.3 Opening a Data Block


You use the OP1\' coi l (LAD) or OPN box (FB O) To open a data b lock v ia the DB register.
Open dato btock LAD representation'

f--{ OPN}------l

",

MOTORI is the symbDlic addre" tha t you have assigned to a data block in tbe Symbo l Table. ACrvAL i. th e data operand you defined when programming the data block. The symbolic name "MOTORI".ACTVAL is JUST a, unique a specificaTion Dfthe data opemnd as The specification DB SI.DBW 20. Fully-addressed data access is Dnly j"lOssible in .onjunction with the global dam block regisT er (DB register). In the case of fully-addressed data operands, the Program Editor firs! opens \he data block via the DB register and the n accesses the data op<:ratld You can use fully-addressed acec,s wilh all functions permissible fDr The data lype of the addressed d,tla operand. So with b lock parnmeIe,.,;, for example, you can also specify a fullyaddressed data op"rand "' <lemal parameler. Absolute addressing of data operands For absolute addressing of dala operand~ . you must know the addresses at which the Program Editor places the data operaods when setting up . You can fim] out the addresses by ourpulting them afterprog:ramming and compiling the daTa block. You will then see from The addres, colwoo The absolute address at which the relcyant ..ariable begin,. This procedure is , uitable for all data blocb. both those you u,e as global data blocks as wel l as those you use as inSTanc e data bl""ks (for local instance, see ChapTer 18.2.4. "'Special Points in Data Addressing"). in (his way. you can a lso see where The Program Ed itor stores the block paramelers and The slatic local data for function bloeb. oa(a openmds are addressed byte by b)1e like, for example, h it memory; the funCTion, used on {he data operands are abo Ihe same as those use,1 with b iT memory.

FBO representation:

The OPN coil!box is conneCTed d irectly 10 the left power rail ,md slands alone in a rung. The specified data b lock is always opened via the DB regi,teI. In LAD or FBo. it i.s ooT possible to open a data block via the 01 regisler with OPN eoilfbox. (The Dl register u.se, the call box to open The current irut:mce data block.) In th~ ca,,, of incf<-'IIlental programming, you will find Ihe Oi'N coil/box in the PWb'r.un Tilements Catalog under "DB Call". Th e open data block must be in the work memory at runtime. In the nCIWOn.:s following 'he OPN eoil!box. you ean use panial addre,sing to access only Those dala op"rand, that are locaTed in The open dam block. If you want 10 copy from one data block to another, you can, for example go into Ihe lemporary local data via an intennediaTe b uffer or (better) usc fully-addressed data operands. Pleas e note : A fully-a ddressed data operand o\erv"rttes the DB regiSTer with "its'" data block. EXmlple: The value of data word DEW 10 of data block DB 13 is to be Iramferred to data word DBW 16 of data block DB 14. With the MOVE box, you can only copy partiallyaddre,sed data operands within the currently open data hlock. For copying between d ata blocks. you require an intermediate butTer. such as a local data word (sec Figure 18.7). It is better to use full addre~'ing .
Wh~", you open a data b lock. it re mains "valid"' until another data block is opened. Under cerlain cir<;umslanecs, you IlliIy not be able 10 see this via the J>mgram Editor, for example if a block is changed with the call box (sec Chapler 1S.2.4. '"Special Points in OatH Addressing"').

'"

18_2 Block Flmclions for Data Blocb

~~~'i3'

,
DB 13 (OPN}----1 DB 13

I O'N I

Network: 6

Load from DB 13 and copy into a bllffer


MOVE

~ ." #CWORO .~:


~':,;,l

DBW lQ

' N 'N

0"' ~1iIt_WORD
DB 14 (OPN}---j

' NO

DBW 10

MOVE

'N 'N

OUT END

::;'[

....

Notwork 7 ; OpiIn data block DB 14

I
Networi< 8 MOVE , iIt_ WORD Network 9; -

I OPN I
~

DB 14

Copy 1T0m bllller Md transfor to DB 14

Copy with

'" '" '" '"

'NO OU'
MOVE

DSW 16 lit_WORD

MOVE

'N 'N

0"' '"0

O BW16

Iully--ad dr~uCd

data operands

'"0
DB 14.

0813 .
DBW12 DBW HI

M OV E

DB'3,; _ DBW12

'"
'N

OU , 'NO

_~B 14_ DBW 18

..
..

....

OU'

tn the c",~ of a block changc w ith the CALL eoilfbox, the co"t~'tl lS of the data block r~gist",-,; au retained . On returni ,,!! to the calii"g block. lhc b lock change rCston;s the old contents of the registers .

.tccess;ng block param~rer$


Access to the followin g b lock parJm~IC'" changc s the contents of the DB regi<ter: All block param~tc"" of complex data type in th e ea3\; o f functions, and ;n/ol1t parameters of complex dsta type in the case of function b locks .

18.2.4 Slleclal Chuoges in


lh~

Po int~

in Data Addre"ing
~egi st~r"

c"nteD" of {he DR

C" /linK "-funerio,, block >";th the call box


Bcfor<: the actual function block ca ll , thc call box ,lares the number of thc current ;n<ta nce data b lock in the DB register (by swapping the data b lock regi __ !ers) and op<..'t>s the in <tance dara block fur the called function block. In this way, the in<tancc data block associatcd with a c"l led function b lock j" alway< open. Amr the actusl block ~a ll, thc ~;,Jl bo x swaps data block registers again, so th at the current instance datu b lock is fl\'ailablc "gain in the c,,-lI; ng function b lock. ill thi s way, the ca ll box changes the contents of the DB register.

W ilh the following funccion<, the Program Editor g~n eral~' add;t;o nal instruction, which can alter tb~ e(ITllcn ts oflhe two DB rcgistcrs ;

Full ",]dress;ng of Ja/" operands


Each timc data operand, arc fully addressed. lhe Program Editor finn op<'"m 1he dats h loc k and then a c c ~ sses the dala operand. The DB rugistcr is ovcrW'riUen uach time . This slso applies to supp lying block parameters w ith ru lly_addre<sed dala operands .

18 Block Funclion;;

DI register in [omelia" blocks


In function blocks, the 01 register always conlains the number o f the current instance data bloc k. A ll accesS to block parameters or stalic local data is o"~" the 01 register. The address of Ihe local data g iven in the Oedru-ation Table of the f""c!ion block applies on ly when you open Ihc function block with an inSlan <: c d~ta block, in which ca;C the data operando begin at byte
~ero.

"0...,,,,-"

. A ~ ~Va h:.

t$l.Daw 10

where "Data" is tb~ symbolic address for data block DE I. If you would now ad d an a<l<litional da!>! word with the symbolic address klaxC",rell[ ;mm(Xl ;atcly in front of data word DBW 10, the rcsult upon the next opening (or storing) of!he code block will be as follows: In the case of "A bsoh<te add"". .' hlls priorily ": '
::Oata".MaxC-~r re nt

DEl. .DEW H

\Vhen you call a functio n block as lo(al inst"nc~, its data are "in the middle" of the calling data b lock's imtan~~ data bl""k. They contain tbe absolute addre<s of the \c,cal data when you output the in,tance data block in data view formal. Each individual variable is then displayed with name and address, including (he v,mable s of (he local instance called When yOll program a function block that you a l'o wam to have avai lable later a, local instance, you do not yet know the ~bsolut~ addrcss ofthc variable at the time of programming . In this case - JUSt as the Program Editor does for symbolic programming - (he content s of address rcgister AR2 lire added to the vari ab le addrc>s. However, this is poss ible only in the STL programming lang uage. Chan ging th e cont~nh of d a t R blo;:ks at a late r time In the PToper!ies window of the otiline objttt container Blocks in Ihe "B loch" rcgi,ler. you can "~ify whethcr the absolute address or the symboli c address of the data operand is to have priority for s"bsequcnt d;;;plays and savcs when thcr~ is a change in the contents of the data b lockS for code blocks (hal have already bcrtt stored. The default is "AbsolllIC address has priority" (the same a. in previous STEP 7 ver<ions). Th is defa"h mean, that when there is a change in the dec laration, the absolu!e add,,-,ss is rdained in the program whi le thc symbolic address changcs acco rd ingly. lfthe "Symbolic address has priority" default is chos(."n, the absolute add",,, changes whi lc the symbolic addrcs' i.' retained. Examp le: illsum ;ng that data word DEW 10 in d ata block DB 1 (ontains the symbolic address of ActVilh,e. In the program, you might adJ ress this data word wi th

In rhe ca.,e of ''Symhok' address has priority"','


"nat ... " . ActValu.

A, for a cces. !O data operand~ in global data b locks. tho same appli e, as for acce,,!O global operands (for instance inputs) for which a symboli c address has been entered in the Symbol Table . You will fi nd ,ktai1cd information on this subject in Chapter 1.5.5, "Address Priority". Note that this "rewiring"' does not take place automatically since th~ b locks whicb have already been compiled contain the executable MC7 code of the statemcn!s vei th lhe absolute addres . The change is only carried out in the !1:S~ociated blo~k (with a corresponding mes o sage) following op~ning and saving again. In order to carry out the modification in the complete block fold.r, 'ck~! EDlT ---> CHECK ELOCK CONS1STENCY with the Blocks objcc! sclteJ

18,) SY 5tem F unction s for Data


Blocks There are three system functions for handling data blocks . Their par~met~rs are dcs~ribed in Table 18.2.
I>

SFC 12 CREAT DB

Cre ate data block in work memory


l>

Sf C 85 CREA DB Create data block in ,,"urk memory SFC 82 CREA OBI. Create data b lock in load memory SFC 23 Dt::L DB Ddete data block SFC14 TEST_ DB Test data block

:>

18.3 System Table IS 2 SFC, for Handling Data B locks

Fun~tion"

for Data Block.

=i;;i;;

" "

;:,;;
~

rJ!
,',

, , ,
"

'6"~ ,
,
.
BH 16l'()4

,
,

"

.~ ~

, ,
, ,
I ~Y

"
,

, ..
,

,;,

,
;

,
"
~

~
H1 ~

b
,

block i5 initialized

"

, ,,

IS.J.I Crea tIng a I)at~ Bloc k In "\\'o r k J\femor J System functiom SFC 22 CREAT _ DB and SFC 85 CREA_DB create a data block in th e work memory. As the data h lock number. the system functi"n tak~s the lowest mc number in (he numbcr band given by the input paramctcrs LOW l.IMIT and UP LIMIT. The numbers <pecit1ed at these parameters a r C induded in the n umber b and. If both valu~s are the same, the <Ia\a b lock is ~reatcd with this number. The number of a data b lock already pres~"Ilt in the user program ~rumo l be assign~ d aga"l. n()\

even i ft he dala block is only pre,en( in the lOad memory. The output parameter DR NUMBER supplies (he n umber of the data block acrualJy ~rc "ted . W ith the input par"mctcr COUNT, you specify th e length of the dala block (0 be created. T h e length ~orrcspond. to the number of data byt~s and mLlst he an even number. Creati ng th e data block is not the same as call ing it. The current data h lock is still valid. A dat" block ~reated with this syst~"Ill funcliOTl contains random data . For meaningfu l usc, data

18 Block Functions n,e data al'~a a<> igned as default 10 the cr~a\cd data block is spec itie<:l ot input p arameter SRCBL K. Hen: you can spccify a com plete <lata block, e.B. DB \ 60 f)T "Areh>,e l. " "anable from a data block, or an ah.olute addc~ssed dala area as an ANY po;tlkr. e.g. P# DB 160 DBX I6.0 BYTE 64. The ' OlITCe rou;;! be a data area in th e wock memory. If\hc somee acea is smaller than the target area , the ,omce area is wr itten completely into the target area. The remaining bytes of the ta rget area ue fil led ",;th ~eros . If lhc source area is larg~ (han (h e target arca, the target area IS '1' written completely; th e remain in g byte , of the SoUrc e area Brc ignored. Yo u can ass i!(J1 Ihe roll"wing altrib "tes to the created data block "sing the ATTRIB parameter;
'>

must tirst be w rillen to a data hloek created in this way bdQrc t h~ data c an b~ r~ad.
The data bloch cr~ated w ith t~ SFC . 22

CR E AT D B and ~5 CRA Oil ar~ "nl)' pres~nt Tn work memory If a CPU diff~rcn li ate, bem'een retentive and non-retentiv~ work memory, lhe SFC 22 CREAT_DB ~realCs a ret~>y) li vc data block, and the SFC 85 CREA_ D H creates a dall' bloc k as specifierl hy the AlTR TB parameler. "Retentive" dala block mean s that is its contents are retaine<:l in the event ofa w a nn restarT/ho\ rc'lart (,~c Chapter 22.2.4 , " Retentivity"). T he syslJ,;m fu nction SFC 8S CRA_ DB replaces the SFC 22 CREAT_DB.

A <Ia,a block cre ated by the Sl:'Cs 22 CREAT_ DR and SFC ~5 CREA_ DR dues not change lhe checksum of the Ll.~er program. not even if it is WIitt~n or deleted again. If a data block created by an SI'C is i.mponcd imo the o m ine data mO!llig~mcnt. this has an influen~~ on tb e
ch~cksum.

In the even t of an ~rror. a data block is not erealedo the pam meler DR_ NUMnER paramet ~r i. assigned Z<.--ro, and an ~rror number i. output byRT_ VAL

B it O = "I" The dat<! block has Ihe Unlinked anribute . Following transfer to the offline data m anagemenl and reloading into the C P U, the <.lata bl ock ;s still on ly pccs~'IlI in the load
m~mo ry.

'" Bitl = "j" The d,ua block has the DB is write-pml(!ded in /he f' I..C a ttrib ute. Yo" can only read the val ue. of thi' dala block. '" Bit2=" I" n,~ data block attribllle. has the

H I.3 .2 Crellt ing a Da ta B lock In LOlld Mem ory


System functi on SFC 82 CREA_ DB L crcat"" a data b lock in Ihe load memory. As the data block number. Ihe syslem func lion take' the lowe'l tree numlx.'r in th~ numb~r band given by the input paramcl~rs LOW_ LlMlT and UP_ UMIT. T he numbers .peeiiied at these pommelers are induded in the number ba::ld , If bOlh v a lues an: the ,arne , the da la block is cre3ted with th is number. The numix:r of a data b lock a lready present in Ihc user program cannot be as<igned again, nOI even if the dala block is on ly presenl in the work m emory. The output parameler DB_h'l JM ,uppl ies the number o f the dala b lock ac.tually created , Wilh Ih~ in put parameter COUNT, you spedfy the length of the data b lock to be crea\ ~d. The length corresponds w the number of dala bytes and must b e an c"cn number.

Non Rei";,,

The other b its arc not "sed al lhe mom~nt , You can find funhe r infonnation on the b lock attribllles in C,hapte r 3,2.3. "Block Pro!X'rtie," System function SFC g2 CREA_ Dl:IL operates in ""yn~bruDous mode: you trigger lhe c re ation proce ss with S'b'l,al state "1 " at iu p "t parameter REQ . You mavonly access 'he read and written data are a, again when the Olllplll param~1cr BUSY has returned to the .ignal , tate "0", Creating does not call the associaled data block. n , e current data block is slill Ihe ""lid onc .
A data block is not cre ated in the e vent of an en'or. the output parameters are a>signed undefined values. and an ~TIo r mc",agc is out r ut by Ihc function val ,,~.

18.3 Sy.tem Function. for Data Blocks

18.3.3 Deleting a Data Bl(lck System function SFC 23 DEL_ DB deletes the data block in RAM (work and load memory) whose number is specified in the input parame ter DB NtJ1.1BER. The data block must not be open at the time, as otherwise the CPU will go to STOP. Data bloch created with the keyword Unlinked and data blocks on an Flash EPROM memory card calUlot be deleted with system function SfC 23. In the event of an error, the data b lock i~ not deleted and an error number is returned as function value.

18.3.4 TeSllng a nata Block System function SFC 24 TEST_DB provides infonnation On a data block whose number you spec ify at input parameter DB_NUMBER. Output parameter DB_ LENGrH contains the number of existing bytes. and output paJ1lmeler WRITE_ PROT indicates whether Ihe data block is write-protected. If the tested data block is only in load memory. this is indicatw as an error by RET_ VAL: the DB_LENGTH and WRITE_PROT parameters ne'e.rtheles. have the corre~t assignn"'nts. If the specified data b lock is not present in the CPU's work memory, RET_ VAL is returned

with W#I6#80BI.

'"

19 lJJock Parameters

19 Block Parameters

deB.
t> t> t> t>

This chapter d<:$C:ribes bow 10 use block: paramYou will learn how to
d~lare

block parameter5,

how to work with block partmcte1"S,

bow to initialize block parameters and how to 'forward' block: parameters.

Block parameters represent the transfer inler_ face oolWL-.:n the calHna and the called block. All functions and function blocks can be pr0vided wilh bl ock parameters.

block function. Example: You want to write a block as an adder that you can use 111 your proiram ~'eral limes with different variables. YOIJ II1ltIsfer the ,'ariables as block parameters: in Our example, three input parameters and OTIC OIJtpUl parameter (Figure 19.1). Since Ihe adder need nOI Slore any values internally, II function is suitable as the block type. You define a bloc. parameter a. an input parameter if you only Check Or load ;IS value in the block program. If you only describe Il bloc. parameter (assign , set, ",.et, transfer), you u!e an output parameter. You must always use a n illlout para meter if a block pammeter is to be both ched:cd and overwrinen. The Program EdilOr does nOI ched: the usc of the bloc k panullctcr:.

19,1 Block Parameters in Ge neral


19.1.1 Denning th e
8lu~k

Pwramcters

Block parameterS mllke it possible to parameterile the processing instruction in a block, the

.,,,,

Btock ty?!, name .

Fe 12 Nama : Adder

Parameter .

Pr~m

om

Ronutt
FI~ur. 1~.1

Eumple of Block P.ramctcrs

19. 1 Block Parameters in General

19.1.2 Processing t he Rlod< I'aram~te~


In the adder program, the names of the block parameters 'tand a, p lace ho lders for thc latc,t actual variab les, You use the block parameters in the same way as symbolically addressed variables ; in the program, they are called "formal parameters" You can cal! t~C "Adder" function several lim .. in your p rogram. Witb each call, you tran,fer o ther value, to tho adder in ,he block parametcrs (Figure 19.2). The values can be constant" operands or vari"bles; they are called "actua l p'''dmetcrs''. At runtime. the CPU replaces the formal param eters w ith the aClu,,] parameters. The first call in the example a dds the ContentS of memory words MW 30, MW 32 and IvlW 34 and stores the result in memory word MW 40 , The same block with the actual parameters of the second call adds data words DBW 30. DB W 32 and DBW 34 of data block DB 13 and slOres the result in data word DBW 40 of data block DB 14 .
1/ Fir" oall

MW30 -

-Adder" Num b_1 Resu lt MW32- Numb_2 MW34 Nu mb 3


~

r,

MW4Q

Actual parameter
II Second co11

Illock par.meter -Adder" Num b_ ' Result Numb_2 Numb

DB 12. DBW30

DB '2, DSWn _
DB 12 , DBW34

r-

D812. DBW40

ADD I
-M~

Numb_1 Numb_2

Memory Numb_3 -

19.1.3 Declaration oftbe Block Parameter. You define the block parameters in the declaration ,eclion of the hloc\: when you program the hlock. Figure )9.3 shows the declaration tables of a function FC and a function block FE. In addition to the b loc k parameter>< (IN . OUT, I:N_ OUT), you also declare the temporary local data (TEMP). the function value (RETURN) for fun ctions Fe, and the static local data (STAT) for function b locks. Only the temporary local data (TEMP) exists for organization bloc ks OB which arc neither called in the u,er program nor possess an instance data block. Default values are optional and are only possible for function blocks if a block parameter is stored as a value. This applies to all block parameters ofdemcnt"T)" data type and to input and output parameters of comp le x data lype. A parameter comment can al so b e given.

~m"m
ADD I MW3Q- IN1 MW32- _ IN2 M emory ~,.

'N'

'" 0'" '" ADD_ I '" 0"' -

R.... ult

Fum,.1

0"' -

"""""

II Second call

'"'
'" 'N'
ADD I -OUT Memory

'"'

ADD_bUT

-MW 40

DB 12. DsW30 OS 12 DBW32 Memory DB 12. DBW34

'"

ADD I -OUT _

DB 12. DBW40

'"

Figure 19.2 Block Call with Block Paramete..

19 Block Parameters

Fl2U r . 19.3 Empty Dcciarntion T.bles for

~unct i ons

Fe and

~unction

Bloch FB

The block parameter name Can ~ up to 24 ~haracters in length . II must consist only ofletlers (without nati onal characters such as the German Um laut). digits. and the underscore. No distinction is made between upper and lower case. The name must not be a keyword.

by specifying th~ data tYP<' and possibly a com ment in th e declaration table u nder RETIJRN and the n ame RET VAL. As data type of the fWlc\ ion valt.lc, all elementary data type, as well as the data types DATE_ AND_TIME, STRING, PO INTER, ANY and user-defmed data types UUT are p.:rmiued , The data typ es ARRAY and ST RUCT arc no! allowed. As the fir<t outp ut parameter, the function va lue has no spec ial role to play in the LAD or FBD programming language. It only g ains significance in the SCL programm ing language, where you can usc the block type FUNCTION as a '"genu ine" function. Here, a function Fe can stand in p lace of an operand in a printout: the function value then rep resents Ih e value o f th is function.

For the dam type of a block parameter. a ll elementary, complex and user-defined data types are permissible as well as the parameter types (see C hapter 3.5. "Variables. Constants snd Data Types"). ST EP 7 stores the names o f the h lock paramete rs in the non-executable section of the blocks on the programming device' s .'torage medium. The work memory of the CPU (in the compiled block) contains only the declaration types and the data types. For this reason. program changes madc to b locks online in the CPU must always be updaled On the programm ing device's data medium in order to reta in the original names , If the update is not made, or if blocks are transferred from the CPU to the pro_ gramming device, the non-cxecutable_b lock sections are ov~rwrittcn or deleted. The Program Editor then gcnerates rcplacement sym bois for d i8play or pri ntout.

19.1.5 Initializing Bl ock Para meters When calling a block with block parameters, you in it ialize the block p arameters with actual parameters, These can be constants. operands with absolute addresses. fully-addressed data operands Or symbolicall y addresscd variables , The actual parameter muSt be of the sarnO dala type as the block parameter. You must initia li?c all o f a function', b lock parameters at every call. In the case of function b locks. in itialization of individual block parameters or a ll block parameters is op tional.

19.1 .4 Dcd ara tion of the Funct Ion Va lu e In functions, the function value is a speciall y treated output parameter. It has the name RET_ VAL (or ret_val) and i" defined as the first output parameter, You declare the fu ncti on value

'"

1<;1.2 Foml,,1 Parameters

19.2 Formal Parameters


In this chapter. you willieam how \0 a~eeSS the block parameters within a b lock . Table 19.1 shows that it is possible to access block parameters o f elementary data type, components of an array or structure. and timers and CountC1"S without re>triction. Chapter 19.4, ""Forwarding" Block ('arameters" Access to parameters of complex data 1ype and of paramctcr types POINTER and ANY is not supported hy LAD or FBD. However. you can initialize acqu ired blocks or sys1em blocks that have such pararnc t~"T8 with the relevant variable. You c an find examples of this in the libraries "LAD_ Book" and '"FRO_ Book" under the program " Data Types" that you can download from the p(,blishcr's Web5 ite (see page 8). Block parameters with data type ROOL Block parameters of data type BOOL can be individual binary variables Or binary compo-

nems of army. and structures . Yo u can chec k in put parameters and in!out parameters wi th coutaclS or with binary box inputs. and you can iniluenee output parameters ~lld in!out parameters with b inary box Outputs . After 1he CPU has used the aetual pammct~r spec ified as block parameter, it processes the functions as shown in the relevant chapters. Bl()ck paramNers ()f digital data type Block parameters of digital data type occupy 8. 16 or 32 bits (all elementary data types e~cept BOOl.). They ean be indiv idual digital vari_ ables or digital components of arrays and structures . You app ly input an d in/out parameters to digital box inputs. and you write output and in! out parameters to digital box OU\pUIS. You exchange values hctv,:een block parameter!; of different types or different sizes w ith the MOVE box as described in Chapter 6, "Move Functions".

Table

1~.1

Accessing!:l1ock. ParameterS (General)

;
O~

Possible

,=,
type,
DT. STRIl--'G ARRAY. STRUCT In dividual binary components tndividual digital components

, ,

, ,

, , ,

yes

'"
M

,
,

, ,

, ,

,..
ye,

TIMER COUNTER 8LOC K ]C. BLOCKJB BLOCK_DB BLOO,_ SDB

, , , ,
, ,

". ,. ,.,
yes

,"

0" 0"

J 9 Block Parameters
B lock parameter. of da ta type COUNTER You can use b lock parameters of data type COUNTER with all functions as described in Chapter 8, "Cowltcrs"'. When setting a counter, the counter v alue can also be a block parameter of data typ e WORD. B lock parameters of dat.a type BLOCK_ DB You can transfer a data block via a block parameter of data type B LOCK DR Call this data b lock w ith the OPN coillbox by lalx:ling the OP;:"! coil/box with the fonnal parameters . When opening a data block via a bloc k para meter, the C PU a lway, uses the global data block register (D B re gister), Bl ock parameters of data type BLO CK_Fe You can traIl5fer an Fe function via a b lock parameter of data type BLOCK FC Call this function with the CA LL ~oi llbo; You can uSe the CALL coi1lb o~ with a formal parameter and w ith or w itho ut any preceding logic operation if you are currently programming a function b lock , If you usc the CALL coil!bo~ witb for_ mal parameters in a function. a preceding logic operation is not permissible (ab~olU1e call only). An Fe fu n cti oo lranskrrcd via a block parame ter must not have any b lock parameters. Block panmeter. of data type BLOCK_FB You can transfe r an FB function block via a blo<:k par.mlctcr of data type BLOCK_ FB . Direct aec es< to hlock parameterS of data type BLOCK]B is not possible wi th LAD or FED functions , An FB func tion block transferred via a block param et~r must not have any block parameters. Block parameter. o f data type PO INTER and A... "'Y Direc t acces , to bloc k parameters of data type PomTER and ANY is not possible with LAD or HH) f unctions ,

B lo(k param,'len of data type DT and STRING Direct access to bloek parameters of typc DT and STRING is not po>s ible. In function blocks, you can "pass" input and output param~ters of data type DT and STRING to parameters of ca lled block. Bl ock parameter. nf data type A R R A Y and STRUCT Direct a~CeSS to bl ock parame!= of type ARRAY and STRUCT is po,sible on a eomponent_hy_componcrtt basis, that is, you can access individual binary or digital components with th e relevant operations, Access to the complete variable (entire array or entire strucrnre) is not possible and neither is access to ind ividual components of complex or user-defIned data type. In fimction block" you ""n "pass" input and output parameters of data type ARRAY and STRUCT to parameters of called block!; . Block parameters of lI~er-deflncd data type You handle block parameters of user-defined data type in the same way a~ b lock parameters of data Iype STRUCT. Direct acceSS to block parameters of data type UDT i ~ possible on a componcm-by-eomponem basis, that is, you can ~CCeSS individual binary or digital compone nts wi th the relevant o\X-rat ions Access to the complete variable is not po,sible and ne ither is access to individual components of complex or Ilser-ddined data type, In function blocks, you can "pass on " input and oUlpm parameters of data typ e U DT to parameters of called blocks . 810ck para meters of data type TJ:\IER You can uSe block parameters of data type TIMER with all functions a s described in Chapa-r 7, "Timers', When a tim er is stmtcd, the time value can ,,],0 be a block parameter of data type SS Tl.ME.

19.3

A~tua l ParaJT1ete~

19.3 Actual Parameters


When you call a block, you ini tiali~e it, b lock parameters with con>!ams , operands or vari_ ables with which it is to operate. These are the actual param<:tcrs.lfyou call the block often in your program, you usually USe different a ctual parameters each time . An actual parameter must agree in data type with the block parameter: You can only apply a binary actual parametcr (for e:-;amp le, a m em_ ory bit) to a block parameter of type BOOL; you can only initialize a block panuneler of type ARRAY with an identically dimensioned array variable . Table 19.2 gives an overview of which operands you can use as actual parameters with which data type. When ca lling functions, you must initi alize all b lock parameters with actual parameters. When callin g fun ction b locks , it is not a manda_ tory requirement Ihat you initializ e b lock parameters with a~tual paramet"rs.lfyou make uo specification ala b lock parameter, the (old) values stored in the instance data block are used as the actual param<:ters. These can b~. for example, the default va lues Or the valu es of ""tual p arameters from an earl ier call. In/out parameter. of complex data type ~annot be assigned defau lt vailles, and neither can parameter types . You must provide these block parameters with actual parameters at lea,t allhe fir.t cal l.

You can also use d irect access to aeees~ the bl ock parameters for the fu nction b lock. Since they are located in a data block, you can handle the block pararn~ters like data operand s . Example : A function block with the instan~e data block "S/a/ion_l'" controls a b inary output parameter w ith the n ame '"Up '". Following processing in lhe f" nction block (after its call), yo" can ch~ck Ihe parameter under the symbo li c address " Sla lion_ t".Up, without having ini_ tialized the output parameter. Initlalizlng block paramet ers with dc mcntary data types The actual param~ters lisled in Tab le t9.3 are permissible as actual paramcters of elcmentary daUl type. You can assign either ab solute or "ymbolic addresses to input . output and bit memnry operands. Input operands shou ld ~ used only for input parameters and output Op<'rands for OUIp"t paramete rs (however, this is not mandatory). Bi t memory operands are suitable for all dedaration types . You must apply peripherat inputs only to input parameters an d peripheral outputs on ly to output parameters. You use the 800lean constants TRUE and FALSE in LAD and F130 10 sct defaults in the de~ l aration of block parameters, static local data or dala operands . Initializing block paramete~ with thes~ const~nts ; s not penniued. You also cannot Create these con . tants at n contact ( L AD) or at a function input (FBD). If you want

Table 19 .2 tnitialization with Actu~l

P aram<t~f"

"

Cornponetlts of arrays or

,tructur~ S

of ~I <men tary data I>'pc

"

Block parameters o,thc cal ling block

19 Sloek

ParameI~r1

OUlput$ (proc<'ss ;ma~)

, ,

, ,
<

,
,

,., "
Qy.x

"

:-t

<

<

,
<

DID

Compl= component name

"

to initialize block pan"nc\~rs with TRLc or FALSE, you require a variablc that ;s pennanenlJy ass;gne<i signal ,tate "1" or "0" and thaI you usc instead of the Sookan con'lanIS. Bil memories are obvious candidate3 for "ariables ill th is..,.....,.. The following example shows)'ou how 10 SCI a bil memory pennanenlly 10 signal Slale "I" or ''0'' &1 Slartup. see figure 19.4. Parl-add",ssed dala bilS an: nOI pcnnissible as actual parameters in LAD and FBD. The reason for this is Ihat the Pro!;ram Editor transfers the signa I state of every binary actual operand to a temporary local dati. bi t prior 10 Ihe a"ual block call. For Ihi~ teuon. it is pos.iblc in LAD 1lIld run to initialize a binary block: input wilh a log;"; operation. Dunng copying before the block: call. the u~ignment oflhe dala block 10 thl; dala bil il los\. Even if you open the "correct" dala block in the proiIllm of the called block prior to aCCe8J;inll Ihe block parameler occupied by a partially addrcslcd data bil, only the previously created copy of the 'ignal Slate will be scanned. The same a""liel 10 binary in/oul paramet('TS and OUtpUI paramet('TS: here 100. asSignmelll with part-address! dala bil$ is nOl pennissible (the Progntm Editor will not reje meh an Msigl1lnenl bul in most cases ;1 will result in crrored functions).

When I.Ising part-addressed data operands at dillital parameters. you muSI note thaI when ~~e~ssing the block paramelers (ill the called block), Ihe currently opened dala block is al!:O Ihe "co""ct- data block. Sinu the Editor may in ccnatn cin:umstanus. lucb as during a block: call or if the block paramcll'I1I have previously bn acces.>ed, nOI visibly elumge the dala block:. the use of partially addressed digilal dala operandi is nOl recommended. Use only fully addressed dala operands for this rcason.

Temporary local data arc usually symbolically ncldress.:d. They are located in thc L Slackofthc calling block and arC declared ill the calling block.

1 '''''If -' ------'-"-'''"''"''--1-" -1 '--' 1f' --'


, (R

811

BilmX.y

flj;urr 19.J lniti.li,ation WI'"

F i~.d

Signal StOle

19.3 Aeroal P8lllOleler5 If the calling block i. a function hloc k, you can al r.o U.<e it' .ratie local data,,~ aeruall'arameters (see Chapter 19.4, Fvrwurd ing Block l'an'met"'l"S"'). Static data are u~Llally 5ymboli ~ $Il ~ addressed: if you would like to a~sign . 0solulc addrc%cs via Dl opernnd~. please note the informal ion in Cba~er IS .2.4. "SpeeiaJ 1'0;1115 In Data A~f08ing. W ith a block parameter of type BOO!., youean apply the constant TReE (signal state "1"') or FALSE (signal .tate "0"), Hnd with block p~mmcters of digita l data type, you can appl~ "Jl CVll.t~nlS corrcspondinS t<> th e data t~pe . Initiali/ation wil" eO""'tams ;~ r-errnis,ible onI~ for input I'arameters. You can also initialize a block parameter ofele mentary data type with compooenll< of arrays and 1\CU~tllICS if the componCltt IS of the same dat.a lype as the block parameler.
I nlt h.lbin{: block parRmctcr~ of complex data ty pe

I nlthll111nlil block parll.n,etu, of UHrdefine d dM la IYJK"" Por complex or eXlcn si~ c dalll SlruClnrcS. Ihe usc ofllscr. defined data types (UDT." i, I"ommended. First, you defi ne th e UDT and Ihen you u~ iI, for example, 10 generale the variable in Ihe datM block or to declnre the block parameter". You can \hen 0""' the variable when initial izmg the block parameter. Here. tOO, the actual pammeter (the variable) must be of tbe samc da!a type (the same as thc hlDek parameter.

VOn

A complete data block with the .ame UDT type as the bJocl:: parameter is nol pcrmis~iblc ., actuul parumeter.
Jnltlali~in\: block p anmctc" of type TlM"F:R, C OU:'<;T.E:R a Dd BLOCK_II

Every block parame ter can be of the evmp le.x type. Vari"b1cs of the .ame Iypc can be Il.'led as lelUIII OpCrands.

You mitiHli~e a block panmcICToftyPf' TIMER with Ii timer and a block parameler of type COUNTER wilh a counle r. You can apply only hlock~ without their own panlmetL"Il< Iv bluck. parameters <>f pammetu types I:JLOCK_f C und I3LOCKJR. You iniliulizc BLOC K_DB5 with a data block. Block paramctrnl oftypcs TIM ER. COUNTER and B LOCK_x~ must be input paramelers. Inltllilb.in2 block paramete" nf type POTNTER Pointers (constanls) and opr""o,ls arc p<:rmi .. i. ole ror block parameters of parameter type PONIT:R. The se pointeili are either rang~ pomters (32 -hil pointers) or DB pointe", (48-bit pomters). The opcnmch ;ore of dcmcnlary dalll type and can also be full~-.ddrcssed dat.a operands. Output parameteTh of type I'O INTER an: not permitted for func tion blud s.
InIlIDl1~lo"

For ini tiali7.inl: block parameters of type DT or STR ING, in dividual variable~ or eomponems OfBITII}'$ o r structures oflhe same data type arc
penni~sible.

STRING vari ab les can be of vuri"ble length. If you have ~l'ec if,ed the STRNG Icn','lh when deda ring an input or vUlpl:t pbrameler for II function block. the Editor rcserV(:5 the specified space in lhe instance data block; if you ha"e not ~pecifitd any length, 256 byles are resen-cd for Ihe STRIt'G variable. The ma.' timum length of the STRJ!'IG variable. wh ich you specifY in the d'Xlurution, mll,' be th~ same for the actual parumetcr and the rorm~ l parameter. Exception: Wilh Fe funclions . you spec ify eilher no length or the standard lenglh of 2~4 bytes when declnring a ST RING variable: h~re, yon can use ST RING variables of all kllgth~ lIS aemal pnrnmetel1i'. f or initializing block parameten of type J\.R.RAY or STRUc..'T, variable.'! wi!.b exactly tbe "",ne structure IlS the block parameters arc pemllSsibl e.

block

parameter~

of

typ~

ANY

Variable.' of all data types arc prnni,sible for block parametcn; ofpanuncll"T Iype ANY. The progmmrniog within the I;l<lk-d block detcrmines which variables (operanlh or data types) mo~t be applied to the block parameters, o r "hich variab les are feasible. You ca n alsu 'peeif;' B constant in the formal of the ANY poinler

1'Iobl< 19 .. PcnniMiblc Cmnb'""t'''''' wh= Forward,"lI Block l'acameI=


' . 11inr.:.'>' caned !Xcbral'o" t)'p< Inrut _ Input
Outpul > Outplll In/OUt _ Input In/oot _ Outpul In/Old _ lI'IIout
C
~Ic" ... _ y

,
, ,
,
,

Fe ,ails Fe
C

, ,.flJ enll. , ,
Fe

Fe caUs HI

, , , ,

, ,

, , , , ,

,
,

FB calli FR.

'-

<!au 'YP<'

, ,

, ,

, ,

.. ,

<.: - c.....,1....... ."...


1 ' - ~_'J'1><'o

TIMER,c:OU(H.R .... BU)"' ,," ""

"P#[data blocl<'}O!'eflmd Data!)-pe NWIlbcr" and thus define an absolute-addr..,;sed arCli.


O"lpUI parnmctcrs "rtype ANY an: nOIJl'"rmusible for funclion bloclcl<.

Block paramelers of puramctcr types T IMER. COUNTER and I3LOC t,Uu can only be pa.~s.ed on from one inpul p3ramel~r to aTlOlber if the calling bloc!.; is a runetion block. Thc:$C IUt ..ments an: represented In Table 19.4.

19.4 "Forwarding" Klock Parameters


"Forwarding" bloc!.; paramtle~ i. a 'p"dBI fonn of aC<:CSS and of initiuli.zi.og bloc.!r. p"mmeters. The bloc!.; paramet.. rs "fthe calling bloc!.; are "forwarded"10 Ihe paTllm~tcrs ofthc called bLock. The formal param~1~1: of the calling block then bccome~ the a~llIal panuneter oflhe ~ B Hed bloc!.;.

19.5 Examples
19.5. I Con "e yor Hell
F.l~ n' ple

The example shows tbe transfer of signal states

In general, il is also the case hel'<' thaI the actual parameter must be of the nme type a. the for mal paramet ~.,- (thai i~, Ihe relevant block parameters must agree in their dala type.). In addition, )'OIJ e~n apply an input parameter of the calling bloch only 10 an inpllt parameler <.>f the called block, I.tId simi larly. an on!pUI pamuleter 10 an nUlput p.a.ratncIC1'_ You can appl)' an h\l'out paramctcr of th~ calling block 10 Bil d~c1aration types of the called block _ There "re restrictio". with reg"rd to data type. caosed by the variations in the SlDrage ofbJod parameter for funct'ons and those for funclion block . Block parameters of elementary data type can be p>ss;;ed on without "-'<'tricrion in accordance with the ",formallon in the previoos puraamph. Input and output paramelers of~om' pl~" typc can only be foowarded if Ihe caiJillll block is a function block.

VII block. paniIIleten. For this porposc, w~ Il$C Ihe fiwction of ~ C<.lllve-)'or belt ~'01Itrol syslem described ill ChaptC1' ~ , "M~'Ttlory Funcrions The conveyor bdl control ~ystcm i, to be programm~,.j ill a (unction block. nnd all input s and OUlpUts are to be route<.! through block I'armnclers so th"t the function block C"tl be call ed repeatedly (for severa! conveyor bellS). Figurt! 19.5 .how, the input aod output param~lers for tile function block. as welluthc "w.tic and tern porary local data uSC(!,
R

Distriboting the parameters is quite <imple in this case: All binary operands tbat were inputs have become inpul parameter., all output, havc be<=ome output parameters. und all memory bils have become "atic IOCBI dut". Yo" will al50 hal'e noticed that Ihe names have ocen altered sliaht!y be<=alL.e only lenet!l. digi~, and Ihe un(!er$core Ilf~ permined for hlocl.:;.Iocal van_
ablc~

The function bloc!.; "Conveyor_Belt";$ 10 e<>ntml tv.o e<>n'-cyor belt!. f or this purpose, il will be cal1.-d Iwiee; Ihe 11rst time wilh the inpulS a~d OUlputs of conveyor belt I and the second

""

19.5

E xamp l~s

FB "Conveyor belt"

19 . 5.2 !'ar ts Co unte r :xa mp le


R ""dyIo.1od
R~ady_r ..." B~._mot

"=, ,=, = ,=, ,=, = =


'OQ eOQ

c.,.-,U oo"

~"

B8,,"_,t
,~

Man_oo

f=

BOOt.

En'U,oIt M fault
STAT
Lo ~ d

RornovQ EM_ R . m_ EM_Rem_P EM_ Lo.o_N EM_ Loo_P TEMP

PM_Rom_P PM L"" P
F I~u ,.., 1 9 . ~

,= ,=, ,=, ,=, " ,= ,=, ,=, ,=

The cxampk dcm01]Sltates the h andling of block parameters of ~I~mentary d ata type . ~ Parts Counter" cxample fmm C hapter 8, Counters", i.' the basis of Ihe func tion. The s ame function is implem~nted here a" a fun ctioll b lock, with all g loba l v ariab les declared cilher as bloc k pamm <:"',.,. ur as stal ic local dat a . T he lime,.,; and counters arc contro lled here v ia individual elem ents. Timers and COllit ... ,--s arC transferred via block paramet~" of type TIM"ER and CO UNTER . The se block parameters m ust Ix; input parameK.,-,;. The initial value, o f Ihc ,ounter (Qua,,'i!),) and the timer (Dural and Dura2) can alsu be trans ferred as block parameters; the data types of the block parameters correspon d here to those of the actual p arameters . The edge memory b its are stored in the stat ic i<x,d data and thc puhe memory h its are s tored in the t~mporary local data.

F Wlc, iun lJlocl< for 'he Convc'Yor Bolt Example'

tim e with those of conv~yor helt 2. For each call, the fu nction block require. an instance data block where it stores the data for the obta ining eonv~yor belt . The data block for conveyor belt 1 is to b e called "Beh Daml" and the d"ta block for convcyorbelt 2 is to be c"l1~d HcltD ata2"'. You cau find lbe cx~...: utcd programming ~xam pie in the library "LAD_ Book " Of "FBD_ Bool<" und~.,. the program "Conveyor Examp le -- that you can down load from the pub lisher's W~b,ite (see page l\). Tt shows the program ming of function block FH 21 w ith inpm paramNers, OUtplll parameters and static local dsts . You can use any data blocks a, instance b1<x ks: in the ex ample, OH 21 is used fur 'Hdt_ data j " and DB 22 fOT "Bdt_ datal', Tn Ihe Symbol Table, these data blocks have the data Iype of the funClion block ( F ]{ 21 in the example , if "Conveyor_beh" i.the _ymbol for FB 21). When you cal1 the func tion block, yuu ,an u8e the inputs an d outputs from (he Symbol Table as actual parameters . In lbo, ... casc, where these global symbols conlain sp~cial characten;, you must pla~ e th ........ ymlxl ls in q'lOtati<m marks m the program. Th e Symhnj Tahk i, dcsib'1lcd for all three examples in th is chapter (fable 19 .6 at the end of this chapter).

You can fi nd Ihe ,ample program in the li brary " LA])_ Huok-- or "FBD_ Book'" umk r the progmm 'Conveyor Example", lhat you c an download from the publishers Website (see p age l\) . It con tains fUD ctiou block FB 22 "Parts counter" and the as.oci at ed instancc J ",,, block

COUNT ER WORO T IM ER S 5TIM E S 5TIM E

,=, ,=, '" ,=, lbanier

FB"P "" Ac krK>w1


~m

=
= =

F.';"r..d
Fau ll -

Ou. n tlt~
,~ ~. ,

Ou",2

STAT EM_ LB_ P EM_lB_N EM_AC_ P EM ST P

,=, ,=,
,=, ,=,
ElOOl e OQ
,~

eoQ

T E MP PM_ l B_ P PM_ LB_ N ' _ BOOl t S5T IM E

S5T IME

FI>!UN 1\1.6

Function Hinck lor the Pwts CQuntor Exornplc

'"

19 Ulock Parameters ''CoumOal''. You can \1.: Ihe inputs. OUlpuU. limer and oounl~r from the Symbol Table (Table 19.6 in previous example) as actual panom<.'Tcrs ",hen calling the function block.

trol all ':O;1>"eyor belt, via B05,e31, Man 011

and SlQP.
The following program fQl" fUneli on block Feed' is de'igned in the same "" y. Thc input and outpUt parameter.; ot"the function block can be taken from Figure 19.7. I" addition. the dig. ila l valu~, fo r 'he pan . counter Q,umlil),. {)~r~' ~nd [J"ral are designed as input parameten hel"<' , We declare the data of the individual con veyor belt controls ami the data of the pans cOunter in t1J.e slatic local data in exactly the same way as for a user-delir>eo;!. data ~, i,e. wuh name and d3ta typ<". The variable Belt l~ is '0 receive the data .trucrure of funcllon block -COIl\"e)"or Bel:', as is variable "Belt2~, ~tc.; the ~ariable "Check~ 1"C<:eives the dala stroCIt.ll"<' ofth~ funetion block 'Pans_counter" .
The program ill the f\.ouction block ~Ians with the initialization of the ,;gn~ls common to all conveyor belts. Here, we make Ui~ of the flltt thu, the b lock parameters of the function bloch calle<.! as local ill~tarn;c. are stat ic loca\ data in the e um:nt block and can be lIeuted u sucb. b lock parameter M,m 'III in th. current funL1ion block controls ihe M~" on input paramcters of an four conveyor bel! controls with a singlc a"ignmenl. We proc:ectl in the :.ame way wim the SIgnals SlOp and Resel. And no,,- thc conveyor belt controls an initialized wi,h the COmmon .ignaI8. (You can, of ~"(>ursc. also jnirializ.:: These input pe.r&met<TS when the func,ion blOCK is c:alled.)

19.~ .J

Feed Example

The ~anw function' de, cribed in the twO previ, oui exnmpleli can al$o be called as local instarw;u. In our example. !hi. mccans tNt we pl"Ojr&m a f\.orw;tion block called "Feed' mat IS 10 control four conveyor belts and COUDT the con"e~ pans. In this function blod:, FB "Conveyor Belt" is called four times and FB PartS_ counter" is caLled once. The call doc, not take place in each ~ with ill> 0"'''' instance data block, bm 1m called FBs are 10 SIOK their data in the instanc<: data blockof~liQn block feed.

Fiaurc 19.7 shows how tbe individu"l conveyor belt controls al"<' interconnect ed (FB Pans counter' is not represented here). Thc start silO' n,,1 ;~ conn""tcd to the SW'I input of the con troller for belt I. the "'tidy_rem output i~ con nected to Ihe Sum input ofbeh 2. elc. Finally. the ready-"em output of belt " i~ conne<:led 10 the R~m(J'Ift OUlPU' of -Fced'. The same sianal sequence leads in the l"<'\'ersc direction from Remo>I over Conl/nue and Reodylood 10 Lond.
8(41_",(>/, L/)(,Irr and IMjauil a~ . epanne eon ~eyor btolt 5ignuls; R"5"', Stanup ao<l Slop con-

n'e

FUnclloo blo<:!< 'f...o""

!I.Ir.... ~1
L ~""1

-...
2"

19.5 Examp le.

Tahle 19.3 Declaratiun Section ofl'B 'Feed' '. p""lara}bme StOTt


R"",ovcd

-lion

M dre<.'
HOOL

tni',aJ
Val"" FALSE

. Comment
Stan co nveyor he l"
Part< have boon removeu truml>eh

...

." "
"

,.ill

BooL
D~L

,.
" " '.0
0.'

,.,

....

:;;'J

..
t

L. ".

\fan_'tart Stop
Re,et

BooL BOOL
COUNTER WORD
"]"l \l~. R

FAl.SE FALSE FALSE FALS F


W # I6#200

Stan C (mv~)'N belts manually Sl(}p ,',mveyor belt, Set control to the ba,ic ""ning
Count~r

Count Quantity Tim Dural Dura2


Lo ~d

lOr the part'

I 4 .0

.Numbc:Tofp~tt.

S5Tl/I.IE
S5TnfE

"

"'

S5Tlt5S
SH"IQS

10.0

Timer forthe monitor :'fo~ j torinii. ,jme fo r part. Monitoring time for gap
Load new parts 0010 helt

om
r: N~OUT I
STAT

Remove Bcltl Belt2 Belt 3


Bd!4

BOOL BooL
Conveyor_ be lt c.:m",:yot_bc lt CO!lveym bel t Conve yor belt
1' ...... counter

FAL SE fALSI::
14.0 20.0 26.0

Hemove parts from belt

32.0 3R.O

Check
TEMP

Control for belt I Control toe ~ It 2 Control for belt :l Control for bell 4 Contro l fo r counting and munilming

The sub,c'luent call, ufthc function blocks for eotwcyor b elt control contain on ly th~ block panomelcr~ rUT the in dividual signals tor each conveyor be lt and the connecti on to the bl ock param Clers of '"Feed'". Th e indiv idua l ,ignal~ are thc lighl barrioN, lhe commands for the belt motor and the motor faults . (We make use here of the fact tm t whl.-'Il" function block i" called. not al l block parameters have 10 be init ialized .) v,,'e program the connections between ~he individual belt conlro llers u,ing assigmnenls .

Thc fB "Pans c ou nter'" '" called a., a local 1n s\an~e even if it has no closer c onnection with the s igna ls of the conveyor belt controls. The inStaJ1CC dala block for '"Feed" stores the t'B data , The input raratnClCrs Quanli/y, Dura! and Dura) jor "I' e~d" nc<:d to be set only Ollce , Thi s can be done u.,ing detimlt values (as in the example) o r in the re smn routine in on 1()() (tor example, through d irect "",ignmenl if these three parameter> arC t.-cated as global data).

263

19 Block I'aramc{crs

I #Ma!-f__"-,________________________'_'~ '~Ma)"--oo_1 __
#Be~.Mall_on

IIBeltJ.M9

ItBel\4.Man_0Il

)--I

~of'---,--------------------------'-'~eltl ~
#Beltl.Stop

e - -e -L--_

- - --{)--I

- -- --{ )--I ,

#Be~3.S{OP

II'B@it4.S\op _ _ _ _ _ _--{, )--I

~ef~ :..-__,---------------'~'~'~'~"_{BaH ~'

f-_____________' '.~'~:,:Ba~ ~~ O f-______________~'~'~.~"~':,: .Ba~


L._ ___ _ ______ ___~ '~.~"~ '~ ',:B9H

1------1"

ItBel! !
Ro~dyload ~ #load

" ''" f--H----1 """

#Bel{ l(fl_'_'_"'_'_'________________________'__"~'

tH

;r;Belt2SU>rt

( )--I
tlgurc 19.8 Program for he<l example (LAO)
Con,jnued overleaf

19.5 I::.umpid

e"",/n"N:
IIB.1t2

.,"lMfa>lll2"

'"
End_belt Mfeu lt

'NO
ee~_mo l

FiK.. ..., I'.s


~m

for FC<."<i Example

"B'~_rnot7"

(LAD)

I1t8ett3(Qadyi<n<l

f-I- ' - - - -- -- --jl

"B~t2.ConIinufl
_3.Stool1

)--I

IjRIlady-rom f-I-"'--- - -- - - - i l )--I


.. eeN3
'N
.~.

'NO

"lMh"'~"

.,

""'-Mfault

'"emo<
- --

_ __ mol)"

l",eelt4te~dYload

f-I- - --

---<1

#8eH3 .ConUnU9

)--I

1'8.K4

"
Conbnue
End_bell Mfau lt

'NO
Rncl)"-,,,m
Bait_mol

r-'R~

"lbalY4"

"lMfaul14"

f--'

.."t.berrt"

~- ,

"

'"0

"',
lbolrri.,.

,,- rFeuN

"FlnItllacl"

~~

r-

' FauII""

""""" - ""'. """"'" ~

OtOu<e1 #Oura2 -

-- """"" """

M.lan~ .tar1

IIBNll .Man.-,)n

# Belt2.Man on

#8ek3.MaR_on

~.Man_on

IISiop

/l'8e1t1.Stop

#Belt2 .Stop

IlBeIt3.Stop

llBe1t4.Stop

#Reset

IiBen1 _ Bnlc_,t

#8eIt2.Ballc_11

.Bett3.BIoalc_u

ItBelt4 BIollc_u

/t6e ll t

"'Loom "
"/MfauIt1

""'"

"'"
----i

En<C~t

Rudyload Bell_mot

"-~,
~LmoW

MfauH

118e1t2_lWadyIoad

,
,
Exampl ~

1l'8e~ 1 .Conlinue

I I

1IB<IIt1.R&ady_rem

---1

IIB& rod2.Start

(FBD)

FIKIlI"e 19.9 Progn.ru for Fd


COlt''''~~ o ... ,,./~af

26'

#8 ..,t2 "/ M/au lt2"

"Lbarr2":=~;';";'~_;O:.:___':.:':'~m:oj~ 'Be~_mot2" t Mfault "


---1
#Be1t2. Conliflue

#Selt3 .R&adyload

80

# Selt3 "fMfault3"

"Lb",,3"
--1

E~d_b9~

Beicmot

Mfault

118..113. Continue
&

#aelt4 . Re~dytoad

#Band4.Start

#Removed "Lbarr4 " "fMlault4"

#B@ lt4 Ready rem Continue Belt_mot End_ belt Mla ult

#Remove
'a9~_mO t 4 '

#Start "Admowl" "Lba rrl" #c<>unt #QuanUty #TIm -

~~jset

"'~,

Ack~oV>1

Finl~hed -_ Fault

"Fin ished" "Fa un"

Lbarr\er Cou nt Quantity

#Dural -

Tim Dural

#Dura2- ': ',, -_ _ __ _--l " C


Co~II",,~d."

figure 19.9 Progt"Um for feed I::xomple (FBI))

'"

19 1llo<:k I'lonuneCen

T.bl~

111.6 Symbol

T.bl~

r..... lhe COI!,eyor tielt. PIU"1II COWlter ~nd F~ Example>

." "

conveyor
com.yor

" "

"j

"

, "

'"

Program (',"""cssing

Program Processing

This section of the book discusse s the various methods of program processing. The main program executes cycl ically. After each program pU>s, the CPU rerums 10 the beginning of tb" progr<tnl and e "ecUle, il aga in, Thi, is the "standard" method o f pro~e,sing PLC programs, Numcrou..> system functi()ns suppon the utiliza tion of ~yst~m gervices, such as conlroliing the rcal_ lime clock or commun ication via bus sy,,lems. In COntra,! to the static se!lings made when parame lcri/jng the CPU, system fun~ tions ~an be used dyn amical ly at program run nnw. The main program can he temporari ly 5U<_ rended t() ali()w interrupt .crvicin g . The vari om Iypcs ()f imcrn'pts (time-of-day imenupts, time-delay intctnlpts, watchd[)g interrupts, hardw"re interrupts, DPV I interrupt', "ynd1T()n OU8 cycle interrupts. muh;pro~c~sor ;mcrrupt) are di vided into priority classes who<~ processing priority you may yourself, to a large d egree , J~termine. Interrupt servicing allow s you to react qu ickly to .ignal, trom the controll e d pro_ cess or implement periodic control procedur~ , ind~pendently of the process ing time o f the nla,n program, Before starting the main program, Ih c CPU ini tiates a stllrt- up pro;:ram in wh ich you can make ,pcc ifkalions n:garJing progmm PNccssing, detjne default values fo r variah lc s, or parameterize modules, .Error handling is also part of pro1,'tam p ro_ ce,sing. STEP 7 distinguishes between synchro'J<)Us errors, which occur during prlXcs>ing of a statement , and asynchrouous errors, which can b e dc\cctcd independently of program proc~s"ing . In both cascs you ~an adapt th~ error routine to ,uit your needs

20

.\-hln pro;:rllm Program "tructure; scan cycle contr()l; respon>e ti m~: program functio"",: mu!!i computing ope ration; data cxch&ngc with system fun~tions: start information Interrupt handUng

2t

Time -of_day interrupB; rime-Jeta)' ;tHerrupl,; watchdog interrupt': hardware interrupt>;: DPVI interrupts; multiprO'-'cssor int<-"rrUpt; "ynchronous cycle intcrn 'pts; h andling interrupt c"~nL' 22 Stut -up characteristics Power-up, mcmory rcscl, retemi v ity; cold re,la!1 ; warm l'e<turt; ascena;n module "ddr~s", parameterize mod !!les Error handlin;: Sy nchronous errors (programming ~rro"_ acces, errors); handling synchronous elTor evems: asyn~hronous ~rror'; sysl<-'1ll Jiagnwtics

23

'"

20 Main Propm

20 Main Program

The mnin program i. Ihe cyclically scanned UK!" prol,:ram; cydic ,canninll is the "nonnal" way in w!>ieh programs exCCUlC in progrnnuna1>Ie logic ~ontrollcrs. The large majority of eOnINI sy~tcm' u.<c only Ihis form of program ex~ cut ion. If eveUl-driven prog.nun ""anniD. i~ used. it i$ in must C<lSCIl only in addilion to the
main pT'Ognirn.
Th~ mll;n prol,:no.m is invoked in Of1j:ani;alion hlock 00 I. It ..xc:cUles al {he IU"'esl pnorily level, und elIn be interrupted by aU olh~ IYPO;:' uf program processing. Thc user program u executed in RUN mode. which is sci usinlo1lhc mode seleclor on the CPU', front pane\. With a 1<.>lUIlc .wilch as mode selector, the position i. II. UN, wilh a kcy_operat.-d .wi t~h , the positions are RUN and RUN -P. When in Ihe RUN-I' position. Ihe CPU ean be programmed via a programming device. In Ih .. RUN po~ilion. you can "'IOOVe the key ,;0 thaI 00 One can chanae the OJl'C'3ting mode w;lhout prop<.T nuthonzsllon; when me mode .eleclor is at RUN. proll"'JIl$ can only be read.

uocr p.ograIl1S). And finally, bUI not lacking in imj\OTlanee. (lividing the prolP'am .implifies both debugging and service Dnd malnlennn~e

The .trucruring oflhe 1,lS~1' program de~nds on il8 si/c and its function. A dislin~"\iOll is made betwe ..n th.-..c different ""mcthods":

In a Unear progra m, Ihc eudn: mam program i. in organirdlloD block OH I. Each eutTem
patb is in a S(Cpa1llle DeNo'Ork. S11'P 1 numbers the nL'!works in sequrnL~. When editing nod debuggmg. you can refe~nee e~cry nctwOTt.: dircclly by ils number. A pani tioncd progr'im is basically n linen r pTOIr"'im which is divided into blocks, R~"sons for di\idin g me program mij;hl b~ b<:e~u>c it is too long for organizalion block 011 I ()T bccaLloc }OU ",anI 10 mak.. il mon' relldable. The blocks are then called in .equence. You Clltl ~ISQ Ilividc the program in anmher block lhe same way you ",ould Ihe program in organi.tatiuu block OB I. This rn.-rhod allowl yuu 10 call associaled process-relaled functions rOt procesling from within OOe and the same blod. The a,dvanl8aC of this program siruciure is tftal, e'en though lht: program is lin...r. yoo can sfill debug and run il in sections (.imply by omitting o r adding block calls). A Slruclnred p~ullnm is u!\Cd when Ihe concepn," l fo rmulation is particularly extensive , ". hen yuu want 10 ,eu~e projp'Ulll fun~tiuru;, or when complex problems must be soh cd. StrucTUring means dividing the program into S~Clions (blocks) which embody self-contained funeI;on< 0.- sen e a specific funCI;on.1 purpo5C IItld ....bich e"'change thc fewe.ot po$sible numbcr of sipls with other blocJts. Assia,nlllg each program s..-crion a specific (proeHI-relaled) fuDC_ I;on '" ill l'f'Oduce easily r<:.w..blc bloc""" ",ilil simple int.. rfaccs to ,,!her blocb ...hen projp'UTDmcd. The LAD and run prugranuntng language. support strucrured programming through fun~_

20,1 I'ro&:rllm Organization

20.1.1 Pru\:rJlm Structure


To nnalyze n co mplex automation task mClm" tu divide Ih~t task into s!IL~lIer tasks or functi(ln~ in accurdancc wilh Ihe SlnICtun: of the process In be controlled. You Ihen defin" Ifte individual luks resulling from lills dividing procCSS by oclcnnining the functions and .tipulal1ng the interface 5ignal~ to Ihe process or 10 other msb. This brnkdown into individual I"".." can be don" in your program. In this way. Ihe <InICtll": of your pn~ corresponds to the di",slon of the automalion Ia.k.

A divided uocrpmgratn can be more easily configured. and cnn be programmed in Sl:Clion. (even by ."v"nll people in the case of very larac

n,

20.1 Pl"oiJ1lll1 Organization tions with wbkh you clln C~~tC "blo<:ks" (selfcontained program sections). Chapter 3.2. " l3Ioc k, '" dise u~scs the diffc~ nt kinds of blocks lind their uses . You will find a detailed description of the functions for calling and ending block!! in Chapter 18, "Rlock Functions". The blocks ~ceive the signal$ and data to be pl"OC(:~scd via the call interface ( the block parametcn). and forward the ~sulu over this !I-/Imc imerface. The optioll5 for passing panlmetCT9 are d escribed in detail in Clu>p1eT 19, "Illock Parameters". The following poinl~ of discussion can g ive only a rouih. very general view with the intention of g iving th e beginner :IOniC idea. on pmgram ~tructuring and on trRllslntin g his control task inlO reality. Advanced prognllnmen; nor_ mally have sufficient e>;~rien~ 10 organize a prolP"llm to suit the special con trollllSk a l hand.
A p I'OCH """"'lItcd PrDira m . t r uclure closely roll",,'s the muclUre of the plant 10 be controlled. The individual program se-clio ns COtTespond to the individual pans of Ihe plant o r o f the process to be controlled. Subo rd inate 10 thi s TOugh structure are Ihe scan ni ng of tbe limit sw itches and operator pancl ~ and Ihe co ntrol of the actuators and display device. (in different pans of the plant). Bit memo!), o r global data

20. 1.2 Progra m OrgnnlZlll o o


Program organizat ion det~-nnin~i whetber and in what ordcr the CPU will process Ihe blocks whkh you have generated. To organi= your prognun, you program block calls in tbe de.ired sequence in the sUPraQrdin~te blocks. You $hould cbo~ the order in wbich the bloch are c a Uw SO th at it milTOrs the process related Or funclion.re la ted division of the conn olled plant. Ne5llnk de plh The maximum depth applies for I priority class (fot the progrom in an orvanizalion block), and is CPU-dependent. On the CPU 314. for exam_ ple, the nesting d eplh is eig ht. that is. beginning with one organizat ion block (nesting depth I). you ca n add seven mOre bloc:ks in Ihe "horizonlal" ,li""'lio n (Ihis i . ca !l ~d nesli,tg). If more blocks are cal led . the CPU itleS to STOP with a " Block overflow" ClTOr. Do not forgel to include ~yslcm function block (SFR) calls aud system funclion (S FC) calls when calculating the IlC'Sling deplb. A data bl<xk ca ll. which is IIClWIlly only the nJ>C"ill.i or se lecting o f a dala area. has no effect on Ihe nesting deptb of blocks. nor is the nesting depth affected by callin g $Cveral bloc ks in success ion (linear block calls).
PU Cllee-r dliled p r Oil r anl Or i anlzAllon

"" ,
Intertocl<3 Ben control 1
Belt control 2
Oeta
acq u i s~ion

PI'OCfIU

Oata procnslng

Conveyor data
0.18 preparation

Communication

In o\"ianization block 08 I. you should caU the bloc"" in the main program in such a way as to roughly organize your PTOiT"'"- A program can ~ Ol"llanizcd on either a process-relatw Or funCl ion~late d ba.i .

CONTROl
Fill" .... 10 . 1
E~~mple

of PTOgnr.m Structuring

271

20 Main Program

are llsed for signal interchange between different parts of the p laJlt. I)rogram .tr uctul~ is based on the control function to be cxecuted. Init ially, this method of program strucroring docs not take the contL"Ollcd plant into account at all. The plant s(rueture firsl be~omes apparent in \h~ Sllbordinate bloch when the control function defined by the rough strucro", is divided nmher.
A
function-,..,I at~d

2{}.2 Scan Cycle Control


20.2.1 Proces. Im uge Updatinj!
The proce.s image is part ufmc CPU's intcrnal system memory (Chapter 1 1.6, "CPU Memory Areas'). It b~gins at 110 address 0 and end, at an upp~r limit slipulated by the CPU. On appropriately equipped CPUs. you can define this limit yourself. Nurm ally, all d igital modules lie in the process image addrc.s area, while all analog moollies have addresse, uuu;idc this mea. If the CPU has fre~ address allocation, you can lise !h~ configuration tabl~ to dircc! any mo d"le uvcr (be process image or ad~" it o utsidc the process imagc arCa . The proce." image ~omi'ts of the proces.inlllge input table (input, J) ~nd the pc<)C~s, imagc OU'PU\ table (outputs Q). After CP U re,tart and prior tu thc first execution ofOI:! I , the operating systcm transfers tbe sil,,"nal statcs of the process-image output table Ie) the output morluks and accepts the s ignal slates of the input modules into the proccssimagc input table. This is followed by execulion of OB 1 where n omlally the inputs ar<: combined with each othet and lh~ output. ar~ enutrolled. Fol lowing termination of OB I, a new cycl~ begins with the updating of tbe proce ss image (Figure 20.2).

In practice. a hybrid of these two concepts is nonnally u,ed. Figure 20. 1 sh",,,-s an example: A functional stmct"re is mirrored in the operat ing mode pTOb"am and in the data processing program which goes above and beyond the plant itself. Program sectioilll Feeding Conveyor I, F~~ding Conveyor 2. Pwcess and Discharging Conveyor are process-related .
exampk al'" shows the use of difTerent types of bloch. The main pTOgram is in OB I : it is in this progr~m (ha( (he b locb for the op erating moo~" the variou, pi<""C cs of plant ~q"ip meot, and for dala processing are called. These blocb are funelion blocks with an instance dmu block"" data SlOre. F.,~ding Coov~yor I and Feeding Conveyor 2 a.-c identically structured: FB 20, with DB 20 as ins' ancc dum block for Fec<.ling Conveyor 1 and with DB 21 as instance data. block tor Fe..ding Conv~yor 2. IS used tor con!rol. In 'he conveyor eonrrol pwgrdm. finlction FC 20 processe, th e interlocks; it scan:; inputs or memory bits a nd controls FB 20's local da!a. FWlction block FB 101 ~ontains the control progr....n for a ~onvcyor bclt, and i, called once for each belt. The call is a local jnstan~e"u (hal its local data are in instance data b lock DB 20 Thc same applies for the data acquis ition program in FB 29. The data processing program in FB 50, which USC" OR 50, proce>ses the data acquired ", ilh FR 29 (and otber blocks). which are located in globa l data block DB 60. fUllction FC 51 pre pares these data forlrans[er. Th~ lransfer is controlled by HI 51 (with DB 51 ), in whid, system blocks SFB ~. SFB 9 and SFB 62 arc called Here, too, the SFB, sav~ their instance data in "s"pllloTdinate" data hlod: DB 51 .
Th~

If an error occur,; during autommic Updating of the process image, e.g. bccau,~" mooule is no longer access ible. organi,,'diun bl(Jd OB l!5 "Program E,,~cution Errors" is called. IfOB 85 i. nO! anilable, thc CPU gocs to STar.
Subp r uc""
imag~s

With appropriately equipped CPU" you can d ivi de the process imagc into up to 30 subprocess images . You make this divi,iOIl during par."mcl~rization of the signal modllies by def,nin g [h~ subprocess image via which the modul~ i, to be addressed whe n you ""igo nddresse,. You can scparm e the division accoTdmg to process-image input table and proces;;-image OUlpul table. All module s that you do nO! assib'Il tu one of lhe subpro~c," image s I to 30 are stored in subprocess image 0, '" hich i, also called the OB I pro-

20.2 Scan Cycle Control

Order of execulic", 10r CPUa up to stllrt of deU"al1l'011998 Start current cyct ic execution Cur ....nt c c ia time 08 1 Start nexl cycl ic e~ecul i on

...

...

'"
Start currMI cyclic execution

Ma in ;>rogram 08 ,

...

"0

'"
Start next eyel ic execu~on

Main prog ram 08 1

...

?
.

Order of execution for CPU, from stllrt of delive ry 10/1998

Current cycl e time 08 1

PIO

I PII

...
Main progra m 08 1

...

P IO

I PII

Ma in program 08 1

... ...

Order of exaculfon for Inte rrupt organization blocks with subprocess.lmege Start internJpt handling Runtim e of the interru End Interrupt hand ling anlzetlon blcck

..
inpu' 'aM.

,,,

m
NO
SPIt"
Sf'lU"

proc<Mr,"a~e

or ,,,PP""C'J,.i,,,,,1P' 0

...
SPtln Interrupt organ izat ion block

pm'mage ""'P<" ",bl. or ,"bp""'." . (ma1<" a Subp""""'.im"!(e" ihpullabl. Sub nxe' i"",K' n ",,'pur ,"ble

...

SP IOn

Figure 20.2 updating Ille Proc".. Image

cess image (OB I_PI) . This subproce .. image 0 is updatcd a"tomalicaUy by the operating sy, tern of the CPU as pan o f cyclic execution . You can al>o program the CPU sllch that the auto mmic updating is switched off. With appropriately eq"ipped CPUs, you can also assign the subprocess images to the inter nlpt org anization blocks so that they are auto matically updated when th ese O Rs are callee!. The system functions SFC 26 UPDAT_PI and SFC 21 UPDAT _PO are ava ilabl e for updating the subprocess images by the uScr program. In th e o rganization blocks for sync hronons cycle interrupt, you usc the sy<lem functions SFC 126 SYNC_PI and SFC 127 SYNC_PO (Chap ter 21 .8.2, "lsochrone Upd ating Of Process Image") .

SFC 26 UPDA"f_PI SFC 21 UPDAT_PO The system func tion SfC 26 UPDAT_Pl updates a subprocess image of the inputs , the system funct ion SFC 27 UPDAT_PO updates a subpro~css image of the o utp uts. Table 20.1 shows the parameters of these SFCs. You can also update subprocess image 0 wilh these SFes. You can carry out updating of individual subprocess images by call ing these SFCs ," any time and at any loc ation. For example, you can define a subp rocess image for a priority cl ass (a program execution level) and you can then cauS e this subprocess image to be updated at the Slan and al the end of the relevant organ iza tion hlock when 'his priori ty clas< is processed. Up<lating o f a process image can be interrupted by calling a higher priority class . If an elTor

27.1

20 Main Program <>ccu r,; during up<iatitlg of a proc ~", image. c ,g. i:>ccau,e ~ module c~n no longer b e ac~~,>ed. this error is reponed yia th e flu"'tion value of The src. The parameTerized minimum cycle dumlion and th e s~an ~yd~ monitming tim~ aTe also d i, pbycd . The cycle { ; m~ for the la't cyde and the mi nimum and max imum cycl e time since (h~ PLC was la,t Slane<! up can also be read in T e h t~mporary local data in the .Iart informarion ofOB 1.

ZU.2.2 Scan Cyc le Monitorin!: Time I'rogram scanning in orgatlization block O B I i ~ monitor~d by the so-calle d "scan cycle mOIliTor" or "scan cycle w"l~hdog:". The default value for The scan cycle mon itoring time i, I SO ms . You can change \hi s valu~ in the rang~ from 1 ms 10 6 , by parameterizing the CPU ac~ord ingly.

StT.tJ R f:_TR TGR


Resta r ting rh e sca n cycle m Olli toring time An SFC 4 3 RE_ TR1GR SYSTem fundion call restarts the Scan cycle monitoring lime; the rimer "" tart, with The new value ,ct via C PU p~mrn;:tcriz~tion. SFC 43 has n o parame ters. Operating <y.te m run Umes The >can cycle Time al~o includ~s the operatin g sy slem nrn lime" Th~"e are eomp<Js~d of the following:
(>

if th e mai n program takes IOllger to scan than \bc specified scan ~yde monitoring time. {he CPU calls OS 80 ("Timing error"). If OB 80 has no\ lx:cn programmcd, the CPU g<><s 10 STOP.
The sc:!n cyc le monitoring lime indudes the full scan Time for OB 1. Tt also inc! ",\es the scan times for high~r priority classes which imenupT the m~ill program (in the eun-em cycle). Communication p roce"e, ~arricd oUt by the opcr~t ing 'ystem. su~h as GO communication o r PG acces s to the CPU (block 'talU"), also increa,e the runtim~ of the main program. The increa"~ can be rcdueed ill part b y the way you paramcteri~ the CPU ("Cyclic load from commllni cs tiou " on the "Cycle1Clock m~ m""Y bits" Tab)

Sy'tcm control of ~y~lic cycle- ). fi~ed vaJLLe

s~"nning

("no_load

(>

UpdaTing o f the proces, image; depend~'Jl t OIl (h~ number o f byres to])., updatcd Updal ing of the tim~'fS; dc!)<'ndent on the number of Ti mers To be updaTed Communications load

(>

>

Cyd .. statistics If you have aD online connection from" programming dev ic e to an operating CPU. >d~e( PLC ---c> JI,10DIILE lN FORMATIO~ {o call IIp a d ia log box thm contain, " ~' nal tabs . The "Cycle Time" tab ,how , the current cycle T im~. as well as the >ilioncsT and longest cycl~ Time .

Conunurncatiolls functiolls for the CPU include tbe tran, f~.,- of ",cr progmm blocks or daTa c x ~ h an g e betwee n CPU modlllc s u s ing system fu nCTions , The T ime the CPU is to use for Tbesc funCTions can be limi1ed by paramelen z in g the CPU. A ll \alueS a t operating 'yS{~ 'IIl runllme pTOperties ofIhe re levant CPU.
"Ie

T:tblc 20 t PART
RCT
V~

Para mct~ .,.

[OT the SFC, rOT ?roc" l.J.na~e Upd:>,ing


De.:!aration
D.", TYl><
C"tlte~"",

h"'-TJ'tSt.cr_'<""""

5)FC

FLADDR

" " " n n " I

INPUT

BYTE
<NT WOR!)

RETURN OUTPUT

n . ""Tiplion ~u mber of the ,ubp",)..-"" image (0 to 15) Eaur infOTTTllitiun On an ac,ess error: Tbe adc!ress of tho firS t
hyte to ca",. the e<ror

20.2 Scan Cycle Control

20.2.3 ).flnlruum Scan Cyd., Time, Back_

ground Scanning
\V,th a ppropriate ly equ ipped CP Lls . yo,", may s pecify a minimum scan cyd e time _ Tf lhe main program (inc!",jing interrupts) lak es less time. the CPU waits unt il the spec itied mi nimum scan cycle tirn~ has elapsed h efore be ginning the next cycle by recalling OS I . dcfaOlIt va luc fot th~ minimum _,can cycle time is 0 ms, th at is to ~ay, th~ function is disabled, You can set a m in imum S~an cycle tim~ of fro m I ms to 6 s in "Cy~lci Cl"",k m~mory bits" tah whe n you parame teri z e the CP U . Background . canuin g OR 90 In the int~rva! between the actual e nd o f the cycle and expiration o f the minimum cycle time, the CP U executes organ ization b loc k DB 90 "Backgro und scanning" (Figure 20 .3) _ on 90 is cxttuted " in ,li~c ," , \Vben the ope rating system c alls OR I , cxc~U1ionof OB 90 i, interrupted : it is Then resum ed at the poilll of inlerruption when OB I has lerrnin" ted , OB 90 can be int<-rrupted after each statemenl, any sy ,\~m
Th~

block ca lled in OR 90 , however, is first scanned in it s entirety. The length of a " slice" depends on the ~urrenT scan cycle ti me o f OR I. The closer O B I 's scan time is to the m inimum sc an cycle T ime . the less tim<- remains fo r e"eCUTing OB ~o , The program scan time is not monitored in OB 90. O B 90 is seanned only in RUN modc. It c an be interrupted b y interrupt and error event" just li k e OB L The stan i"fonn at;on ;n the temporary local dam (Byte I) a lso tell. whi~h even ts call,e OB 90 to e"ecute from the beginning:
[>

8 #1 6# 91 A fter a Cl'U restart:


B# 16#92 After a h lock procc,",cd in OB 9 0 wa" deleted or re placed: B #1 6#93 After ( re)loading ofOB 90 in RU"l mode :

I>

"
[>

B#1 6#9 5
After Ihe program in OB 90 "'a" scanned and a n e w b,,~kground ~yd e begins.

Orde r of execution for CPUs up to start of d ..!ivery 1011998


Start current cyc lic exe cution

,
Start next

"i',

Curren t cycle time OB 1

Contin uation of execution in 08 90

cycl ic execution

'"

Main prO>jram OB 1

... ...

"0

Backg round OS 90

Minimum sc"n cycl. tim ..

'"
,'.'.

0"'

Order of """cution fo r CPUs from start of de livery 1011998


Start current cyclic execution

,
Start next cyclic execution

.:,;..,:;,';:';::,:

Current c cletlme OB 1

Contin ua tion of execution in OB 90

PIO

! PH

Ma in program 08 1

... ...

Ba ckground OB 90 Min Imu m scan cycle tIme

P IO

I Pit

08 1

_ igure ! O,3 M in imu m Cycle Du"'ti"n and Baciq;round Sconning F

275

20 Main Program wg of ltllerrupt<, th e fu nction, cHrried out by the operating system, such a, updating ti rn ~rs. controlling the i\ 1PI intaf,,~~ and updating the p=e<. image<)

20.2.4 Response TIme


Ifthe user program in 013 I work:; with signa l states of the process "nsg~<, thi, result. in a response time which i" ,kpend<.'l1t on \he program cxeclllioll limc (. can cyck tim e). Th e response time lies oc tween one and t\VO scan cycles , "" Ih,' f()ilowing exrunple explains, When a limit switch is activated, Cor ins\al1 ce, il changes its ,jgn~ 1 <late from "0" to " I". The programmable controller detects this chanl;c duri,,!> {he subsequen t updating o rt hc process unage . and scb tbe inputs allocated to the limit switch to "\" . The progrrun evaluates 1bi:; change by resetting an output, for example, in Oro"T 10 switch off the co=sponding motor. The new signal "t,,{~ o[mc OUtpUI mal ,,-as r<:set is trmllif~'TTed ~l the end of 1he program ,can; only lhC11 is the corrcspondinl; bit resel 011 the ,hgital output mn<.luk. III H bc,\-c~se ,iIDation., me prOl:ess imagc " updat,,,l immediately following the cbange in thc limit switch', . igl1,,1 (F igure 20A). Tt would thcn take only onc cycle for the ~Ievan! output to respond. In the worst-case simmion., updatin g of the process image was JUSt completed whell the limit switch signal changed. Tt would then be ncccs,ary to wait approximately OIle cyclc for the pro!lflill1lllabk " untroller to d"tect the <ignal chanl;~ and SCI th e input. A fler yet another cycle, tbe program can respond. When so con"i dered., the u ,cr progr3m', c.,~ec ,, tiulJ lime contain" :on pT<J,edl.l"" in one program cycle (including. for instance. the servic -

we

The n:,pon,c time 1-0 a change in an inpm signal can thu, be hem'een o~e and two cycles . Added to the respo".e ti me ar<: the delays fo r the input modules, 1he ,w itch ing times OfCOn!3CWN, and
.0011 .

Tn wme instances. you can reduce the re'pon,~ lime , by addre>Sllg the liO, dire~tl)' or calling program sections on an event-driven basis (proces s imerrul>l) You C3n 3chieve uniform response lim~S or equal time imen'als for the prnces, control if a program c<Jmp<Ju~nt is always process~d a' the ,aJ11C time interval, c.g . .., ~yclic inkrrupl rrogram, Program processing i,ochronous w ith t he pn,,;cs,ing ~ydc <Jf a PROFIBUS DP mB.<1er sy,tcm als() rroduce~ calculable r~.po"se time, (Charter 21.8. "Synchronom Cycle II11"TrupIS"),

20.2.,5 Start Tnfor n'at;on


The CP U ', operatir::g system fo!Wards otaT! infonna,ion t<J <Jrganiz..,tion bl<.>ek OB 1, as it ,joe, to c,'cry organization block, in the first 20 byt ~s of tempormy local data. You C3n I;~ncra te the declaration for the stall infom1at ioD your, elf <Jr you Can ,IS" informmion from Swndard Library undC1' O"g'mi~"tio" Blocks.

Sensor signal chllnge with immed iato t f~nsf ~r to process-Image

... O utput sign" t Mango

Response time _ one eye t.

Ipl, o

'"

User progra m Sensor sijon,,1 chang~ without transf" , to prQc~~s~mag o

---

-- -

I ,>0

'"
Transfar to proce ss-tmage

User P"'llram O UlpU!

. --

. --

I PIO
si gn~ t chan~e

'"

Ruponu 11m.. _ Iwo cyclu

20.2 Sc.n Cycle Conlrol

Tallie 20.1 Sum Information for tile OR


.j

!l

~~

1:I=16i!'03 B# 160f()4 -

En!)' OIMT cy<:1e

ht cyde afler cold

Table 20.2 shows this stan in fon"at; on for the OBI , the default symbolic designa tion. and the dala types. You can change the d~"S igoalioD at any time Illld choose names mo: acceptable to you. Evo:n iryou don't u.<e the stan informanon, )'l.lu mU$I reserve the finn 20 bytes of tcmporery Incal data for 'h is ptIrpose (for InSIance in the form Of a 20--byte IIrray).
In SI MAl"lC 57, all CVet" mc.~sages have" fiXed ,tNcture whi~h is spedficd by the eVent clas~. The start information r"r OEl I , for instance. reports event [litl 6# II a$ a standard OB call . from tbe contents ofthe nexI b}1e you can tell ..... helher the main prognlm is in the first cycle after power-up and is therefore calling. for instance. initialization routines in the ~ydie prolt'"R"'. The priority and 08 numher of the main progmm are fixed. \Vith three INT va lues. the stan infonnotion provides inf"rmation un the cycle time orthe last scan cycle and on the minimum and maximum cycle timC!; since the]a" powerup. The llUl ~"lIlue . in DATEj\l'\D_TIME formill. indicates who:n !he prionty control program re<;ci~"Cd the event for callmg o n I.

0lJj:ani7..ation block because thut information consists of temporary local data. If you require the stan infonnation in blocks which lie o n deeper levels. call sy"em function S FC RD_ ST?-."FO at the rel~t localion in Ihe program . S f C Ii RD.SL'I FO Rudlnlol (Jut start Informatlnn Syste m fun~tion SFC 6 Rn.S INFO makes th e ~ta" information on (he cu~nt organization block (that is, the 08 at the top ufthc cal! lIce) and on the stan-up 013 lUI executed available to you eV"" al a deeper call1e,"el (T'ablc 20.3). Output parameter TOP.51 containi 1M first 12 b>1e;; of stan information on the cu rrent OB, OUtpUt parnmeter START. UP. S I tbe first 12 bytei of stan information nn the llUl Start -up 013 executed. There is no time ~t .. mp in either case. SFC 6 RD. SlI\rO can nnt on ly be called at any location in the main program but ;n every prin,ity class. even in an errOr organization bl ock or in the Start_up roUlin~ . If the 5 FC is called in ~n intL'lTUpl organization block, for example, TOP.Sl contains the start information of the interrupt OB. In the ca~ of .. call at ",start, TOP. 51 and START.UP_ SI have the same contents.

Nnle thai direct ",ading of the start in fOTmanon for an organization block is polS;ble only in that

20 Main Program Table 20.3 Paramctcni for SFC 6 RD SFC

S l~'FO

Parameter Name

RET VAL TOP_S l START UP ,EV_CLASS ,EV_NUM ,PRIORJTY ,NU>.1 _ TYP2 J .TY PI .Zl l _ li2 3

Decl ....ation RETURN OUTPUT


OUTPUT

D.ta Type
INT

Con!eDts. Dc,;criptioD F.:mr infonnatinn Slart information for the CurrOn! DB ("'ilh the same strucNre os START UP ") S"'rt information for tho last OB started, E"ent ID and ''''~ nt clao< Even' Dumo.r E~ocution priority (number of tho <"""mion leve l) OB number !D o[sllw1emem.ry information 2_3 lD o[sllpplemem.ry infurmation I Supplementary information I Suppl~m.ntary information 2

STRUCT
STRUCT BYTE

"

om
" '

m,

,m
WORD DWORD

BYTE

20.3 Program Functions


In addition to pammeterizing the CPU with the Hardware Conliguration, y(}U can al50 select a number of program functions dynamicaUy at runtime via the integrated system functions,
2[1.3 .1 Time of day

Sett ing a nd readin g the t ime of day Calling the SFC 0 SET_ClK or the SFC 100 SET_ClKS us ing MODE = B#I6#OI or B#16I>03 set the clock to the va lue defined by the PDT parameter_ SFC 0 SET_ClK set. th~ win ter time for CPUs with summer/winter time idemification. With the 5FC 100 SET_Cl KS, you can use the SUMMER Ilarameter 1 define 0 whether the time is the winter time (with " 0") or the summer time (with " I "). The current lime is r~ad by SFC I READ_CLK and output in the CDT parameter. The time has the format DATE_AND_TLVlE when sellin g and reading, i.e , therefore contains the date an d lime, Modul. time. toca l time The time present On the CPU is the module time. This is decisive for all timcd processes which control the CPU, such as run_li me mctcrs. suming of time_of_day interrupts or cntering of lime stamps in the diagnosli ~s buffer and OB start information, You Can set and read the module time using the system functions for the CPU clock. CQrrespondingly desi gned CPUs addilionally save a "time Slatus. This contains a correclion value which reslll" in the local time wben added to the module time. The correction value is set in interval s of 30 minutes, and can also be negative (CORR pammetcr of SFC 100 5 ET_ CLKS) , The loca l tim .. can be used to display time zone,.

Each SIMATIC CPU has a clock which you can sct and scan u.ing STEP 7 or syst~m functions _ The timc of day is rcpresented in the u'~r program in the format DAfE_At'-' D_T1:vIE. consisting of the dat~ . time and day of week. Newer CPUs witb firmware version 3 and higher allio havc thc time status_ You can then additional ly set a di fference from a time zone a, ",'ell as .ummer/winter time identification_ The following system functions Can be used to access the CP U clock:
t>

SFC 0 SET_ClK Set datc and time SFC I READ_CLK Read datc and time SFC 48 SNC RTCB Synchronize CPU clocks SfC 100 SET_CL KS Set time of day, date and time status

t>

"
t>

Vou will find a list of 'ystem function parame_ ters in Table 20 ,4.

20.3 f'Togram

~Unclion.

Tabl.20.4 Si'C Parameter:. fm

tb~

CPU Clock Dan'l)'p


Conte~l6. D_r;l>lio~

SFC

Parmnet:::r N_c

Declamtion

" ,
" W"

mT
m
V~

m,UT
RETURN REnrRN OUTPUT RETURN INPUT

DT
mY

Date a"d time ("ew)


Error lnfo!"Illation

ROT VAC

TNT

CDT
RET V~ MODE

Of
INT

Error information Date and lime (curre nt) Error informa1ion


Operatin~ rnoo~

BYTE

1l# 16i'03: Set time and lime .tarns

B" 16;;02 Only ,et time ""'n'

fI# 1Mit)): Only set time

POT
CORR

iNPUI L"IPUT INPUT I!-.PUT

OT
L"T
llOOI.

S UMMt:1I. ANN_

ilOOL

RET

V~

RETURN

'NT

Dc tim'd t;mo Differe nc e f,om ba<;e time in O.5-hour inter "ah from -24 to +26 Summerlwint.r time id.nt;fjc~tio" CI" - s um mer tirn~) Announcement of time ,witchover: a " 1" indic"'e' that" ,witch is made fmm mmmcr time to w lnter time or vice vcr,~ the ne'~' time 'nat th~ hour change" Error informatiOll

Time s tat us The time status is set whell parameterizing the CPU with STEP 7 or w ith the SFC 100 SET_ eLKS . The time of day and the time statU.'< ean be read using the SI'C 51 RDSYSST vi a the system stams list (SSL_ID - W# i 6#O 132 with IND EX W# I6#OOO8). The slaWs v<mable includes:
p.

Loadable ,tandard blocks help you to hand le the ""mmer/winter time <witching of the local time in th~ user program, in particular the starting "fl ime-of-day inK"fl"ur>ts depending on Ihe local time (_ee further below IIndeT, "u>adable time-of-day b locks").

Time synchronization In an automation network wi th sev<'-"ral STM"ATTC stations exchanging dat<I with one anot..'>.eron subners, it is possible to synchronize the clock.<; of ~11 CPUs. You parameterize the n cloc k of one CPU as the "Masterciock , and ~et Ihe interval at which the synchroniation is to be carried out. You parameteriz e the blocks to be synchronized as "S lave c1<><.:ks". The synehroni'lalion can be carri ed out within an S7 stmion over the conmlUIlication. bus (ba ckplane bus) or between "Iation~ over the MPI bus . This is carried out at th~ parameteri ~~,<! interval aUlmnatically wh~"Il (he master e lock is set for th~ tlrst tim~. Jfyou set a clock with the SFC 0 SET CLK or SFC 100 S ET_ CLKS, al l other clocks in the subnetwork are automat ically synchronized to Ihis value.

The correction value (bits 2 to 6) in the 30- minute intcf'lal


Tb~

p.
to>

sign of the cotre<:tion

v~juc

(bit 7)

The ,ummer/ winter time identitication (bit 14) The


allll ou nc~ ment

[>-

hour (bit

I ~)

T he ."mmerlwinter time identijjco.lion shows whether the local tim~ calcu lated from Ihe module time and the correction value is the ,tllnmer time (with " j n) or the winter time (w ith 'D') . If Ihe announcement hOllY bit has th~ stams "j", the switebovcr from sununcr time to winter time i" carried out althe next change in hour. Using the time statu, infOrlnation, a local t ime can be generated from lhe module time ill ordeT to cOnl",1 timed pn:><:esses in the u~er program.

==

20 Main Program By calling the SFC 48 SNC_ RTCB in the mas clock, you can synchronize all slave b locks independent of the automatic interval. If the master clock does not have II timcof-day status, the slave docks are synchronize" with the winter time. The correction factor is zero, the local time then corresponds to the mod ule time. If the master clock works with II time_of day status, the ~omplet e time status is transmined in addition to the time. Therefore the same local time (the same time zone) exists On all CPU, in the lime network.
Set time ,.. rn g STEP 7

0-

lCT

I'B 61 SET- SW- S Switch over s ummer/winter time with time status
UDT 60 WS RULES Rules for switching over summer/winter time (e.g . time for switching over)

0-

20.3,2 Read System Clock


A CPU's system clock start, runn ing On power-

up. The system clock keeps running a s long as the CPU is executing the restart routine or is in RUN mode. When the CPU goes to STOP or HOLD. the current system time is "frozen'".

If you initiate a hOI reSlan on an S7_400 CPU,


When sett ing the CPU parameters, you Can set the synchroni?,.ation mode (ma'ter, slave or non~) ,md the synchron ization imerval in the attribUies window on the "Diagnosticslclock" tab). The correction value set hue is used to set the clock accuracy. You can set the time and tbe time StatuS using STEP 7 if the programming device is connected online to II CP U. Sekct PLC ..... DlAGJ','Qsncs/ CUSTOMtZE ..... SET TIME OF [)A Y. III the enhanced d ialog, you can set the local time as a differencc from the module time, and defIne the mmmeriwinter time. The time status is shown in the <'Status" box. Loudable timc--of-day blocks The program Miscdloncou. Bloc", in the Sla". <
dard Library contains loadable hlocks for han-

the system clock stans running again using the saved value as its starting time. Cold restart or wam, restart reset the system time.
The sy'tem time has data format TIME,
whe~by

it can asswne on ly positive values:

TIME#Oms to TI!I.1E#24d2 0h31m23sM 7ms. In th e evcnt of an overflow, the clock stans again at 0. Newer CPU. update the 'yslcm clock every millisecond, older S7_JOOCI' Us every 10 milliseconds . SFC 64 TTl\IE_TCK Read srste m time You can read thc current system time with system function SFC 64 TIME_ TCK. The RET_ VAL parameter contains the system time in the TIME data fomlat . You can usc the system dock, for example, to read out the current CPU runtime or, by computing the difference, to calculate the time hcme .. n two SFC 64 calls . Th~ diffe~n ee ~tween m'o valu es in TIM E fonnat is computed us ing D INT subtract ion. 20.3.3 Run-Time "Ieter
A run -time meter in a CPU counts the hours.

dling summ<..-r/w inter time s wi t~hing and the local time in the user program
b-

FC60LOC_ TTME Determine local time FC 61 BT_ LT Convert module time into local time FC62LT_BT Convert local time into moduk time FC 63 S LTTNT Sett ime-of-day interrupt to local time FB 60 SET_SW Switch over summer/winter time

b-

b-

(>

You csn u,e the run_time meter for such tasks as detenll ining the CPU runtime or sscet1aining the runtime of d.-vices connected to thai CP U. The value on tbe run-time rueter is also retained following e oold restan. failure of the backup voltage. and following a memory reset.

0-

'"

20 .3 Program Functions Table 20.5 Parameters uflhe SFC. for the Run_Time I>letet

.,

'"

,.
"
The range of values and the number ofron-timo me= per CPU dcpend on the CPU, The rang e is 16 b its (2 15_ I hours) or 32 bils (2 31_ 1 hours). When the CPU is at STOP or HOLD, the run-1ime meter also .10pS running; wh~n Ihe CPU is rcstallcd. the run-time m eter must be restarted When a run-time meter reaehe, the maximum time d "ration , it StOp, and reports an overflow. A run-time met ~r can b<: ,Cl to a ne w value or reset to zew only via an SFC call , Thc fol lowio g system functions are a vailab le to control a run-time meter;
D-

can be initialized us ing a ~onstant or a variable (as can all input parameters of el ementary data type). The PV parameter (data type fNT) is u,ed 10 set the m n-lim e m eter to an initial va lue. SFC 3's-Sparamctcr starts (with ~ ignal siaic "I"') Or stop, (with sif,,'nal _.tate "0") Ihe selected run-time meter. CQ indicates whether the run-tim e meter was ruoning (signa l stale .. I ") or stopped (signal State "0'') when scanned, The CV parameter record, the hours in INT format. By aSSigning Ihe MOD 6 parameterofS FC t u t. you can control a 32- bit run_time m eter as fol lows : B#I6IiOO B# I6#01
B 1t 16 ~02

SFC 2 SET_RTM Sel I 6-bit run -time meter SFC 3 CTRL_ RTM Start or stop I 6-bit run-t ime meter SFC 4 R.EAD RTM Read 16_bit run- time meter SFC 101 RTM Adjust 32-bit run- time meter

Read current meter value Start at last meter value Stop meter Set to value specified in I'V Set and stall at value speci fi ed

D-

D-

B#1 6#04 B#I6#05


Sol- l6#06

ev
PV

'"

Table 20.5 shows the parameter for these system functio!l.'l . The NR parameter stan ds for the number of the run-time meter, a nd has the data type BYTE. It

Set and Slop at va lue "pe<:ified in

You can al so u'e the SFCs for a 16_bitrun_time m eter to control a 32_bi t run_time meter. The

281

20 Main I>rogram Th e maximwn waiting time is 32767 I's; the minimum waiting time ,urresponds to the exe,ution time or the system function, which is CPU_spec ific. SFC 4 7 can be interrupted by higher_pr ior ity e\'~'DI.S. On an S7-3OO, mis increase.> the waiti ng time by the "" an time ofthc higher-priority interrupt routine. The system function SF C 46 ST P tenniruttes the prollram ,",an, and the CPU gocs to STOP. S'FC 46 STP has no parameters.

laner then rcsronds ns with a l ,,-b it range uf vnlu es. 20 .3.4 C omprc .. inK C P U
M~moQ'

Multiple del etion and reloa ding of bl""k:;, which otlcn ""cur during on line hlod:. modification, can resu l' in gaps in thc C PU's work m "",,,ry a nd in the RAJv1 load m emory which decrea se the amuunt of USllblc space in mem _ "'y When yuu call the " C ompress" ti.lll ction, y ou start a CPU program which tills these gaps by pusbing the blocks togethcr. Yuu can initiate the "Com pre,," f unction via a prOb 'TammiJ1 g dev ice c OIlllect cd tu the CPU or by , aUing ,yste rn fu nction SF C 25 C O :-' fPRES S. n , e p aramete r< for SrC 25 are lisu:d in Table 20.6. The compression p roced ure is d llitributed over several program cycles The SFC reHlI"f" RU SY - "I" to ind icate that it i< still in progress, and DONE - "I" to indicate th at it has cumpleted the c umprc>sion uperation . The SF"C call1lot comprcss whcn an ex ternally initiated cu mpression i< in progres., when the "Ddetc B lock" ti.mction is active, or when PG func tio n s ore accessing the block to be shifted (for instan ce thc I:Iloek Status function). Nute th m block:; of a particular CPU_specific maximWll lenglh cannot be compressed. so that gaps would sti ll remain in CPU memot),. Only th c Comp rc.s function initiatcd v ia thc PG w hil e the C PU is at STOP closes all gaps.

20.3.6 M uitip r oc csslll: " 'lo de The 57 -400 en ables multiproccssing. As many as four appropriate ly des igned C PU s e"n be operated in onc rack on th~ ,ume P bus and K bus. An S7_4{)() station is automatically in multipro ce s> or mode it you arrange more than one CPU in the ~entml rack in the Hardware Cunfig uration . The slot.> ~r e arbitrary; the C P Us arc d is tinguished by a Dumber a"ib'Dcd uut"matically in ascend ing order when the CPU, are plugged in. You can also assign this number your>d f un lhe "Multieomput;ns" tab. Thc configuratiun ,l,l;i fur all the CPUs must he loaded into th~ PLC, even when you make chang~s to only one CPU .

After assi gn ing parameters 10 tbe CPU,> you


must assign each modul~ i1l the station to " CPU. This is don e by parameterizing the moduk in 'he "Addrcss~," tab under CPU Allocation" (Figure 20 .5). At th ~ sam, time Ihal y<>u assign tbe T nodule's address area, you also assign the module's interrupts to this CPU. With VTEw ---> FlL TER ---> CPU No. X - .\10D ULES, you can empha size tbe module, ~s>igned to a CPU in the config uTation tables.

20.3 .S '\Vait in l: a mI St opp in g The syste m fun ~'1ion St C 47 WAlT hait, the program sca n fur a specified period of time SfC 47 WALT has input parameter WT of data type tNT in whi ch you c an spec ify the wailing timc in mi croseconds !fl').

Tab le 20.6 Panuru:tcr. for SFC 2S COl\-lPRLSS

20.3 Program Functions

P....,.,,"~ ,

lJtth><IJI " .v tnt~"upI

III00S ' 1

'I

p- .E"" pttIC . . . " , , !:!"---

1 I 2

Figure

20.~

Module Assignment> in Mul,iproces>or Mode

The CPU s in a multiprocessing ne1,,'ork all have the sam e operating mode. This meanS
t>

The y m'-'5t al l be same restan mode:

para 'neteri ~e d

wi th th e

ey of the time acqu isition is C P lJ-dependen! and the times arc ~pec ifi ~-J in microse~onds. If there is no value pending for a requested time, - I (O Wit I6#FF FF FFFFj is returned , Principle oftime mea.urement In the operatinli\ system of Ihe CPU, a timer runs wilh a relative time in m icroseconds from o to 2 31 _ 1. A t th e rran,ition from STOP to RUN . the timer is started. runs 10 the upper 1im_ it. and then start s a gain from zero. The OB stan even!, the beginning and end of OB execution. an d the intclTUption" caused hy h ighe r-priority OBs are caprnred in thc operating system. T he data of th e last compl eted OB execution that was current allhe time of calling the SFC 78 is stored SFC call outside the OB to be measured applying the SfC. a d ist inction is made b ctween a call in Ihe program of the requested OB aud one o utside the requested OR. E",am pie: The SFC 78 is called in the OB I and is assigned a value " f 30 in the para meter O B _ NR. The la:;t captured times for OB 30 are then read, Specifi cation of the synchronous error OB with the numbers 121 and 122 is not penn is s ible because these be long to the priority c lass ofthe error-c ausing OBs and tbus to their pr<>gmm
Wh~n F i gur~ 20,6 shows some examp les o f calling SFC 78 outs ide th e OB to be mc" sur~d, The ini -

t>

They all go to RUN simultaneous ly;

"" They ~ll go to HOLD when you debug in single-,t\.l' mode in "ne of the CPUs; "" They all go to STOP as soon as "ne of Ihe CP Us goes to STOP. When "nC rac k in the slation fails, organization block OB 86 is called in each C PU , The user program s in thcse CPUs execute indepcmkm ly of one another; they are not synchronized. An SFC 35 MP _ALM call start, organ ization block OB 60 "Mu ltiproce ssor interrupt" ' in all CPUs simultaneous ly (sec Chapt~,,- 21 ,1 . "M ul tiprocessor Imcrntpt"j , 20.3.7 Delermlnlng the OH I'rfIj;(ram Runtime The system function SFC 78 OB_RT determine, the runtime of in dividual organization blocks over different time periods. This enables you 1 detennine the time load (utilization) of 0 the u, er program. The operating sy st em of a CPU designed for this purposc log, Ihe run! ime~ of the indiv idual organi~alion blOCks and m ak es them available for readi ng vi a Ihe SFC 78 OI'_ RT. The acel.lrS-

20 Main Program

Parameters oflhc S l-"C 78 INPUT


[NT

tim.", .'" to be

OUTPUT

nTKT

\ial values after a ST O P-RUN transition (c xarnple(Dl ,

a~ - 1

prionty cla"es

a~ nOI

includ ed in LAST_RT

(@).

L A ST RT indic ates the nl!)lime in m;""" ec onds o f the laSI co mr leled 0 13 e"ecution (ex am pl es (%) 10 @). The -'n et" runt imes arc output. lnterrur t tim es cause d by OBs wilh higher

LA ST ET indicales the tim e p"riod in m inoseconds between the stan request and (he en d of process ing for Ihe last "omplct"d ""cculion o f

Sl OP

IRUN .

S FC7 6 calt outsid e the organ(2alion block to be mM$O'ed

Interrupt"'n by 06 01 highe, p riority

l tD

(j)

O'n processing O'n s tart ' '''luest


SFC780a ii

o
!

D
I I

O
I I I I

(OS_NOa xx)

I I
' ....

II I I I II I I I

II
I

o
I I

I II I

v. tu in ,o.. SfC 71

p" . . m.

Fig",,",, 211.6

Ca llin ~

SFC 78 outside tho orson ;n,;on h lock 10 be measured

'"

ZO.3 I'roaram func.ion$ Ihe 013 10 be measured (e:ump!CS@IO@). In lem.tpl limes cause<! hy higher prinrity cla"e, are included m LAST_ET (@). CUR_T indicate , the rel ative lime in microsec onds (~Wtus oflhe counter in the operating sy, tem) of the start I"filucst of the OB. After initial ization Ct JR T {(D) conLain~ -I. On comple.tion of OB eunnion, CUR T i~ let to zero . Since SfC 78 i. can.-d out.ide the OB in these exampk~ ;1 cons.-quently OUtputS zero at thi. ()artlmelcr. CUR_RT indicates the effective execution time of the O R W1ti l calling "f SFC 7g in microsc~ onds. After initialization CUR_RT (CD) con taiDs 1. Anercomplelion ofOa execulion, the vallie in CUR_RT is IrllmfermJ to LAST_RT and CUR_ RT i. set to "",ro. Siru."l.' the SFC call laJ.:c~ place outside th" oa in these exampk-s, the value i. alway. zeTO. CU R_fiT indicates the time period from the OB sian request to calling of SFC 78 in mieroscc onds. After ~ompletion of OB c~cc"ti on, the value in CUR ET is transfen-cd to LAST ET and CCR_RT i:, <et to ~ero. Since the SFC-call
tak~s place out,ide the OB in tht'SC the value is alwa)" zero e~amples,

NEXT_RT indicates the time from the next OR .tan !\:qllC>1 10 callin!> of the SF<: in mkro.",, o~ds if fllrtbcr. IInproceued stnrt reqllcst& are fK'nd~. In the ~~sc of the eUrRmly supplied CPU" NEXT_RT i, not ealcll[ared IUId the val ue is al""'~5 -I. S FC u llin th e pr ognm nr th e 08 10 be
mCll~ ured

S.F C 7~ can al,o he call ed in the program of the 01'1 t() be measured. The parameter O B_NR i. then initialized with ~t'To and the ()arametcr RfT_VAL returns the c~nt OB number - in Ihe C~ of error fr..., e~eculion . The limes for the O D in which SFC 78 is ea ll .-d an; read. When calJ..iDg in one of the . ~nchrooous e-rmr 0135 witb the numbers 121 and 122, this is the data of the OR causing the error. fijjul"C 20.7 shows some examples of calling SfC 78 in the program of the OB 10 be mea gured. This elln be dire<;tly in the

on program
De

In......,p1lon ~ OB of high prio rity


o,~

~E'
i ,

SFC78 eellinlide t!le organization bInc:k ID

'. r--1 , _ __ _ __ _ _ _ _ __ _ _!Il_.L_______

moowred

____

"
j .:"'

processi,,!!
oe~

I
I

I I

I I
I

SUrt requNt

SFC78 call In \tie


O8JOt (OB_NO.oO)

iI , I, ,
,

I '

I, I , I I , I
~

II
I' ..
I" Iff

I' ,

'J! I1

:':
I

110 I" 111

I'~

~.Iuo.

'" 111, Ife7. poramo""

Fljl.ore 20.7 Calling SFC is withlll rho

o'il~ni:<ati()fl

block 10 \>0

m~ .. urcd

20 Main Projram

Prot..,tioo level I

, ,

o r in one of the blocks called there . The initial values after a STOP-RUN transition are - I. LAST RT indicates thc ruonroe in mt<:roScCo ndl; of the last completed OB e"ceution (e,,_ ample . . and @) _ I f the SFC is called again in the OB to be mea.ured. -I i. o utput (e ~ampl c is)}. The "n~t" rumimes IltC" outpUt; interrupt times caused by h;~er priority classe. are oot inoluded in LAST_RT (">lample ). LAST_ ET indtcates the time period in microseconds betwccn Ihe request aDd the end of pro-

ondj if funhcr. unprocnsed stan re quests are pending_ In the ClUC of the currently supplied CPU!!. NEXT_RT is nOI detenn;ned and the v.lue i. alwaY5 - I .

20.3.8 C haai'ng I"oiu", pro tection


The user program in u CPU can be protected against access ;n three protection level, (see Chapter 2.6.2 ... ?t-ol~ini the User I'Toal1lm"). ProJntm-dri,-cn touling between protection Ie-.els I and 2 IS possible ",ith the syStem function S FC 109 PR O T ECT. You can fin<J the pa rameters of thIs system function in Table 20.S. CaUing SFC 109 PROTECT is only effe..:tiv" if you ha\'e set Protection level I with the hard_ ware configuration. 11 remairu; inef'fe<:tive if Profection I"vel 2 Or 3 is set, or if. password has been ente,..,d in Protection levcl ] in conJunction Wilh the oplion Can be revoked by paS5"ord The prote ction leve l IiCt wilh SFC 109 PROT ECT ,..,mains unchanged if: :. 'he CPU goes 10 STOP due 10 a (program) error. an SfC 46 STP call, o r operator inler'enrion.
Co

cc""ing for the la81 completed e"eeutiDn o f tbe O B 1 be measured (e>lamples ([l and@) _This 0 also applies for the fi rst call of SFC 78 in the O B to be mea.urcd (@). If the SFC is called again in the OB to be measUNld. - I is output (ClCample It). LAST_ET abo contain;, tbe interrupt times caused by higher Priority classes

(@).
CUR_T indicates the rdative lime in micro~ o nds (statuS of the counter in the operating system) o f lbe Sla" request of the OBs. "'hen - as in the following ex .. mpln - the SFC 78 i. called within the OB. On completion ofOB exec ulion. Ct: R_T i ..,t to zero. CUR RT indicates Ihe effect"'e ""eculion 11mc a fthe OB in microseconds uotil cBlhni ofSf C 7 8. After completion ofOB ex e~ution. the value in Cl,-R_RT;s trans fcm:d 10 LAST_ RT and C UR R T is set 10 ~ero. Int~rTUpt lim~s cau~ed b y higher priority clas...,s ftre nol included in C UR_RT {@ andlt)). CUR_ET ind icates the tune pe-riod from the DB
SIan rc:quc~1 to tlllling of SFC 78 in mierase<:-

the CPU ;~ baltcry-backed and the mai n. supply is ,..,sI0red. Or

Co

a reSlarl is carried out (S7-400)

In all otber caseS. ProteClion level 1 is set in the c:UC of an operating mode mm.sition. Even if you switch the mode selector to STOP, Protec_ tion level I is (,..,)sct. can d etermine the Current prole<:!ion level online in the SIMATIC Manager wi th .elected CP U ami P L C ..... DLAOl'OST1C/SETfL"O"'" OPERAT1:"G MODE. In the program. you can scan the protection I""el w1\h the SFC 51 RDSYSST via the systcm st3rus list W"16>f02J2 with the 1!Ide" W"I6><0004,
VOIl

oods. A fle-r comp l~t;on of 08 e~e<:Ulion. the value in CUR_ET is transferred to LAS T_ET and CUR_ET ii set to zerO. CUR_ lOT IIlso con lains Ihe ruJ1\ime~ of the higher_priority OBs Ihat inlerrupt the OB current;y to be measun-d.
NEXT_RT indicale5
th~ time from the ne"t DB stan request to caJlmg of the SFC in microscc-

'"'

20.4 Communication via Distributc<i 110

In the case of a CPU with key loc k switch as mode selector, you can remove the key in the RUN pos ition and permit read access only by the progmrnming device during operation. In th e case of a toggle switch as mode sele<:tor. this is not possible. In this case. you can call SFC 109 PROTECT in the restan organizat ion blocks 10 activate Prote<:tion level 2, that is, write protection (read aCCess only) when swi tching on the CPU With SFC 109 PROTECT. you can change the protection level during operation without operating the mode selector. Thu . for example. with SFC 109 PROTECT you can (re)set the protection level to I wilh M ODE W# I6#OOOO depending on the signal state of a binary variable, in order. for example. to reload program sections . Then you re_activate write protection w ith MODE - W#16#OOO1.

referred to as the DP master system. Several DP master system s can be present in an S7 station . Newer DP m asters can handle tWo operating modes : DPVI and S7 -eompatible . "S7--<:ompatible" corresponds to the previous mode . With this, you can operate all DP standard slaves according to EN 50170. and additionally the "D P S7 slaves from Siemens which could al ready send interrupts to the DP master. In DPY I mode, y ou can additionally used DP slaves which exhibit the new properties according 10 IEC 61131, such as increa~cd diagnostics and parameteri7.ation capabilities resulling from the acyclic transmission of data records or the use of new types of interrupt. New sys tem fu nctions for traru;mission of data reoords. as wcll as new interrupt organization blocks. exist for the.e new "DPYI slave s". Like the central modules. the DP slaves occupy a ddre.se, in the lIO area of the CPU (""logical a ddress area") . The DP master is as it were "transparent' to the addresses of the DP slaves; the CPU " sees' the addresses of the DP slaves, meaning that the .. e must not overlap with those o f the central modules. nul e ven w ith Ihose of DP slaves in olher DP master systems assi .. ",ed to the C PU. Every DP slave has three addresses in ~ddition to th~ node addre ss , a geographical address. a module staning address and at least one diagnostics adJ",ss (Fi gu'" 20.8). Node ad d ress Every node on the PROFBLBUS subnetwork has a unique address, the node address (station number) in that subnetwork that distinguishes it from Ihe other node s o n the subnetwork. The station ( the DP master o r a DP slave) is accessed on PROFIB US with this node address. Please nol e that there must be a gap of at least I between the addresses of th e activ e bus nodes (e.g . in tbe case ofDP ma.ter and nodes in cross traffic) . STEP 7 takes this into account when assigning node addresses automatically. Geu graphlcal a ddress The geographical address identifies a module slot. With central modules. the gcographical

20.4 C ommunication yi a Dis t r ib uted V O


Distributed lIO is understood to be m odules connected over PROFIB US DP Or rROFlNET

'0.
With PROFtB US Dr, the DP maSter communicates with the DP sla vcs assigned to It OVer the PRO FtBUS sub n etwork. With PROFINET 10, it is the 10 controller which exchanges data with the 10 de vi ces assigned to it over the InduSlrial Ethernet sub neN'o rk. Th e data tran sm issio n is carried out 'automatically", you do not need to be invol ved. You configClre and address the d istributed VO using the Hardware Configuration tool in a manner similar 10 with the central modules . From the user program. yOCl can address the inputs and outputs in the stations of the distributed lIO just like the inputs and outputs of the central modules. 20.4 .1 Address in g PROFmUS DP The d istributed modules (slations, Dr slaves) with PROFIl:IUS DP are assigned to a DP master in" manner simi la r to how the centra l modules are assigned to a CPU and controlled by it. The DP master with all 'its" DP slaves is

20 Main I'rogmru

Dlllln" ..tl~ . Idd (_ _ otIr) ....

@.
_ _-

Module< DP ......
SIoto
Slot ~

_.

.. /

""VIo1u8I" .kot (not pI"l)....,.,. ",,;0''''')

'" .,., "M "'" , .,.,


~
;;B~
,,~

1020 Sla!icn 101 9 '

""""Io" ".1klI!

SIolO_..",,,, _
SI<>/ 2 ecn/a;n. 1M bu. Im..-h>oo
1M).

In ..""" modui<>

"',,_.

SJgt>III_s . . U _ In 0/01 4 and

E837

A8 506 00& .. 0
AB~!

B\"U \

Mod ....... nlnll add . ...


(&11_

00

"'.Y)

addrC!;8 comains (he number of the raek ar.d that the sl" t. Wi t~ PROfIB US DP, th~ geogmphicill addres~ conluins (nc numher of (he DP nlll&(er ays(em. the "UII;"" numlJ.er lind the slOl number.

"r

Slol numbering of a 01' ~la,c depends OD its typc. If il i. integrated u~il1g a GSD iilc. the entri,,~ in the GSD file determine Ihe sl"t a t which the 110 modules Slart. Tn lhe ease "fDP standard slaves, the 51015 for 110 modules begin al 1. Slot DWJlhering ofllll S7 sla'e is ba.cd on the 5101 of an S7-300 $Ultion. S1015 I (pow.,r supply) and 3 (c"pan~ion interface module) rellUlin empty. Slot 2 (CPU) corr~jpond.$ to the interC8.(:c module (header modul~) of the modu lllr DP Slaves. The ~ignal modulcs (SM) are poo.;itioned stanin& at s1014.1n addition. there is Ihe vinual" slol 0 (nol physically present): this representS th" comrlete statiun. It is similar with intelligent Dr slav~s. In th is casc. the tnmsfcr memory i. the mtet"f..cc to the Dr> ""'stet". Confi&UT8.lion of the transfer memory _ whicn you CftlT}' OUt with thc Hudwar.. ConfillUralion tool genemtes areas" hieh corl"C"<pond to modules or .lms. These ~jOtS do not l"C"aUy l:JIil;t. and one th~refore speaks nf vir_ mal" slolS.
Virtual ,101 0 I"C"preSCtllS the: DP <18tioll. virtual lot 2 lhe bus interface. in this case !be slave

CPU a> the heRder module oftbe DP slaw. From vinual $101 4 o"ward<. the user data "r~as are pl\:scnt in lhe transfe r memory; th ey COlT"'spond to the si&nal modules. The virtual slot. in the transfer memory are ~sem hy both Ihe mILSter and ,lp'e CPLs. The defm.ition or virtual <lots malte. It possible to dire~t1y a~.ign diagno>1ic. tlnd intemJpt events of the mlcrfllce module "r the station (see further below ~Diagnosties lidd .... ss ..). Thc srsTem funcTions SFC 5 GADR_LGC and SFC 49 LGC_GADR a1"<" available for converllion from the &eograrhical "ddr~ss to the iOllieal nddr~sscs and vice versa. and (he '}"Ilem functiOn! SFC 70 UEO_LOG and SFC 71 LO,,_ GEO ar., al'O suituble for PKOFINET 10. NOle that DP slaves which are iocorpor:a.,ed inlO

the hardware confillunltion through ~ GSD m",


according to EN 501 70 of ver!\ion 3 or latn (DPV I) c an suv'"' the user data staning at <lot I ,
Lo~ica l

a d dress..

module starli ng a ddl"l's


You use the logical addre.s t" ~ce~s th~ user dati' of a station, Each byte "f the user tiura i~ unumbiguou.ty identified by a logica l uddre~s. The logical address corresponds to the absolute liddTcs<: a ,;ymbol (Dame) Can be assigned 10 it .0 that it i~ easiertoread (symbolic addresi!ing) .

20A Communication via Distributed 110

The ",,,,Ilest logical ad d,ess of a module or station is the mooulc starting address (sec also C hapler lA, "Module Addresses"). Dia::nostic,; addu .. Modules an d stations which can deli ver d iagnostics data and d o not h ave a u ser dats address themselves are identified by the diagnostics address. The diagn"sties add..,,. occnpics one byte ofIlO input in th e logical addre " .." lum e . In the d eb ult sening, STEP 7 as,igns the diag nostics addro" starting w ith the high~ ,t address in the 110 "re~ of the CPU. You can change Iheo diagnostics addr,,"s. Th~ addre" overview io the Hardwm... Configuration tool identifk, the diagnostics addre ss by a star. Signal mod ules or u'~r data areas in \he t",ru;f~"T m~mory of intellig~nt DP slave, ha"e logi~al addresses, also for scanning d iagnostics data. Thc complete station delin"Tll its d iagnostics data via one diagnostics addres, which is "",i;;n~d to virtual ,lot O. With modu lar and intelligent op s laves, the bus interface can del iver it' d iagnostics data v ia the diagno>lics address oislot 2. Figure 20.9 shows an ~Xllmple of the dia .. tics addre,';e , in a OP master system A co m_ pact DP slave pos~es,c" one diagnostics addre.s for the compl ete s"'lion, a modular DP slave po,sesses one diagnos tic s addre ss for the stati on and onc fOT lh~ interface module . \Vith intelligent DI' s laves, there is also a d iagnostic s address [or the OP interface. Th e d iagnostics addresse, are ass ig ned in descendi ng order starting w ith the highes t 110 address. For example, \he UP interlace of the CPU J I 7-2PNIDP is aSSlg:D ed the diagnostics addres. 81 91 , the PN interface the addre ss 8190 (not shown in Figure 20.9), and the virtu al slots o and 2 in the tra "sf~r memory the addrcsses RI89 and 81 8R. It is similar w ith the ma,ter CPU: the diagnostics addrcsscs Start at 16383 for the DP im erfu ee and continu" w ith 16382 tnr the MI'VDP interface (not shmnl), 1638 1 and 16JHO for th e virtual slol:l 0 II1ld 2 of the tirst intelligent DP 'lave. 16379111ld 16378 for the second 01' slave etc. The diagnostics addre,ses for th e np slaves are a ss igned hy the Hardware Configuration tool in the sequence of coupling to the DP master system.

In th" user program , the diagnostios data are

scano ed using system b locks . The system TImetion SFC 13 nPNRM DG is " v"ila bl~ for this with conventional 01' >tandard s laves. The SFC S9 RD_REC is used w;\h OP S7 slaves in orde r to read the data record OS 1 w ith the diagnostic . data. DrYI s lav es a.., able to provide more eompreh~n,ive d iagnost ics data wh ich can be rcad with th e system filllction block srn 52 KDREC. Th e modules are addressed by m~an" of the logi cal module starting addr~ss of th~ user data or by means of th e d iag no",ics addresses. Transfer me m ory o n in telligent DP .Ia,cs In the cas e of eornp",:1 and modular DP sla.ves. the addr~ sse s of \he inP < an d OUtpnts are llS locat~d together w ith the addresse, for tbe cen!nil modules in the address volume ufthe mal<ter CPU. In the ea , e of intcllig~ m ,Ia,cs, the maste r CPU has no direct ae~eSS to the input! output m odules of the UP sl ave. Every imelli gem Dr slave therefore has a tra n.fer m emory whosc size depends on the CPU used. TIle transfer memory can be divided into several areas of di fferent len~>th and dam ~onsiSlcney. The indivi dua l areas then respond like modules whose lowest address i~ th c module starting address. From the viewpoint of the master CPU, the intclligem DP . lave then appears as a compact or mod,, 1 01' s lave. dcpt.."Ilding on 1lC the division (Figure 20. I 0).
\Vh~ n configuring thc slavc, you ~an configure the individual areas of th~ !nmsf~r memory as inp ut,; or outputs wi th the "module starting address" and the area length. Exception; if the CI' 342-5 01' provide s the DP interfac~ tor the intelli gent slave, the divi sion of its transfer memory is only configur~d when coopling to the DP ma ster system . The addresses o f the transfe r m emory must not overlap with tho.e of th~ eentrol m odules in the intclligent DP slave. T the addrcsse, are present in the process f image . the areas can b e handled by the o,cr program l ik~ inputs and outpUI:l, o\hcrw isc Hke periphcral inputs and outputs. If the s lave C PlJ possesses panial pro<:ess image . you can assign a partial process image to each area.

'1l"'-

When coupling to the DP master SY"tem, yon supplement th~ configuration a t the master e nd by the " module starting addresses" from the

20 Main l'ropm

Mu~'

CPU ((1120Pf

CP m..

'" -~~':.c:~"~"'~~~~,-.~,,=~====::tJ ' .~ '

t.,

--.
_

n....- .. """ ..... ;" IhrI moootor CPU


.wit~the

..

<l> -,~-:.

_algent OP ...""

S ...... CPU (311 .JPNlOP) 819>'


8189'
8188'

OPIro_
1$381 ' SIo"UI/IIIOn

LL.. \

I,

1&380'

Bu.in>:o<f_

'" I ::r-'"

The use, prognrm


inlhrlslaYeCPV
"""" wrtrl _

.d<I,Mse.
SI.,.. CPU jJ14(:2 0P

"""llIg.nt OP I I."" OPin_

L_ "'"~~'"',-, ' ~;.".".""""",-",~ , -,I ;:J ",Mo~ul . ,

OP .ro ....
OP~

--inlhrlslaYeCPU

The...." .."""."

addresse_

L______J---"*'"
r,
~-"'"

1~75'

S\o lIIIon

(D U<Io t-iIoIodI<c bo'I. "'~_ biolrirr _ ia .... ~of"" _ '" "'"

..

(Jl EIdIr bu. 11m............ d . . . . _ ' " - . . . . ,,'1ri<II is


OM ......

- _ I M > {_ _ k ""\',.- ... io

obi' p<rperIr" of"'" iat<rlace ill ....


<!jot "'" "Orin.: io.

- _ uI> {_

1bo

"n.

c?\.).

1_ . -1 _ - , ...

... -

II> 1b< .....,., orNI ;,. t.... _ _ Ira,......"""'"

II<Idrno wlriob ..... in .... '*'i' "rib< "",i,", ill tho ~ ... b (rlooblo oll<k ttrc: DP .1,,". <tali"" in til< Iranl""" confiJU"""'" 01 "'" DP ..... "rf .

"""'""lOt

The _ ... iJlM> urrl"o 100" Jio;ooon _ ... wlti,h ..... in .... ob,o;:t _ n i .. ~I"" .... ,;on in th. "Moo." ",b (rIoob!< '1I<k 110< "lW' Ii"" i. tiro

.II,-.UU).

.,-,,
-~

--_. - ...... -_
,

.~

r ... ___ _

- -"... . - -'-:;'~=:
__ h

F----~----. .Ii

----~.

~-

""

20.4

Communi~at ion

via Distributed 110

B 05

system
Int~,r,,,;,,

\. _~I!~_

"_""~~~ :;:::: ,"~'~':;I~I. _ 01 DPnostic. add ..." Diag {ntarfaoe


(lOOP m.aot&r)

'"

Tran.f. rmGmory
, I

" '' - _ - '

DP "aU"" ~~===~~2F: Dia~noslic"


0/

add","

of bu. ir.tillfOC8 (oJav. C P U )

Di09"",,1;0 " lIdd","

UO<Irdata . "'."

T",n.11t, m<lmo<y from

".w of

mnl ~ ' CPU

T.... n.f.' ....... mory from view of . Iave CPU

Figure 20. 10 Trnmkr Memory em inldlilr<nt DP Slaves

v iewpoint of the master CPU and by the trans_ mission dir~et;on. You assign inputs on the s lave ., ide to outputs on \he maSter side and vice versa. If the addresses are within the p t oeess im"g~. the areas ~an No handled by the U.~er pmgram like inputs and ou,p"ts, othe rwise like peripheral inpm~ and outputs . If the master CPU possesses partial pro~ess image_ , you can also ass ign a partial process image to each area. from the viewpuint of the ma,ter CPU. the "dd",,!<es o f the transfer memory must nDt overlap with ad~sscs or other modules in the (ce ntralized) S7 stalion . neither with the add",.ses Df the c<,."11tral modules nDr w ith the addre sses in Dther DP master systems ass igned to thu ma.ter CPU. Yo" alw define the diagJ105!ies add",",c, fwm the viewpoint of the inte lligent 01' slave. during configuration of these. You determine the diagnostics addresse" from the vicwpoint ofthe master CPU during coupling o f the inte lligent D P slave 10 the DP master ~ystem. D ata eon . i.tcn cy Data cDm i. tency means that a b lock of USer data is band ied a ll t ogcther. DP slaves can exhibit consistent dma areas, either as a result o fl he wnfiguration infonnation in th e OSD ftl e or - as with the transfer memory Df an intelligen t slave-through CDnfigW"8tion by the Hardware Configuration tDOI. In the Dbje<:l properties of the D P sl ave, one can set the data cDnsisteney tD "Unit'" (byte or word) or "Total" (~on-

figured area) on the "Configuration" mh. These data are tak en intD considcratiDn by the Dperating system, e .g. during Updating of the (partial) proees. image (see Chapter 1.5 .3, "Consistent User Data"). As the user, you m",! enSCIre thc con. is tency of the transmitted d1lm in the pmgram. If thc data are a comprises one, two or f<Jur byte", transmit the data as bytes. words or doublewDrds using the load and transfer instruetiDru; or the MOVE hox 'Vith an area lcngth of 3 Dr more tha n 4 byte s. usc the system funetiDn. S FC 14 DPRD_ DAT and SFC 15 DP- WR- D AT in order to transmil the data betwe en the user m cmory Bnd the transfer memory. H the addres.e s of the transfer m emory are in the process image , use th~ address area for inp ut" I or output. Q on the RECORD parameter of the SFCs , otherw ise the addrcs. area for periphera l inputs PI or peripheral outputs PQ. The system f"netions a re u sed in bmh the mer p rogram of the s lave CPU and in the uscr program of the m~sler Cl'U in Ordcr to B~ce" the data . The cDnfigur~d data areas which are transmittcd with the 'ystem funet iDns are present com pletely in the pmccss image (with n ewer CPUs) so Ihat you can also access them using IDad and transfer instruction, or the MOVE: oox. Note that Y<JU may destroy the data c<.>ru;;stcncy in the proce" StaMing from the user program of the slave CP U, you can trigger" process interrupt for a n address arCa of the tmnsfer m~mory "sing the

'"

20 Main Program SFC 7 DP_PRAL, and a diagnostics or process interrupt in the master CPU using the SFB 75 SALRM. 20.4.2 Configuring PROFIBU5 DP
m~mory). You can also configure the remaining modules later. Save and compile the ,tatioo

Proceed m the same way for the remaining stations int=ded for intelligent Dr slaves.
6) Open the master station with the DP master

General procedure
You configure ilie distrib uted I/O on the rRO F1BUS DP in essentially the same way as the centralized modules. Instead of arranging modules in a mounting rack. you a"ign DP Stations (PROHBUS nodes) to a Dr master system. The following order is recommended for ilie necessary actions' I) Creale a new projec t or open an existing one wiili the 51MATIC Manager.
2) Create a PRO FlBU5 subnetv.. ork in ilie

system and use the mOuse to drag the PROFlBUS nodes (compact and modular Dr slave.) from th~ hardware catalog to the DP master system. Assign node addresse s and, if necessary, set the module starting address and the d iagnostics address.
7) If you haye created intelligent DP slaves,

drag th e relevant icon (in th~ hardware catalog under "PROflBUS DP" and '"Already configured stations') with the mouse 10 the DP master system. Open the icon and assign the already configured DP . lave e'Connect"), assign a node address and configure lhe user data interface from the viewpoint of the DP mas_ ter (or from the viewpoint of the cemral rna~ter CPU). Proceed in the same way with every int.llig~nt DP slave.
8} Sa"e and compile all stations. The DP mas_ ter system is now configured . You can now supplement Ihe configuration with centra'ized modu les Or with further Dr slaves.

project with the SIMATIC Manager and. if required. set the bus profi le.
3} Usc the SIMATIC M anager to create the

mas\<."! slation in the project thaI is to accommodate the DP master. e.g . an 57400 station. If your system contains intelligeot DP slaves. you also cr~ate th~ relevant $Ia\'e stations at lhis point, e.g. S7-300 station;; . You start the HardWllre Configuration by opening the master station.
4) With the Hardware Configuration. you place a DP master in the master station. This can be. for example, a CPU with int~

gral DP interface. You assign the previously created PROFIBUS so.lbnctwork to the Of> interface and you then have a Dr master .ystem. YOo.l also define the DP mode in the "Mode" tab: DPVI or 57-comparible. You can also configure the remaining modules later. Save and compi le the station.
5} If you have created an 5i "Union for an intelligent DP sl av~. you open this in the Hardware Configuration and you '"plug in " the module with th e desired DP interfac~, c.g. an S7-300 CPU with integral DP interface or an ET200pro basic modo.lle 1M 1548/CPU. If you set the DP interface as "DP 81 ave", asslgn the previously created PROFlBUS subnetwork to the DP interface and configure the user data interface from the viewpoint of the DP slave (transfer

You Can also represent the DP master system configur~d in this way graphically with the Network Configuration tool. Open Network Configuration by. for example. double_clicking ana s ~b nel\\ork . Select VIEW --+ DP SLAVEs/IO D EVICES to display the slaves. You can also create a DP master syslem (or mOre precisely, assign the nodes to a PROFIBUS subnetwork) with the Net".. ork Con figuration tooL You parameterize the >lations after opening them with the Hardware Configuration. lIere too, you must first set up an intelligent DP slave before you can integrate it into a DP master S)"5tern. Con llgurlng Ihe DP master You must have created a project and an 57 station with the SllI.1ATlC Manager. You open the 57 sta tio n and create a mounting rack (see Chapter 2.3, "Configuring Stations"). Now drag the Dr master module from the Hardware

292

20.4 Communication via Distributed Catalog to the ~onfigUJation table of the mouming ra~k. You may already have sele~(cd a CPU with OP connection. In the li n~ below. the DP master is displayed with a conn~ction to a OP master system in the station window (brok ~n black _andwhite bar) . When placing the OP master module. yo u select in a window the PROFlBUS subnetwork to which the DP mast.. r system is to be ,.,sign..d and the node addre" to be ass igned to the DP master. You can also ~reat e a n~w PROFffilJS subnelwork in Ihis window. In the "ModC-' lab you also defi ne the Dr mode with wb ich the Df> master is to work. This modc applies to the complete DP master ~ys tcm. If there is nO Di' master system a"ailable (it may be that it is obs~ured behind an object or it is outside th e visible area). create one by selecting the DP maSK"!" in the configuralion w indow "nd tJ'en ~deeling INSERT ..... MASTER SYSTEM You ean change th~ node address and lh~ con nectiotl to the PROFlBUS subnetwork by selecting the modu l ~ and then making your changes with the "Properties" button on th e "General" tab under EDtT ..... O,HECT f>ROPRTIES. CP 341_5DP as DP master Ifa CP 342_50f> is the DP master. place it in (he configuration table of the station, 'elect it and then EDIT ..... OBJECT PROP ERTIES. Set "01' Master" 00 the "Mode" tab . The "Addresses" tah shows the user data addre.s occupied by the CI' in the address area of the CPU. From the viewpuint of the master CPU. the C P J42_50P is an -'analog module" with a module starting address and 16 bytes of user data. Only DP standard slaves. or DP S7 slaves that behave like \)P standard slaves, can be conn.. cted to a CP 34 2-50P as OP ma,tcr. You "an find the suitable 01' slaves in the hardware catalog under "PROflBUS OP" and "CP 342-501' as DP master" Selee( the desired slave type and drag it to the OP ma"er system. The transfer memory as OF master has a mall ;mum length of 240 bytes. It is transferred as one with the londable bloch FC 1 DI' SE}.!) and FC 2 DP_RECV (included in the Sta"dard

[/0

Library under (he Communication Blocks program). The data memory.


cons ; st=~y

cOver, the entire transfer

You r~ad the diagnostics data of the con nected DP slaves with FC 3 DP_DlAG (e .g. stalion list, diagnostics data ofa spec ific station). Fe 4 OP_ CTRL tran,fers control jobs to the CP 342_50P (e.g. SYNCIFREEZE command. CLEAR command, set operati ng stale ofthc CP 342-5DP). If you select CPU o r CP 342-501'. ViEw ..... ADDRESS OVERVIEW shows you a list of the as,igned addresses, inputs and/or OUIPUt>;. You can also SCfcen the existing address gaps. Config uring
co mp a~t

DP , Ian'.

Tk compact 01' slave, are to be found in the


hardware calalog und~r "PROFIBUS DP" and lbc re levant sub-catalog. e.g . ET200B. C lick on the OP , lave sel ected and drag it to Ihe icon for the OP master systCtn. You will see the properties sheet o f the station: here. you set Ihc node address and any d iagnostics address. Then the OP slave appears as ,m icon in the upper section of the station window and the low,,"!" ",~tion contains a coofigunuion table for (his stalion. A double-click on the i~on in the upper section of the station windu'" opuns a dia log box with one or more tabs in wh ich YOLl fiet the desired station properties. In the lower .ub-window. yo .. then ,cc (he input/output addresses. Double-cl icking on an address line shows yuu a window wbere you can change the su ggested addre'$e$. The lower sub-window shows optionally the conf<guralion table of the selected OP slave or of the master system (Ioggle with the "arrow" b utton). C onfigurin g modu la r UP slaves The modular OP slave~ can be found in the hardware catalog under -'PROFIBUS OP" and the relevant sub -catalog, e.g. ET200M. Click on the selected interface module (basic module) and drag il to the icon fur Ihe Df> master system. This SCreenS the properties shecl lor the stalion; here. you set the node address and

20 Main I'rogJ1lI'l

any diagnoslic~ addreSl<. Thcn the DP slave appean as an icon in the uppu section of the SUllion window and th e lower sc~tioD coma ins configuration table for this station. Now place the rruxl ules that you can find in the hardware catalog uml(', 'he .felected inlnfo", module (!) in the configW"lltion table. Dm:bleclicking"" the line opens the propcttie. shcct of the module and allows you !O pruameteriu the module.
Thc lower sub-window shows eitherlhc canfig-

for u '..-.anna l"' sl.8tion: insen I n S1 Stllti<m inlo the project using the SIMATIC MllTlager MId open the Hard",,,,.., ubJe~t. T>rng a mountU1Q: rack to the wind"w in the Hardwa,.., Configuralio n aod p lace tbe dcsin:;d modules. For con tiguring the Dr slave. it is enough 10 place Ihe CPU; you can add all other mudules later. Wb<.:n insertin g the CPU_ tbe propetties shetl of the PROFIBUS interface is screened. He"" you must ft'Uign ft .ubnr;1W<>1'k. 10 Ihc DP ;n.ufate and you must assign an addn'ss. If Ihe PROFI. BUS subnetwork docs nol )'ct exist in the project, you call ,"c alC u new One with the "New" b unon . This is the subnetworK to which the intelligent .lave wiU Inter be conn ected. You can open tb~ propenieuh""l of the interface by scle<:ting the DP in1Cl"fa.ce and then Enrr ..... OI:llFCT PROPEJl.TIES or by double-dicKing on the interface. On the ~Mode~ tab. select the o ption "'DP Slave". Now you can tonfigure the user dam interface un the "Conflguration lah from the viewpoint " f lbe UP ~lavc. Select MS (master/.lave confillur~tion) $S lh~ mude, Ktld detine tbe structure >md a<ldrcsscs of tbe tnmsfer intetfllce from the ~icwpoint of the slave C PU (Figure 20.11). Chapter 20.4.1 ...Addre ...~ ina PROFJBUS DP~ pro'icics information on the user data interfilce under "Transfcr memory 011 intelligent DP 5Ia,"es.
H

un"ion table of the selected 01' sia"c or of the nUI.Stcr system (toggle with the "arro,," bunnl\) .
I'ad.:inf{ addn:.ssC$
Digital cl..xtronic, modules witlJ 1"0 Oit channels... c.g. ET200S or FT200pro, initially OO;<;UPy uDe byte in the configuralion table. After Mil modules have been configured. you can US" the "I'ack add..."ses' bunon 10 remOve the )!:ap5 betv.cen the bit channels oflhe selected mudules und thus occupy fewer addresse.'. The addres, nreu for inputs, "utpul~ and motor starters a..., packed separately.
"pitcked~

Please note the following special fea=. of II module: Slot assigmnem is no 10:lger possible ; Ihe CPU cannot determine a geographical addre&.' for th;" module . No module ~ta1Us informulion for (his mod ule can be r~ad .
to a "pacKed" For thi~ reason. a d iagno;;\k, address is assigned for thJ.s module (iodicaled by italic. and &. star III the oonfiglffillion table). You can ~ceive intenupt infonnation .... de' thIs add~.
addres~.

I>

I>

> lnterrupts cannOI he assigned

The sizc and .troc!Urc ofthe mmsfcr memory is CPU-spilic. O n the CPU 315-211P, for exam_ p~e, you can divide the entire transf", memory into up to 32 addrcS5 a reas tl1<lt you can acccs~ :>cparately. Such an add,..,ss "rea Can be up to 32 b~tc<\ in ,ue. The eotire trltnSrcr memory can ha"e u p 10 244 input ad<Jr-.,:IS<;5 and 244 uutput

addres5C5. The addreSS<'.

drf~

hc-re :ott located in tbe

I>

"Pack add...,ues" an<l "loservn:rnov~ module intcrropt- arc mutually cxc 1m i,-e.

Cunfig uri"l: It CPU "lth integral DP interflloce u an inldU&enl OP ,IaH With an appropru<lely equtpped. CPU. you clLll p.a.ramcterizc tbe .Ialion ellher a..~ a DP IIlllliICf station or as D Dr s13~'e station. Before the Slation can be conn..xted as .. Dr slave 10 .. DP maSter system, il mUSI be create<l. The procedure for doing Ihis is uactly the same a, that

add",,,, volume of tlJe ~Iave CPU. ThC$e addresses must not o\erlap with a dcire,sc:i o f centralized or distribu tw modules in the f)P 91ave station. The lowest address o f a n address a,n is the "module ~Ianjng address".
Th~ uscr program in the .Iave CPU gels di agnostiC! infonnarion rrom Ihe Dr IIlaSler via the dialV'osri cs add...,ues specified on thi, tab.

You lo;nninatc configuratIOn of the intelligl'UI DP ~l"'e with STATIm< ..... SAVE _"'''D C0\1P1LE. <':onn~~ting the intelligcnl OP . lave into the DP ma.ter syslem is dcscribc:d below.

,9<

20 ,4 Communication via Distributed JlO

... ..".,,,~, , .. ,0."", 'I

-"~~-.~

....

I~'

,- ,,-

-. -. ...,
_090

11"_.. '

1
jop

ie-

" "
.oj

I>I-.-~~

~-

1 0
1 "'-

. -...- , -. _.
"~--

_ . ,

f-." ""'"

I'
I '~'

I"

"I
"

" "

--

11
, . .. R

'" "
"

FIgure 20 .11 Configuring the Tromfer Memory of an ImeHigent Slave "';th Im.gml DP Interface

Co nfigu r ing a n ET20 0pro an int.'U1ge n t DP sla\'e

a.

Configuring an ET200pro station is very simi lar to eonfigw-ing an S7 -300 ,tallon. Insen a SlMATIC 300 station in the SIMATIC Manager under the project and open the Hardware object
In the Hardware Configuration, drag the obj(X:t 1M! J4-8 CPU from the hardware catalog under "PROFIBUS DP" and "ET200pro" to the free w ind ow. or seleet it by double-dicking. On the displayed propenie, sheet of the Etherne t interface, set "not networked" ,

,ubnet does nOt yet exist in the proj(X:t, you elUl create one "'ith the "New" button. This is the subnet to which the intelligent slave will later be eOWl~ 'I~d. On the "Operating Mode"tab, seIc~t the option "DP Slave" The meanings of the addresses on tbis tab and of the addres, on the "Addresses" tab are described in Chapter 20.401. "Add ressing PROFlBUS DP" under , "Diagnostics address", Now you can configure the user data interface on the "Configumtion" tab ftom the viewpoint of the D P slavc , Sclect MS (master-slave eoofiguration) as the mode and define the structure of thc addresses of the transfer illlcrface from the viewpoilll of thc ET200pro CPU (Figure 20.11). You can find information on the user data illlcrface in Chapter 20.4.1, "Addressing PROFIBUS DP" unde r, "Transfer memory on imdligem DP slave,".

EDIT ----> OBJECT PROPERTIES in the case ofa selected interface X I, or double-dick the MPU DP interface to open the Prop~nie, window. On the "G~neral" tab. selcct PROFIB US as thc interface, and in the Propcni es window of the PROflBUS interface select the Slation ad~ss and the PROFIBUS subnct . If the PROFIBUS

'"

20 Main Program In the ~ o f Ihe 1 1$4.8 CPU, yoo ean di M vide Ihe enlin: transf.. r mfll'lo1')' imo I lOlal of 32 addn: ,9 . n: as thaI you can ace ..... $oCpBralely. Such an address a...,a cln be up 10 32 bytes in size. Th e entire transfer memory can enComp;l8s up 10 244 input addresses and 244 OUtpul
addn:llse8.

BUS $Ubnetwor1.: on Ihe "Gen....I" tab (Selecl "PROFIUC"S" in Ihe "lmerfaceOO bo~. and click the '"Amibute." bUlIon). Set the address ranges for the user d~ ta interface from the viewp<Jinl of tbe OP 51Bv~ al thi. point. Th~ maximum 5ize of the user data area is 32 byte. of inputs and 32 bytes of outputs for the 1M 151 CPU. You ~Bn d ivide this area into eight sub-areas with di fferent data consistency. The slave program receives diagnostics infor_ mation from the Dr maSter via the diagnosti cs
a~ss.

The loully defIned addn:nt'S are wilhin Ihe addre.~ vo lume of the ET200pro CPU. These add..., sseJ musl nol o verlap uddresses of The cen Iml or di~tributed modules in Ihe ETIOOpro 'Ia lion. The luwest ad<IrI:!.:I of an address 1n:3 is the " module 5tarting address". Further COnfIguralion of the ETIOOpro sliltion is carried Out in the same ,,"ay as that for an S7300 stalio n wilh fixed slol addressing. You can o nl y arrange Ihe modulel Ihal can be found in the hardware catalog undu l\.lI54-8 CJ>I;. You terminale confilluration of the inlelhlletlt OP slave wilh STAno,," ~ SAVE M.'D COMPILE. ConllC<,:linlllhe intellia;ent DP slave inlO Ihe 01' ma.sler system is de.cribe<! below. Conflllll ring I n IMI$I!CP (; .. an Inteiligeni DP sl t If you Wa nt 10 generate an 1"2ooS as an inte llige nt D P $I ave, flISt insert a SIMATlC 300 ~Ia lio n under the proj""t in tbe SIMATIC Manager and open the Ha,rI...arfl object. Now dnlg the obj"'" IM/JI/CPU umkr "PRO FIBUS 01'" and "ET200S" in the liardware Ca1alog to the free window or seleci it by doubl e-~Ii~k ing on il. If the 1M I 5 IIC I'U does not bave an ).11'1 jnlerface.the attributes window oflbe DP interface is displayed. SeleCI the node Bddress hen: and the PR OFtl.lUS mbnelWQ1'k (or generate onc and assign il \() the 01' interface). You will iICe a confiiUT8lion table like the ooe for a S IMATIC 300 ~talion. The inteHillenl 1).1 15 1 of the ET200S station is present be", instead oflhe CPU . Double-clicking on the lVl 151 Hne o~ns the window for \he 1M pro~rtics; double-clieking on the DP interface opens the propcTlles "'indow of the interface. If you have not already done so, 'el the node addresses and the PROFI -

Funher CQ1'IfIgumtion of the ETIooS 5t&lIon is carried OUt in the same way as for an S7_3oo stallOR wilh fi xed lilot addrcss inll . You Can o nly arrange tbe module$ listed in the Hardware Cataloll under "ThO[ 15 I!C PU . Scl""t 5TATIO:-; ..... SAVE M."IJ COMP1LE to conelude confIgurinll the intelligent DP sIH~e. Imeir8tion of the inte llillCDI Dr slave into tbe DP lPast ~ r ~y~te m iii de~cr i bed fim her bc low. C<m fli\uring In S7-300 stado n ... IIb C I' 3'(l-SDP a. all inttlJige nl . Ia,e [fyou insert an 57.300 ~t ation in the SI~1ATlC :.,ianager. open Ihe !Iardll"a,.., ohject and confiilurc a OOnonn~I" 57-300 station. Among oth er things, you lrnmge a CP 341-5DP communicatiOnli processor in tbe eonfiguration table. When in.minll the station, the properties sht oflhe DP interlace appears; the subnetworl: to whit:h the intdligent DP ,lave is later to be connected is 10 be assii'!oo to the 01' interface he re and you must aloo ,uian tbe nod<: address. To opm tbe propC1"lleS "indow, ,..I"t the CP 342.5DP and tben Eon ..... OBJT.CT PROPERnts. ordouble click On the CP 342.S0P. Selc~t the option '"OP Slavc" on the "'Mode" tab . The "Addres~" lab 5hows the user data inlerface from the vi"""'potnl of the .Iave CPU (Start ing address and 16 bytes in leDgth). The size o f lile Imusfer memory on the CP 341-501' as DP sln"e is up to 86 bytes. and you can divide this into different address IlI"cas aft..,. connection to tbe master system. STATION ..... SAVE M'D Cm{PILE Icnninales CQ1'IfIliuration of the intelligent OP $)8ve.

".

20A Communication via Distributed t/O

Co nn e cting an int ell igent DP slave to a DP master You must have created a project and configured Dr master station and the intelligent Dr slave (in each case al lea,t with the Dr imcrface). The DP master ami tbe DP s lavc must be configured for the same PROFffiUS subnet;v.'ork.

this PROflBUS subnetwork arc listed on the "Connection" mb. Select the desired slave and click on the "Connect" bulton. The active connection is then sho"'ll further down in the Same dialog box. 'Vhen the DP slave is selected, its configuration table is shown in the lower section of the . talion window. Now you structure the transfer memory: select the "Universal submodule" rrom the h ardware catalog (un der the CP used), drag it to a line on the configuration table. or select a line and double-click on the "Universal submedul e'. You p lace one un iversal submodule for each individual (consistent) addrcss area in the transfer memory: the maximum number is 32 . To open a window in which you define the propertie;; of the addre ss area, select the universal submedulc and then EnrT ---> OBJECT PROP_ ERTIES. or double-click on the line in the table ; space. input or output area or both . Detcnninc the staning address and the length of the area . The addresses defined here are located in the address area of the master CPU. An area can b e up to 64 bytes: the maximum overall size of the transfer area is 86 bytes. If a CP 342 -5DP is the DP master, structuring of the transfer memory can be omitted because the CP 342-5DP transfers the entire transfer area m one ptece When d ividing the transfer memory. you arrange the address areas together without gap' staning from b}1c 0. You acce$S the ~'T1tire assigned transfcr memory in the slave CPU with Ihe loadable blocks FC I DP _ SEND and FC 2 DP _RECV (included in the Standard Library under the Communication Blocks program). The data cons istency covcn; the ent ire tran.fer memory.

Open the ma.tcf station; u Dr master system (brohn b lack-and-while bar) must exisl, if not. create it with Ix ,I;RT ---> MASTER SYSTEM .
In the hardware catalog under "PROFIBUS Dr" and "Configu red Stations', you will fmd the objects that represent thc intell igent slaves : "CPU 3lx" or "CPU 4 1:><" represC11ts S7-300 or $7-400 slations with an integral DP slave, "ETIOOpro/CPU" and "ET200S!CPU" reprcS~'T1t stations which were configured as DP slaves, and "S7-300 CP342-5 DP" t epresents 57_300 ,tations with CP 342-5 as the DP slave i~tetface module. Select the desired s lave t)--pc: and drag it to the DI' master system .

CPU, ET200pro or 12005 as DP slave


Dragging to a Dr master sy,tom Or doubleclicking on the DP slave opens tbe properties sheet. The slaves already configured for this PRO FIBUS subnetwork are listed on the "Connection" tab. Sclc~t t~c desired slave and click on the "Connect"- bUllon . This causes the active connection to be carried oUl at the bottom ofthe same dialog box . On the "General" tab. yow set (he diagnostics addr~sg oflhe DP slave from the viewpoint of the master station On the "Con(ig"ration" tab, you now set the addresses of the user data interface from thc viewpoint of the DP master. The output addresses on the master arc the input addresses of the slave and vice versa. Chapter 20 .4.1. "Addressing PROFIBUS DP" contains mOre infonnation on the user data int erface un der "Transfer memory On intelligent DP slaves"-

On th~ "General" tab, you set the diagnostics address of the DP slave from the viewpoint of the masler station. The diagnostics data are read with FC 3 DP_DIAG (in the master station).
Chapter 20.4.1, "Addressing PROFIBUS DP" contains mOre infonnation on the user data interface under "Transfer memory on intelligent DP ,laves".

CP 342-5DP as DP slave
You open the properties shect by dragging to the DP master system Or by d<Jublc-dicking on the DP slave. The slaves alftady con fi gure{! for

20 Main J>roaram Conngu ri ng


Ih~

DPID P coup ler

VP/ASj Link 20 "Drag'" the Dr AS; Link 20 from the hard""arc cataloa to tbe bar ofthc PROFlBUS DP master system. In the displayed windows. define fiTSt the pn:SCt configuration ( 16 or 20 bytes), and !hen Ihe node addre", . On the DP/A S-i link 21), you eRn define 16 bytes of inputs/outputs as the selpoim configu_ ration. with an addi1ional 4 bytes for control conunands . In the latter case. the lower s""tion of the windo,,' in the Hardware Configuration suggests 16 bytes of u.ser data with addressc5 in the process image and 4 bytes of comman<ll with addresses from, c.g. S12. Sel""t the DP slave and then EDIT --+ OBJECT PROPERTIES, or double--click on the DP slave, to opcn a window in which you Can ehanae Ihe addresses suggested by the Hardware Confign_ ration and also set Ihe subprocess image. provided you have a suitable CPU. Select the DP slave and then EOlT --+ OIIJECT PP.OPER TIES, or doublc--click on the Dr slave. to open Ihe slavc propenics window. On the "Parameterize" tab. you set lhe parameters of the ASi slavC'S. with 4 blls for each slave. DP 'AS-i Link Ad"anced "Drag" the DP AS-i Link Advanced - e.g. the double rnast~ 6GKI 41S-213A20 _ from the hardware catalog to !he bar of the PROFlliUS DP master system. [n th.., displayed window. set the propenics of the PROFIBUS inK.,.face. A ~onfigurntion I8ble with the AS-i inlerfaces and AS-i slaves for the two masters appears_ Now selthe address area under which you want to access the ASi slaves from the user proilfMll. EDIT ... OBJECT PROPERTIES with a se lected AS-i master interface (in the COnfiguralion table), or double-click on the master hne to open the propenic-s dialog. On the "Diaital Addresses" mh. set the start address and lhe area lengths reserved for inputs lIDd ootputs. This tab also eontD.Jru the "Pack llIld "Son huttoM with "lUch you can optimize the ad<ircss aSlli gnments after yoo ha'-e coofia;ured the AS-i sla\cs.
H

The DP/OP coupler connects two PROFIIlUS subncts. It is configured as a modular Of> slave in caeh ofm., two liubnets _

f>rcrcquisHe: Both subnets, each "jIb a DP maSlcr system. muSl bc configurcd. Open one ofthe Slalions w,lh Ihe DP master. In tbe hardwart' catalog under "PROFIBUS Dr" nnd "Network component .... you will find Ihe DPI DP coupler. Release 1 that you can dralillo lhe DP masler system with the mouse.
The properties sheet of me PROFlBUS inler_ face appeaJ"ll on wlUcb you set the node addre$li. You II<:t the diagnostics address and funhe. paramelers on the "Parame!en;~ tab in !be object propenies oftbc DPIDP coupler.

With a $elected DPIDP coupler. the configuralion tablc for the t"'!!.'i fer memory appears. Now "Coon.,.,t" the desirt'd modules listed in the hardware calnlog under DP/DP coupler into the configuration table. without gaps and s1arting u\ SlOt I. You ~an set tbc universal module to the desin:d number of inputs and outpUts. The uscr data addresses tha! you spedfy in the module propenic! are in the addro:ss are. of the opened Dr master CPU . Configure lhe seond pan ofthc DPUP coupler in lhe .same way. The structtIfl' of tbe tfamfer memory must agree with that of the first part. Please note that inputs on one side are outputS on the other side. and vice VcrM. The addresses in bolh parts of the DPIDP coupler arc oriented to the address assignments of the relevant mas ter CPU and can differ from each olher. Configuring t he DP/AS-; lin k You eonfi auTc lhe DP/ AS-Interfaee link like. modular DP slave_ Yon will find th~ moduks that yoo can drag 10 the DP master system. such as the DP/AS-i link 20 below. in the hard W8n' catalog under "PROFlliUS 01''' and ';DP ASi", Then yoo set the propcnie! of !he DP section aod configure the AS-i sla,es dcp<.:odina on the link on the propenics shel'! o r in the configuration tabie_ The AS; master sy5lem with the ASi sl."es is not displayed as a subne. by the hardware confiiUTRt;on.

No", "drag" the placeholder for lUI AS; slave positioned under the link frorn the hardware

'"

20.4 CommunicauOll

ViM

lJi'lJibuted IK>

~-

-'._':,=~=::;~~::::r'~'~'~'~=====::~n
II_ ~
:I Ill_ I, ,. 3
e-o '

~-.-

r ll'--~""""''''''

--

-,

_ F ""

.... R_"'.....
"0.0 , ."

calaloij to Ihe configuration lab le . R~at Ihis procedure for all scheduled AS_i .Iaveo. EOIT-I> O!iJTT PROI'F.RTTE~ with a selected AS-; !lav'" (in the configuroliOD lable). Or double-click on th'" slave linl' 1 oJ>C'o the properties 0 dialog. Sct the slave proJX'nil'5 on Ihl' ''Configuration" lab. Clid "Selection- [0 view all the AS-i sillves Jtnm,.."II to the HllI'dwarc Configuration (Figure 20. ]2). 20.4 .3 S p, clal Functions for PROFlBliS 1 )1>

OPTIONS -I> INSTALL GSD FILS in the Hardware Configuration and specify the directory of Ihe aSD file or another STEP 7 project in the window thllt ..ppears. STEP 7 accepts Ihe GSD file and displ ays Ibe slave in thc hardware catalog under "PROFIDUS DP" and "Addil;onal Field Devices-',

STEP 7 save. the GSD files in the di,..".,tory , .. \Step7\S7DATA\ GSD, The OS O files deleted when inslalling or imponing al It IDler lime arc slor~d in the subdirectory ",\tiSD\DKPx. FroIO h~re, they ~an be restored wilh OM'!O}.'S -I>
INSTALL aSD FILE.
Conn ~urlng

Gsn tIIn
You can "post ;nstal!" DP slaves that arc 001 included in the modulI' Cala]og. FOT this purposI'. you requi...., Ihe type file taIlored to the sla~'e (O SO file. General Station Description. device database file). From GSO ,'enion 3 onwards, DP slaves in.talled w,lh a GS O file ,uppon Ihe DPV I functionality. Sele\:\

SYNClFR[Zl: grollps

The SThC control command caliSCli the DP 51Bv.",. combined as a f'OUp 10 OUlput their oulput stales s.imuhanoollsly (synchror>ollsly). The FREk:ZE conlrol command causes the DP slows combi ned as a group to "freeze" the cur-

""

20 Main Program rent input signal s!ates simu ltaneously (syn ehronous ly). in order to allow them to be then fetcbed cyclically by the OP master