Advantages of IEC timers and counters
The universal use of IEC timers and counters makes your program code more efficient.
This gives you the following advantages:
-
The blocks can be called multiple times with newly generated instance data blocks.
-
The IEC counters have a large counting range.
-
Compared to S5 timers, IEC timers have better performance and greater time accuracy.
Programming in STEP 7 V5.x
The S5 timers and counters in STEP 7 V5.x were addressed absolutely via a number. Due to this dependency on numbers, program blocks were not reusable with S5 timers and counters.
The value range of a timer was limited to 9990 seconds and that of a counter limited to a maximum of 999.
Procedure in STEP 7 TIA Portal
You declare IEC timers and counters in the program block where they are called or needed. The IEC timer is a structure of data type IEC_TIMER, IEC_LTIMER, or TON_TIME and TON_LTIME, for example, which you can also declare as a local tag in a block. The IEC counter is a structure of data type IEC_SCOUNTER, IEC_USCOUNTER, etc.
Programming examples in the TIA Portal
The following example shows you how to declare an IEC timer and IEC counter as a local tag:
The data of the TON IEC timer and the CTU IEC counter is stored as a local tag (multi-instance) in the block interface.
You also have the option to create IEC timers and IEC counters within structures as multiple instances and to use them in your program code.
-
To do this, for example, create a global data block with an ARRAY of TON. The data type TON does not appear in the drop-down list, but can be entered manually:
-
Create a function block and drag the instruction "TON: Generate on-delay" to a network. Call the instance of IEC timer TON as follows:
Call of a timer as multi-instance
If you want to use the IN parameter to start a timer as multi-instance, you must not initialize it beforehand in your program code. In this case, the timer called at the IN parameter no longer recognizes a positive signal edge and the timer is not started:
1. Create the timer "Time_1" as a multi-instance of the data type "TP_TIME" in the "Static" section of the block interface.
2. Write the following program code:
|
Explanation |
|
|---|---|
|
A "Tag_Output" |
// When the "Tag_Output" output receives the signal state 1, |
|
= #Time_1.IN |
// the IN parameter of the multi-instance timer #Timer_1 is initialized with a positive signal edge. |
|
CALL #Time_1 |
// When the multi-instance timer is now called and the IN parameter queried again, the timer is not started because there is no new positive signal edge. // Enter TIME as data type of the instruction. |
|
time_type := Time |
|
|
IN := "Tag_Output" |
|
|
PT := T#30s |
|
|
Q := "Tag_4" |
|
|
ET := "Tag_ElapsedTime" |
This is why you must program the initialization of the multi-instance timer within the call.
|
Explanation |
|
|---|---|
|
CALL #Time_1 |
// The timer is called and started. // Enter TIME as data type of the instruction. |
|
time_type := Time |
|
|
IN := "Tag_Output" |
|
|
PT := T#30s |
|
|
Q := "Tag_4" |
|
|
ET := "Tag_ElapsedTime" |