LAD FBD HansBarger

Embed Size (px)

DESCRIPTION

Simatic S7-300 Programming

Citation preview

Hans Berger

Automating with STEP 7 in LAD and FBD51MATIC 57300/400 Programmable Controllers

SIEMENS

HansBerger

Automating with STEP 7 inLAD and FBDwooer 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. A19100 153HI951-X_7600 4" edition, 2008

Publicis Corporate Pllblishing www.publids ..Jelbook~

-

Automating with STEP7 in LAD and FBDProgrammable Controllers

51 MATIC 57-300/ 40 0by 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" Jltnltioos in book. ".".d publi.her are ah.",YJ valefu! 10 bear your "'SJIODSO> 10 th~ conlen'" of me book. PubHcij CorporolC PubliMrina: P.O. IJ.ox 32J REAL numb.:rs:

(PROFIfIUS QP): Cooununiu>; Count up. Count down, SCI, Reset.nd Sc"" Count""'; IEC CountIT Function, 14 Word Lo~i< l'ro;:e;sin& AND, OR and &d""i,'. OR Worrl Logi28

86 87 8890 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 LogieOp~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

'.23.2.1 3.2 .2 3.2 .3 3.24

" 9899

.. ..

'"

' 39

3.33.3. ! 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.73A

Programming Code Blocks Open ing Blocks Block Window . Overview Window. Programming Networks . Addressing. Editing LAD Elements. Editing FBD Elements. Programm ing Dma Blocks . C!"Coo

1:-.< .{,ll

Loc. l "'1llI" up'u 5m witt""" ~ Vtr:.rwniMiOIl (l\t46 j-{))

R omot. Ikperlding on me vcr;ion. they alrtady contain:~

In\cgral liOs Digital and analofl inputs/outputS Integral technoi

Counting. mCaliurcmCIl1, control. po,itiooingI>

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

1.\ .3

S7-400 Sta lion

Ctnrrallzed eonlieunli()nThe 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

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 \ 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\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 .\licrom. 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 (contlgurationdataonlinel

System

Sym~

+llt 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 Disuibtnense 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 . 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.

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 systemA 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.3Actuator/SensorlnlHrac~

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

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"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; (FB). S7 ""(Immunic,tion. can be: c~ccutcd o,er the Ml'l, PROFlBUS anrll.ndu>tri~1 Elhe rnet subnel s.

fF: communlcatlonWiLh "'Optn eommuruclttion via lndu5lrial Eth,,",cl (IE communicatiOn fO'l" shon). you tJ"r limit ,pecifIC to I.hc CPU With digital mooules, the individua l signals (the individual bil

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 CKCs 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~,. instruetiolliox 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 tranl1ZE 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?rmooules. ,,~

Confogura tk> table

C IEC Function Blocks2. 1.4Proj ~cn

and lib ra riest>

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

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

> PID Control Blocksblock!; 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 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>rojeed 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~"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 lindarran 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

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

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() controller10 which the 10 device ;$ to be assigned. Find Ihe 10 de,'ice in !he network obje 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'') ort>

the communications SI"'lATlC 57 device ,

panner

i,

not

a

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 connecrvc 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 : 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 . ,, ' you transfer the SIoLIClloU STATIONS

STM"'l"IC - I STEP7 --> LAD. STL. FBD - PROGRAMMINU S7BLOCKS.

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' 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 .... 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 seleo: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 AddresSd without symbolspo

To generale n;f 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 LOClt3rt 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 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 -"1ANAGl' MLIl.m.lNGUAl TEXIS --,> DELETE LANGUAGI'. 'fable 2.2Tnt type, uf tho rran,1ated tens (se lection)

Exporting mId impmti,,!; /exlsSelect 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 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 sdetec 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>. o C STOP). mooific;aTion of the oP='ting mode

-+ CLf.ARlRES ETRcs.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 111pCned 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'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 eompe." 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 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 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 ...,'SCRT ..... S7 BLOCK ..... VI\IUNlU! TtillLL. and you cltn ,en~-r~IC Iln unn..mcd VAT online by selecl ing S' Program and 5."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 InD..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

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

"._......

.,

.

.,.,'

I

" ' 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)

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

f>

(>

96

3.\ PmgramProcessing

T~bl~ 3.1

SJMATJC S7

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

,,0"

Modifiable .

,.modulosWi 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

ORRIOB~5

toOB ~4, g6.g7

:~~c c. cfailure,

.

Sloer",' .

OB

~8

26 2) 2 5 2) 25 ) '

