Top Banner

of 27

PRO1_11E [읽기 전용] [호환 모드]

Jun 02, 2018

Download

Documents

Nguyen Anh Tu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/10/2019 PRO1_11E [ ] [ ]

    1/27

    Contents Page

    Introduction .................................................................................................................................... 2

    Temporary Variables ........................................................................................................................ 3

    Local Data Stack Size ............................................................................................................... 4

    Byte Requirement of a Block in the Local Data Stack ................................................................. 5

    Total Occupation in the Local Data Stack ...................................................................................... 6

    Exercise: Use of Temporary Variables ........................................................................... 7

    Example of a Message Display Indicating a Problem in the Process ............................................ 8

    Parameter-assignable Blocks ......................................................................................................... 9

    Declaration of the Formal Parameters ........................................................................................... 10

    Editing a Parameter-assignable Block ....................................................................................... 11

    Calling a Parameter-assignable Block ......................................................................................... 12

    Using the EN/ENO Parameters with Block Calls .............................................................. 13

    Exercise: Creating a Parameter-assignable FC Block ................................................................... 14Exercise: Calling a Parameter-assignable FC Block ...................................................................... 15

    .................................................................................................................

    Function Blocks for Message Display .................................................................................. 17

    Generating Instance Data Blocks ............................................................................................ 18

    The Multiple Instance Model .......................................................................................................... 19

    Inserting/Deleting Block Parameters Later On ............................................................ 20

    Corrections when Calling Modified Blocks ......................................................................... 21

    Exercise: Editing a Function Block ................................................................................................ 22

    Calling a Function Block and Testing It .......................................................................................... 23

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 1

    onver ng an o an us ng a ource rogram ..............................................................

    Converting an FC to an FB using a Source Program (2) .............................................................. 25Exercise: Recognizing Types of Variables ................................................................................... 26

    Summary: Block Calls ....................................................................................... 27

  • 8/10/2019 PRO1_11E [ ] [ ]

    2/27

    General Up until now, the inputs and outputs in the bottling plant were addressed with theirac ua parame ers. ou cou no ass gn parame ers o e oc s.

    You would choose this procedure, for example, for the creation of a program that is

    only used once with a special machine.

    For frequently recurring functions in larger systems, you create universally useable,parameter-assignable blocks (FC, FB). These have formal input and outputparameters, that are assigned actual parameters when the block is called.

    The adjustment of block functionality to the hardware takes place with theparameter assignment when the block is called; the inner life" of the block does not

    .

    Local Variables Up until now you have used global variables (bit memories and data blocks) to storeproduction data, for example. In this chapter you will find out more about datastorage in local variables.

    Temporary Variables Temporary variables are variables that are only stored while the block is beingexecuted. They can be used in all blocks (OB, FC, FB).

    a c ar a es e a a are o e re a ne even a er e oc s execu e , ey mus e s orein static variables.Static variables can only be used in function blocks.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 2

  • 8/10/2019 PRO1_11E [ ] [ ]

    3/27

    General Temporary variables can be used in all blocks (OB, FC, FB). They are used toemporar y s ore n orma on w e e oc s e ng execu e . e a a are oswhen the block is exited.

    The data are stored in the L stack (local data stack). It is a separate memory area inthe CPU.

    Declaration You define the variables in the declaration table of the block. In the line "temp" youenter a variable name and the associated data type.

    You cannot predefine a start value here.

    er you ave save e oc , e memory oca on n e s ac s sp aye n e"Address" column.

    Access In Network 1, you see an example of the symbolic access to a temporary variable.The result of subtracting is stored in the temporary variable result".You can also make an absolute access (T LW0). You should, however, try to avoid

    this since the program is difficult to read.

    Note Variable names that begin with the special character # are local variables which# are only valid within the block in which they are declared in the declaration table.

    The Program Editor automatically enters the special character.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 3

  • 8/10/2019 PRO1_11E [ ] [ ]

    4/27

    Local Data Stack The local data stack (L stack) is a memory area that contains the temporary

    .

    Local Data Stack When the operating system calls an OB, an L stack area of 256 bytes is openedSize up while the OB and the blocks called in it are executed.

    Every priority class is assigned 256 bytes.

    The L stack of the 313..316 CPUs has a total of 1536 bytes (1.5kByte).

    Priority Classes There are a total of eight priority classes with the S7-300. However, no more than

    6 priority classes can be active at the same time. If, for example, OB 100 is active

    (with priority class 27), then OB1 (priority class 1) can never be active.

    Furthermore, the error OBs 80 to 87 for asynchronous errors can only then have

    priority class 28, if the fault occurs in the startup program. In other words, when

    they interrupt OB100. More information can be found in the chapter "Organization

    Blocks".

    S7-400 With the S7-400 CPUs, you can decide what the size of the local data stack is forthe individual priority classes (Tool: HW Config.).

    . ,make more local data available to the other priority classes.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 4

  • 8/10/2019 PRO1_11E [ ] [ ]

    5/27

    Displaying the You can see the exact number of bytes a block requires in the local data stacky e equ remen y go ng n o e oc proper es.

    Activate 1. In the SIMATIC Manager, select the block with the right mouse button andthen -> Object Properties. or

    2. In the SIMATIC Manager, select the block with the left mouse button and thenthe menu options Edit -> Object Properties.

    Notes The sum of local data for an execution level (OB) is a maximum of 256 byteswith the S7-300. Every OB itself always takes up 20 or 22 bytes.

    .

    If more than 256 bytes of local data are defined in a block, the block cannot bedownloaded into the CPU. The transmission is interrupted with an error messageThe block could not be copied". Within this error message is a "Details" button. Ifyou click on it, a message box appears with an explanation Incorrect local datalength".

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 5

  • 8/10/2019 PRO1_11E [ ] [ ]

    6/27

    Total Occupation in You can display the number of bytes an entire program requires in the local" " .

    in the chapter Troubleshooting".

    The total occupation of the local data stack and the number of bytes required percall path is displayed on the screen.

    Activate In the SIMATIC Manager you select the block folder and then the menu optionsReference Data Options -> Reference Data -> Display.

    CPU, the CPU goes into the Stop mode. STOP caused by error when allocatinglocal data" is entered as the cause of error in the diagnostics buffer.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 6

  • 8/10/2019 PRO1_11E [ ] [ ]

    7/27

    Goal You are not to use any bit memories as temporary storage in the FC 19 block of the" " "program . ese are o e rep ace y a emporary var a e ac ages .

    If you wrote a program for the block in LAD or FBD, the bit memories were

    necessary to connect the output of the divider with the input of the code converter.Even if you wrote a program for the block in STL (where no bit memories arenecessary) insert the temporary variable Packages" for storing.

    What to Do Open the FC 19 block in the S7 program "FILL" .

    Define a temporary variable with the name Packages" and the data type"Integer in the declaration table.

    Store the number of packages in the temporary variable.

    Download the changed program and test it.

    Result You now know the use of temporary variables.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 7

  • 8/10/2019 PRO1_11E [ ] [ ]

    8/27

    Description Problems (disturbances) that occur are to be displayed by an LED on the operatorconso e. en e pro em . occurs, e . or . s o as w2Hz. The problem is detected at the acknowledge input I 1.2. If the problem is

    corrected, the LED stops flashing. If the problem continues, the LED switches to asteady light until the problem is corrected.

    Program So that even problems that only exist for a short time are not lost, a dominant set flipflop (M40.0) is used.An RLO edge detection of the message signal is also carried out, since the memoryis otherwise immediately reset when an existing problem is acknowledged.

    If the report memory is set (message has not yet been acknowledged), the upperAND logic operation causes the LED to flash. With this, the bit memory M10.3, thatwas defined as a clock memory when parameter assignment was made in the CPU,is gated.

    The lower AND logic operation is used to cause a steady light for a problem that isacknowledged but still exists.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 8

  • 8/10/2019 PRO1_11E [ ] [ ]

    9/27

    Introduction You can use parameter-assignable blocks for frequently recurring program sections.s as e o ow ng a van ages:

    the program only has to be created once

    the block is only stored in the user memory once and you can call it as oftenas you like

    the block can be programmed with formal parameters (input, output or in/outparameters) and only when the block is called is it given the real addresses(actual parameters).

    Example When the block is executed, the statement A Disturbance input" is checked to seewhich actual parameters are assigned to the formal parameter Disturbance input".If, when the block is called, I 1.4 is lined up as the actual parameter, then thestatement A I 1.4" is carried out.

    FC / FB Parameter-assignable blocks can either be FCs or FBs.

    Parameter- In the example, the message display is required ten times in the system.assignable FC20 It is created as a parameter-assignable FC 20 block and is then called ten times

    with different actual parameters.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 9

  • 8/10/2019 PRO1_11E [ ] [ ]

    10/27

    Formal Addresses Before you can create the program for the parameter-assignable block, you have toe ne e orma parame ers n e ec ara on a e.

    Type of Parameter In the table in the slide, you can see three possible types of parameters and theiruses. Please make sure that when you have a reading and writing access to aformal address that you use an in/out parameter.

    Example of the FC20 In the lower section of the slide, you can see the declaration table for the messagedisplay (see previous page). Since the report memory is to be accessed reading(set/reset) as well as writing (query), it has to be defined as an in/out parameter.

    Notes There is only one row for every type of parameter in the declaration table. Shouldyou need several input parameters, you have to use the "Return" key when you endyour inputs in the first row. An additional row for this type of parameter is thenopened up. After you have selected a declaration row, you can also use the menuoptions Insert -> Declaration Row -> Before Selection / After Selection to insert an

    additional row.

    -been called - , you have to update the block calls !

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 10

  • 8/10/2019 PRO1_11E [ ] [ ]

    11/27

    Notes It doesnt matter whether the names of the formal parameters are written with" "cap a or sma e ers. e c arac er n ron o e name s au oma ca y

    inserted by the PG. This is to indicate to you that it is a local variable that was

    defined in the variable declaration table of this block.

    It is possible, that when you write the program in LAD / FBD, that the name is notcompletely displayed in one row. This depends on how you customized the settingsin the Program Editor (Options -> Customize -> "LAD/FBD" tab -> Width of addressfield).

    ym o s . you use a sym o c name w en you e a oc , e or searc es evariable declaration table.If it is there, the symbol with the # in front of it is accepted in the program asa local variable.

    2. If it cannot be found as a local variable, the Editor searches the symbol tablefor global symbols.

    If it is found there, the symbol is placed in quotation marks and is accepted inthe program.

    3. If you specified the same symbolic name as global (in the symbol table) aswell as local (in the variable declaration table), the Editor will always insertthe local variable.

    If, however, you want to work with the global symbol, you must place thesymbol name in quotation marks when you make the entry.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 11

  • 8/10/2019 PRO1_11E [ ] [ ]

    12/27

    Call In LAD/FBD, you can select the call from the "Program Elements" browser.ues on mar s . are sp aye a e npu , ou pu an n ou parame ers o

    the block. Here you insert the actual parameters you want.

    Note When you call a parameter-assignable FC block, you must assign all blockparameters (with the exception of EN and ENO).

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 12

  • 8/10/2019 PRO1_11E [ ] [ ]

    13/27

    Standard FCs The following rules exist for the execution of standard FCs:

    If EN=0, the block is not executed and ENO is also =0. If EN=1, the block is exeucted and if it is executed without errors ENO is also

    =1.

    If an error occurs while the block is being executed, ENO becomes =0.

    User FCs It doesnt matter whether a user block was written in LAD, FBD or STL, when it iscalled in LAD/FBD, the parameters EN and ENO are added as well. Thus it ispossible to pass on the RLO.

    EN/ENO do not exist in STL. You can, however, emulate them.

    You must program -irregardless of the programming language- an error evaluation.

    Interconnection In LAD/FBD, several boxes can be grouped together one after the other and linkedlogically with EN / ENO.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 13

  • 8/10/2019 PRO1_11E [ ] [ ]

    14/27

    Task Write the program for a message display as a parameter-assignable block. In thes e you can see e ec ara on a e w e npu an ou pu parame ers an ebeginning of the program.

    What to Do Insert an FC 20 block in the S7 program "My Program" . Write the program in FC 20. Save FC 20.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 14

  • 8/10/2019 PRO1_11E [ ] [ ]

    15/27

    Task Call FC 20 in OB 1 twice (with different absolute addresses). Test the functionalityo e program.

    What to Do Insert two networks into the OB 1 from the S7 program "My Program". Create the two calls to FC 20, as given in the slide, Download the FC20 and OB 1 blocks, Test the function.

    Note: During HW Config, you used MB10 for parameter-assignment of the clockmemory byte. If you have performed a memory reset in the meantime, you mustdownload the HW configuration once again to cause the M10.3 to flash.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 15

  • 8/10/2019 PRO1_11E [ ] [ ]

    16/27

    Special Features Unlike functions (FCs), function blocks (FBs) have a (recall) memory. Thato s means a a oca a a oc s ass gne o e unc on oc , e so-ca e

    instance data block. When you call an FB, you also have to specify the number of

    the instance DB, which is automatically opened.An instance DB is used to save static variables. These local variables can only beused in the FB, in whose declaration table they are declared. When the block isexited, they are retained.

    Parameters When the function block is called, the values of the actual parameter are stored inthe instance data block.

    If no actual parameters are assigned to a formal parameter in a block call, then thelast value stored in the instance DB for this parameter is used in the programexecution.

    You can specify different actual parameters with every FB call.When the function block is exited, the data in the data block is retained.

    FB Advantages When you write a program for an FC, you must search for empty bit memoryaddress areas or data areas and you must maintain them yourself. The staticvar a es o an , on e o er an , are ma n a ne y esoftware.

    When you use static variables you avoid the risk of assigning bit memoryaddress areas or data areas twice.

    Instead of the formal parameters Report memory" and Edge memorymarker" of the FC20, you use the static variables Report memory" andEdge memory marker" in the FB. This makes the block call simpler sincethe two formal parameters are dropped.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 16

  • 8/10/2019 PRO1_11E [ ] [ ]

    17/27

    Message Disp lay In an earlier exercise you created a parameter-assignable FC 20 block forsp ay ng a message n ca ng a pro em .

    Instead of bit memories, that were used in the FC20 to save the message signal

    and its RLO edge detection, you can use so-called static variables in an FB. Theyare stored in the instance DB referencing the FB.

    Instance DB When a DB is generated and references an FB, STEP7 creates the dataStructure structure of the data block using the structure specified in the local declaration table

    for the function block. After you save the DB, the data block is created and can thenbe used as an instance DB.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 17

  • 8/10/2019 PRO1_11E [ ] [ ]

    18/27

    Generating an There are two ways of generating a new instance DB:ns ance en you ca an , you spec y w w c ns ance e s o wor .

    The following message then pops up:

    "Instance data block DB x does not exist. Do you want to generate it?". When you create a new DB, you select the option "Data block referencing a

    function block".

    Notes One instance DB can only reference one FB. However, one FB can be referencedby a different instance DB every time it is called.

    ,generate the instance DB again.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 18

  • 8/10/2019 PRO1_11E [ ] [ ]

    19/27

    Multiple Instance Up until now, you had to use a different instance data block for every call of ao e unc on oc . e num er o a a oc s s m e owever, an or a reason

    there is a method that allows you to use a common instance DB for several FB

    calls.

    The multiple instance model now enables you to use a single DB for several calls.To do this, you need an additional FB to manage these instances.For every FB call (FB 20), you define a static variable in the higher-level FB (FB100). With the block call Call Dist_1, you do not then have to specify an instanceDB.

    The higher-level FB (FB 100) is called, for example, in OB1, the common instanceDB (DB 100) is only generated once.

    Note Multiple instances are discussed in an advanced programming course.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 19

  • 8/10/2019 PRO1_11E [ ] [ ]

    20/27

    The Problem When you add additional block parameters later on to a block already called in theprogram, you mus a so up a e e oc ca .Otherwise, the CPU would either go into Stop or the block function could not be

    guaranteed since the additional parameters still have to be supplied with actualparameters in the call.

    In the example, an additional input parameter Check_lights" was inserted.

    Updating the Call When you save the block in which the declaration table was modified, a messagepops up warning you of possible problems.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 20

  • 8/10/2019 PRO1_11E [ ] [ ]

    21/27

    Updating the Call When the calling block is opened, the following message pops up "me s amp con c w a eas one oc ca an e ca s sp aye n re .With the right mouse button, click on the block call and select the menu option

    Update Call". The block call is then redisplayed and contains, in our example, theadditional input parameter Check_light. This parameter can then be assigned. Inthe case of function blocks, the instance DB is then regenerated.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 21

  • 8/10/2019 PRO1_11E [ ] [ ]

    22/27

    Task The program for displaying a message (indicating a problem) is now to bemp emen e n a unc on oc . or sav ng e e ge memory an e repormemory you are to use static variables that are stored in the instance DB of the FB.

    That way, you do not require any bit memories for saving.In the slide you can see the declaration table with the input and output parametersand the beginning of the program.

    What to Do Insert an FB 20 block into the S7 program "My Program". Write the program in the FB 20. Save the FB 20.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 22

  • 8/10/2019 PRO1_11E [ ] [ ]

    23/27

    What to Do In the S7 program "My Program":

    delete both networks by calling the FC20.

    write a program for the two calls to the FB 20, as given in the slide. download the FB20, DB20, DB21 and OB 1 blocks.

    test the functionality of the program.

    FC -> FB In our example, FB20 was rewritten, even though an FC20 with the same contentsalready existed. It was not hard to do.

    ,differently:

    1st. possible solution:

    insert a new FB

    copy the declaration table of the FC block into the FB and adjust it

    copy the networks from the FC into the FB

    save the FB.

    2nd. possible solution:

    generate a source file from the FC block

    make the adjustments in the source file

    generate a new FB from the source file (see next page).

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 23

  • 8/10/2019 PRO1_11E [ ] [ ]

    24/27

    Introduction Just as with higher-level programming languages, you can also create blocks usinga source program ex e . en you comp e s source program, execu a eblocks are generated. By the same token, a source file can be generated from

    existing blocks.You are to make use of this to create, with the least amount of work (typing), an FB20 from an FC 20 block.

    What to Do 1. Open a block.

    2. In the LAD/STL/FBD Editor, choose the menu options Options ->" ", .

    "Symbolic representation".

    3. In the LAD/STL/FBD Editor select the menu options File -> Generate SourceFile...

    4. In the "New" window, you can enter a name of your choice for the source fileto be generated in the "Object name" box.

    5. In the Generate Source File" window that then appears, select the programblocks that are to be compiled one after the other in the Unselected Blockswindow.

    6. Click "OK" to start the compilation of the blocks into source code.The compiled blocks are then found in the source file which you namedpreviously, in the Source Files" folder of the S7 program.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 24

  • 8/10/2019 PRO1_11E [ ] [ ]

    25/27

    Sources, What For? for automatic rewiring using symbols

    for assigning block attributes, for example, block protection

    as data protection of the entire program

    more freedom in editing and processing blocks:- modifying block type- insert / delete network separations- merging program elements and comments into new blocks- , ,without having to install STEP7 in the PC- complete symbolic programming without syntax check, etc.

    Source Program In the left-hand section of the slide you can see the source program for the FC 20block. On the right-hand side, the source file is displayed for the program as FB 20.Here, the associated keywords for a function block were entered. In addition to that,static variables for the report memory and the edge memory marker are defined.After a compilation run, an executable FB 20 exists once more.

    Note If you do not know the key words, you can insert a block template using the menuoptions Insert -> Block Template -> FB.

    The subject of Source Files" is discussed in greater detail in an advancedprogramming course.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 25

  • 8/10/2019 PRO1_11E [ ] [ ]

    26/27

    Goal You are to recognize the differences between the various types of variables.

    What to Do In the table, mark the associated data type with an X.

    Answer the following question:What is not correct in the statement T#Number_2 ?

    .................................................................................

    Result You can recognize and use the types of variables.

    Training Centerfor Automation and Drives

    ST-7PRO1Functions and Function BlocksPage 26

  • 8/10/2019 PRO1_11E [ ] [ ]

    27/27

    CALL The "CALL" instruction is used for calling program blocks (FC, FB, SFC, SFB),regar ess o e or any o er con ons.

    If you call an FB or SFB with "CALL, you must also specify the relevant instance

    DB.

    You can use either the absolute or the symbolic name for the program block. Forexample: "CALL FB2, DB2" or "CALL valve, level".

    The "CALL" operation saves the return address, deactivates dependence on theMCR and creates the local data area for the block to be called.

    " "e ns ruc on s an uncon ona ca o a oc o e ype or w ouparameter assignment."UC" is otherwise identical to "CALL".

    CC The "CC" instruction calls a block of the type FC or FB without parameters ifRLO=1.

    "CC" is otherwise identical to "CALL".

    Parameters Parameters declared in the declaration table are known as formal parameters". Theaddresses or values specified in the call are referred to as actual parameters".

    Static and temporary variables are not specified in the call.