×
Siemens Industry Online Support
Siemens AG
  • Content
  • Search
  • Index
  • S7-1200 Programmable controller
    • Basic instructions
      • Timers
        • Timers
    (32)
    Rate

    Entry type: Manual, Entry ID: 36932465, Entry date: 05/09/2012

    SIMATIC S7 S7-1200 Programmable controller

    Document: SIMATIC S7 S7-1200 Programmable controller (04/2012, English)
    Type of topic: Fact

    Timers

    You use the timer instructions to create programmed time delays. The number of timers that you can use in your user program is limited only by the amount of memory in the CPU. Each timer uses a 16 byte IEC_Timer data type DB structure to store timer data that is specified at the top of the box or coil instruction. STEP 7 automatically creates the DB when you insert the instruction.

    Table: Timer instructions

    LAD / FBD boxes

    LAD coils

    SCL

    Description

     

     
    "IEC_Timer_0_DB".TP(     IN:=_bool_in_,     PT:=_time_in_,     Q=>_bool_out_,     ET=>_time_out_);

    The TP timer generates a pulse with a preset width time.

     

     
    "IEC_Timer_0_DB".TON (     IN:=_bool_in_,     PT:=_time_in_,     Q=>_bool_out_,     ET=>_time_out_);

    The TON timer sets output Q to ON after a preset time delay.

     

     
    "IEC_Timer_0_DB".TOF (     IN:=_bool_in_,     PT:=_time_in_,     Q=>_bool_out_,     ET=>_time_out_);

    The TOF timer resets output Q to OFF after a preset time delay.

     

     
    "IEC_Timer_0_DB".TONR (     IN:=_bool_in_,     R:=_bool_in_     PT:=_time_in_,     Q=>_bool_out_,     ET=>_time_out_);

    The TONR timer sets output Q to ON after a preset time delay. Elapsed time is accumulated over multiple timing periods until the R input is used to reset the elapsed time.

    FBD only:

     

    (No SCL equivalent)

    The PT (Preset timer) coil loads a new PRESET time value in the specified IEC_Timer.

    FBD only:

     

    (No SCL equivalent)

    The RT (Reset timer) coil resets the specified IEC_Timer.

    1 STEP 7 automatically creates the DB when you insert the instruction.
    2 In the SCL examples, "IEC_Timer_0_DB" is the name of the instance DB.

    Table: Data types for the parameters

    Parameter

    Data type

    Description

    Box: IN
    Coil: Power flow

    Bool

    TP, TON, and TONR:
    Box: 0=Disable timer, 1=Enable timer
    Coil: No power flow=Disable timer, Power flow=Enable timer

    TOF:
    Box: 0=Enable timer, 1=Disable timer
    Coil: No power flow=Enable timer, Power flow=Disable timer

    R

    Bool

    TONR box only:
    0=No reset
    1= Reset elapsed time and Q bit to 0

    Box: PT
    Coil: "PRESET_Tag"

    Time

    Timer box or coil: Preset time input

    Box: Q
    Coil: DBdata.Q

    Bool

    Timer box: Q box output or Q bit in the timer DB data
    Timer coil: you can only address the Q bit in the timer DB data

    Box: ET
    Coil: DBdata.ET

    Time

    Timer box: ET (elapsed time) box output or ET time value in the timer DB data
    Timer coil: you can only address the ET time value in the timer DB data.

    Table: Effect of value changes in the PT and IN parameters

    Timer

    Changes in the PT and IN box parameters and the corresponding coil parameters

    TP

    • Changing PT has no effect while the timer runs.
    • Changing IN has no effect while the timer runs.

    TON

    • Changing PT has no effect while the timer runs.
    • Changing IN to FALSE, while the timer runs, resets and stops the timer.

    TOF

    • Changing PT has no effect while the timer runs.
    • Changing IN to TRUE, while the timer runs, resets and stops the timer.

    TONR

    • Changing PT has no effect while the timer runs, but has an effect when the timer resumes.
    • Changing IN to FALSE, while the timer runs, stops the timer but does not reset the timer. Changing IN back to TRUE will cause the timer to start timing from the accumulated time value.

    PT (preset time) and ET (elapsed time) values are stored in the specified IEC_TIMER DB data as signed double integers that represent milliseconds of time. TIME data uses the T# identifier and can be entered as a simple time unit (T#200ms or 200) and as compound time units like T#2s_200ms.

    Table: Size and range of the TIME data type

    Data type

    Size

    Valid number ranges1

    TIME

    32 bits, stored as DInt data

    T#-24d_20h_31m_23s_648ms to T#24d_20h_31m_23s_647ms

    Stored as -2,147,483,648 ms to +2,147,483,647 ms

    1 The negative range of the TIME data type shown above cannot be used with the timer instructions. Negative PT (preset time) values are set to zero when the timer instruction is executed. ET (elapsed time) is always a positive value.

    Timer coil example

    The -(TP)-, -(TON)-, -(TOF)-, and -(TONR)- timer coils must be the last instruction in a LAD network. As shown in the timer example, a contact instruction in a subsequent network evaluates the Q bit in a timer coil's IEC_Timer DB data. Likewise, you must address the ELAPSED element in the IEC_timer DB data if you want to use the elapsed time value in your program.

    The pulse timer is started on a 0 to 1 transition of the Tag_Input bit value. The timer runs for the time specified by Tag_Time time value.

    As long as the timer runs, the state of DB1.MyIEC_Timer.Q=1 and the Tag_Output value=1. When the Tag_Time value has elapsed, then DB1.MyIEC_Timer.Q=0 and the Tag_Output value=0.

    Reset timer -(RT)- and Preset timer -(PT)- coils

    These coil instructions can be used with box or coil timers and can be placed in a mid-line position. The coil output power flow status is always the same as the coil input status. When the -(RT)- coil is activated, the ELAPSED time element of the specified IEC_Timer DB data is reset to 0. When the -(PT)- coil is activated, the PRESET time element of the specified IEC_Timer DB data is reset to 0.


    Note

    When you place timer instructions in an FB, you can select the "Multi-instance data block" option. The timer structure names can be different with separate data structures, but the timer data is contained in a single data block and does not require a separate data block for each timer. This reduces the processing time and data storage necessary for handling the timers. There is no interaction between the timer data structures in the shared multi-instance DB.



    Operation of the timers

    Table: Types of IEC timers

    Timer

    Timing diagram

    TP: Pulse timer

    The TP timer generates a pulse with a preset width time.

     

    TON: ON-delay timer

    The TON timer sets output Q to ON after a preset time delay.

     

    TOF: OFF-delay timer

    The TOF timer resets output Q to OFF after a preset time delay.

     

    TONR: ON-delay Retentive timer

    The TONR timer sets output Q to ON after a preset time delay. Elapsed time is accumulated over multiple timing periods until the R input is used to reset the elapsed time.

     


    Note

    In the CPU, no dedicated resource is allocated to any specific timer instruction. Instead, each timer utilizes its own timer structure in DB memory and a continuously-running internal CPU timer to perform timing.



    When a timer is started due to an edge change on the input of a TP, TON, TOF, or TONR instruction, the value of the continuously-running internal CPU timer is copied into the START member of the DB structure allocated for this timer instruction. This start value remains unchanged while the timer continues to run, and is used later each time the timer is updated. Each time the timer is started, a new start value is loaded into the timer structure from the internal CPU timer.

    When a timer is updated, the start value described above is subtracted from the current value of the internal CPU timer to determine the elapsed time. The elapsed time is then compared with the preset to determine the state of the timer Q bit. The ELAPSED and Q members are then updated in the DB structure allocated for this timer. Note that the elapsed time is clamped at the preset value (the timer does not continue to accumulate elapsed time after the preset is reached).

    A timer update is performed when and only when:

    • A timer instruction (TP, TON, TOF, or TONR) is executed
    • The "ELAPSED" member of the timer structure in DB is referenced directly by an instruction
    • The "Q" member of the timer structure in DB is referenced directly by an instruction

    Timer programming

    The following consequences of timer operation should be considered when planning and creating your user program:

    • You can have multiple updates of a timer in the same scan. The timer is updated each time the timer instruction (TP, TON, TOF, TONR) is executed and each time the ELAPSED or Q member of the timer structure is used as a parameter of another executed instruction. This is an advantage if you want the latest time data (essentially an immediate read of the timer). However, if you desire to have consistent values throughout a program scan, then place your timer instruction prior to all other instructions that need these values, and use tags from the Q and ET outputs of the timer instruction instead of the ELAPSED and Q members of the timer DB structure.
    • You can have scans during which no update of a timer occurs. It is possible to start your timer in a function, and then cease to call that function again for one or more scans. If no other instructions are executed which reference the ELAPSED or Q members of the timer structure, then the timer will not be updated. A new update will not occur until either the timer instruction is executed again or some other instruction is executed using ELAPSED or Q from the timer structure as a parameter.
    • Although not typical, you can assign the same DB timer structure to multiple timer instructions. In general, to avoid unexpected interaction, you should only use one timer instruction (TP, TON, TOF, TONR) per DB timer structure.
    • Self-resetting timers are useful to trigger actions that need to occur periodically. Typically, self-resetting timers are created by placing a normally-closed contact which references the timer bit in front of the timer instruction. This timer network is typically located above one or more dependent networks that use the timer bit to trigger actions. When the timer expires (elapsed time reaches preset value), the timer bit is ON for one scan, allowing the dependent network logic controlled by the timer bit to execute. Upon the next execution of the timer network, the normally closed contact is OFF, thus resetting the timer and clearing the timer bit. The next scan, the normally closed contact is ON, thus restarting the timer. When creating self-resetting timers such as this, do not use the "Q" member of the timer DB structure as the parameter for the normally-closed contact in front of the timer instruction. Instead, use the tag connected to the "Q" output of the timer instruction for this purpose. The reason to avoid accessing the Q member of the timer DB structure is because this causes an update to the timer and if the timer is updated due to the normally closed contact, then the contact will reset the timer instruction immediately. The Q output of the timer instruction will not be ON for the one scan and the dependent networks will not execute.

    Time data retention after a RUN-STOP-RUN transition or a CPU power cycle

    If a run mode session is ended with stop mode or a CPU power cycle and a new run mode session is started, then the timer data stored in the previous run mode session is lost, unless the timer data structure is specified as retentive (TP, TON, TOF, and TONR timers).

    When you accept the defaults in the call options dialog after you place a timer instruction in the program editor, you are automatically assigned an instance DB which cannot be made retentive. To make your timer data retentive, you must either use a global DB or a Multi-instance DB.

    Assign a global DB to store timer data as retentive data

    This option works regardless of where the timer is placed (OB, FC, or FB).

    1. Create a global DB:
      • - Double-click "Add new block" from the Project tree
      • - Click the data block (DB) icon
      • - For the Type, choose global DB
      • - If you want to be able to select individual data elements in this DB as retentive, be sure the DB type "Optimized" box is checked. The other DB type option "Standard - compatible with S7-300/400" only allows setting all DB data elements retentive or none retentive.
      • - Click OK
    2. Add timer structure(s) to the DB:
      • - In the new global DB, add a new static tag using data type IEC_Timer.
      • - In the "Retain" column, check the box so that this structure will be retentive.
      • - Repeat this process to create structures for all the timers that you want to store in this DB. You can either place each timer structure in a unique global DB, or you can place multiple timer structures into the same global DB. You can also place other static tags besides timers in this global DB. Placing multiple timer structures into the same global DB allows you to reduce your overall number of blocks.
      • - Rename the timer structures if desired.
    3. Open the program block for editing where you want to place a retentive timer (OB, FC, or FB).
    4. Place the timer instruction at the desired location.
    5. When the call options dialog appears, click the cancel button.
    6. On the top of the new timer instruction, type the name (do not use the helper to browse) of the global DB and timer structure that you created above (example: "Data_block_3.Static_1").

    Assign a multi-instance DB to store timer data as retentive data

    This option only works if you place the timer in an FB.

    This option depends upon whether the FB was created with "Optimized" block access (allows symbolic access only). Once the FB has been created, you cannot change the checkbox for "Optimized"; it must be chosen correctly when the FB is created, on the first screen after selecting "Add new block" from the tree. To verify how the access attribute is configured for an existing FB, right-click on the FB in the Project tree, choose properties, and then choose attributes.

    If the FB was created with the "Optimized" box checked (allows symbolic access only):

    1. Open the FB for edit.
    2. Place the timer instruction at the desired location in the FB.
    3. When the Call options dialog appears, click on the Multi instance icon. The Multi Instance option is only available if the instruction is being placed into an FB.
    4. In the Call options dialog, rename the timer if desired.
    5. Click OK. The timer instruction appears in the editor, and the IEC_TIMER structure appears in the FB Interface under Static.
    6. If necessary, open the FB interface editor (may have to click on the small arrow to expand the view).
    7. Under Static, locate the timer structure that was just created for you.
    8. In the Retain column for this timer structure, change the selection to "Retain". Whenever this FB is called later from another program block, an instance DB will be created with this interface definition which contains the timer structure marked as retentive.

    If the FB was created with the "Standard - compatible with S7-300/400" box checked (allows symbolic and direct access):

    1. Open the FB for edit.
    2. Place the timer instruction at the desired location in the FB.
    3. When the Call options dialog appears, click on the multi instance icon. The multi instance option is only available if the instruction is being placed into an FB.
    4. In the Call options dialog, rename the timer if desired.
    5. Click OK. The timer instruction appears in the editor, and the IEC_TIMER structure appears in the FB Interface under Static.
    6. Open the block that will use this FB.
    7. Place this FB at the desired location. Doing so results in the creation of an instance data block for this FB.
    8. Open the instance data block created when you placed the FB in the editor.
    9. Under Static, locate the timer structure of interest. In the Retain column for this timer structure, check the box to make this structure retentive.


     

    Rate entry
    no rating
    Requests and feedback
    What do you want to do?
    Note: The feedback always relates to the current entry / product. Your message will be forwarded to our technical editors working in the Online Support. In a few days, you will receive a response if your feedback requires one. If we have no further questions, you will not hear from us.
    Support to the statistics
    With this function the IDs found are listed according to number (format .txt).

    Generate list
    Copy URL
    Display page in new design
    mySupport Cockpit