'" " '"

" "

2 to 26 2 to 28 2 to 26No

2 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

Us~r

In extensive an d complex program"

The initialization A 1()C1I1 ;n.1III is younger than the callinginstance (affect. function blocb).

> A user data type UDT is )'OWIgCf than th. block who:se ">riables an declared with the UDT: Ihi~ can b"'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

I

.".......""... ' :""']

ot'" ('" """'~l OI' !"I':

Fi~Dr~

3.4 Exomplc of!h< Repr< oon"'tic" of the 'Check Block Consistency" [kpc 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 depcndcnollc addressingIf you want to use symboli~ names tor globa lop~>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 cntsign a name for the n~twork template and you define lhe ,torage location (SmDolATIC 57 l'roi""m

](" symbol is nOi yet iru;luded in the symbol tIIl*_)OU Can scle

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 orV 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 ILaddr~,s _ ~ya)ua!ing

Th~re

are simpk

box~,

}\;jd ftu-",'i

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 boxAND or OR boxes via the END output.

If Y

!>

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, .'

m

3 SI).IATIC S7 Prugnun 3.4.1 CTnlTing Data Blockst>

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-enien! parameterization (...., Ch.aplcr 2.1.8 ~onj:oring and "'lodif~"U1g Data Addf(;s~s,. The datH ~ie"'s are d~riboo bk

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 cUC' 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 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 dataman"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 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 Types3.5.1 Generul R~mal"l

Local variahl~d 'y""'xJ;Cd#y,

01"".

Va_a ble i

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 digi1aloutputmodu 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'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. 18VAriables 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 5contains byle, 20 and 21 Variables uf

DatatYP

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 aring

Q 16.4

Variabl e, of data type BYTE ha"e as abwlUlc address the address identifier and tt.c number ofQD, 2"

I

,

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

I

I

QW2S

F11:IlN 3.1.tByte Co ntent! in Woru.; and Double" ",, 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 ing including the dat;, bk>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.EPl~ 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, ofa 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 Parameter types Table 3.4 ~hOW5 the pro~rties of Ih.,. d>.ta Iype das5signment 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"sed.

pos~i blc

w ddin~ an empty string" a~ the in i_

Th ig speci fication ~"n abo be omitte 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 assor 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 sIIu,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

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 J. coli

Ii I I I~I IN_ork2 N_twork 3

,..rwork , laCn

"'")--I 1INOTICoII2

Contact1 Coil1 Contact1Col 1 2

II I

I I I I

I

I

1 )--IColl3

-,

n nI C

~_:~tet2

I

ICoon, "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 opO')' oox is retained. Thi~

RS rncm(lry functiouill 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 pri is e"C"CUIW (you ""iI! find dct3.ile

Mati onSwit~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 tcsTUllO ....

You use the move fun '" '"

(n+1 l

01By... n 01Bu"', 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 LFun~tI"nz~roes.

A

byte or a word at OUlpu! OUT j~ mnove! input double"ord

LWn

LD.

Moving a local data byte Moving: a local

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 bloclpenInds - wbleh may difT..,- from the IeNal value~ in wor~ memory - ar~ prcnt 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:

''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=>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'rGcn~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 0>:)

TIme< operllrld

II

~l ,ure

7.2 Individual Elemen .. of. Timer (LAD)

--'"7.1.2

- 'N'N

MOVE

'NOOUT

Digitalopet1Ind

In d lvld u l l p rog ra m elemenu In }" BD

For incremental programming, you wilt findthe 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 isthen ~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!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.3Spetaol. L. word operand, n. as vKri~bl . oflype SjTJME.

Spcnous updating will prevent the Oite cbcck resuh as the one produced by a che 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_ 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: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

SFB I CTDDo"'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.:owl R _Network 2 Activate monitoring

Dural

Lbarrl -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 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 ofTobIe ~ .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";

Range violation (overflow) in tNT amiDINT 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 divideN,

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 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,\"Tdl'" !~!on

10.3 Calculating with Data

T~'p",

DINT011\, 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 nnmber1 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)-pR

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}.,'TIIiln~li on).

The Dl R funclion dm's not

r~porr

errors,

12.3 Com'ersion of BCD Num hersTable 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"llmbersTh...,.~

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 Rounding1'0 "." h igher

'"'CHI. flOO R ROUND TRu'lC

Data Tyl''' forP...-.-wxl~~

0""DINTD~"

om.

RFAl~

ialle : .hi ll ", lenlAD , 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 Gxcti"IlS Sh ift left Shi ft right S hift w ith silfll \(otat. left I{otat. right

Word

'"' '"R,~

W

SIll._ [JW,,~

,

W

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

" ' "0SHR_ OW "G lobal DB". ShiltOff-

0"'

-

MW132

Shifting doublewordvariabl~.

" 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

M

rung (LAD )

You ~aTl e mlTl ee 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'Il " dummy" operand 10 lhc coi l. for ex"", plc a temporary local data bit.VOl' can esult 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 nsAN 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 BitsTable 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 bie1 ~. 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

!FeRLOSTAOR BR

first Chock Re.'T

:>

222

15.2 Sel1ing tile Statu S Bits

T"b.llo 13.2 S otting the Statu. B it>

I..'OT calcul.tionThe ",.uit is:

DIl'iT c alculotlon

ceo

CCI

< 32768(ADD_ I. SUB I)+32 767 (ADD I. SUIUJ ,. +32 767(MUL_TJ)2 76H{OJV I)

" ," " 0 ,0

( )65 536 Division by Uco

, " , , ,0 0

0

" , , , , , , , , , ,

"

-1'0-2147483647 >+2 14 7483647 (ADD D J. SUB 01) >+214748 3647

(MUL DI)

2147483648(DIV_ DI)

H " 194 967 296Di v i,ion by >:oro (DlV 01. MOD 01) Comp. ri.on

, , , , , , " , " " " , " , " , , " , , , , , , , , " , , , ,

ce. ov

0;

0

0

0

0 0

JU:AL c.lculation

The ,e CC,0

OV0

t"with shift nOln be. 0

" , ".

"ronot zero

.

0

,

,

.

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

FROrcprewnlation

A cu=nt OOW$, o r the check

is fulfillw wben

-1~> 0

-H~

--I f 00 bUI Si.

LAD representatkmA.Uv.te MeR .",a

a singk coiior assign box and 3 midline out-

Open ;I.(C(( .onet>

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

FBD

r ep'a~entat i oo

t>

A.Unt. MCR o",a

-------l MCR< IIMCR>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 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 CRdependency 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 dcpenH ,:(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-{.''"

MCR>MCRD

I

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 BinDespite enabled MeR dependency, yuu can .et or rc~"'t the bilS of an JlO I'll'a with Ihc syslemfunctions. 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 =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 restem 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 prC10 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 "!> !>

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,,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 ParametersWhen 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 paramf 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 "-'

." "

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

UpdaTing o f the proces, image; depend~'Jl t OIl (h~ number o f byres to])., updatcd Updal ing of the tim~'fS; dc!)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 PARTRCTV~

Para mct~ .,.

[OT the SFC, rOT ?roc" l.J.na~e Upd:>,ingDe.:!arationD.", TYl> in Mul,iproces>or Mode

The CPU s in a multiprocessing ne1,,'ork all have the sam e operating mode. This meanSt>

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 prgmmWh~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 ' '''luestSFC780a ii

o!

DI I

I

o

I

@

OI I I I

(OS_NOa xx)

I I' ....

II I I I II I I I

III

oI I

o

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 cause0

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 mtIII_s . . U _ In 0/01 4 and

E837

A8 506 00& .. 0AB~!

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":o 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 dra