Determine system time and OB runtime

Một phần của tài liệu Automating with SIMATIC s7 400 inside TIA portal publicis (2013) (Trang 192 - 196)

The system time is updated at an interval of one millisecond for a CPU 400. The sys- tem time starts when the CPU is switched on. The system time runs for as long as the CPU is in the STARTUP or RUN operating state. The current value of the system time is “frozen” when at STOP or HOLD. For a hot restart, the system time continues to run starting at the saved value. A cold restart or warm restart resets the system time.

The system time is present in the data format TIME, where only positive values are possible: TIME#0ms to TIME#24d20h31m23s647ms. In the event of an overflow, the system time restarts at TIME#0.

You can use the system time, for example, to determine the current runtime of the CPU or to calculate the duration between two TIME_TCK calls by generating the dif- ference.

TIME_TCK Read system time

The TIME_TCK system function reads the current system time. The RET_VAL param- eter contains the read system time in the TIME data format. Fig. 5.21 shows the graphic representation of the system function.

Fig. 5.21 System functions TIME_TCK and OB_RT

TIME_TCK OB_RT

SFC 64

Read system time

SFC 78

Read OB runtime Read system time and OB runtime

RET_VAL OB_NR RET_VAL

PRIO LAST_RT LAST_ET CUR_T CUR_RT CUR_ET NEXT_ET

Determine OB runtime

The operating system of a CPU 400 saves the runtimes of the organization blocks using an internal timer in a microsecond grid. In the transition from STOP to RUN, the timer starts, runs to the upper limit of 231–1 and begins again at zero.

The data saved in the operating system can be read using the system function OB_RT for the last completed call and for the current call of the organization block.

This enables you to determine the time load (utilization) of the user program.

OB_RT Read OB runtime

The system function OB_RT reads the runtime of an organization block. Fig. 5.21 shows the graphic representation of the system function.

For the operating mode transition from STOP to RUN, the measured data is pre-as- signed with the initialization value –1 (DW#16#FFFF_FFFF). If no new value is avail- able at the time of the OB_RT call, because, for example, the requested organization block has not yet been called and executed, the initialization value is returned.

OB_RT provides the last recorded measured data independently of whether the requested organization block is currently loaded, deleted or overwritten (over- loaded).

If an error occurs during the execution of OB_RT, RET_VAL contains the error infor- mation. Otherwise, it contains the number of the organization block whose data was retrieved. The parameter PRIO displays the priority class of the scanned orga- nization block.

When using OB_RT, a distinction is made between a call in the program of the orga- nization block to be measured and a call outside of the organization block to be measured.

OB_RT is called outside of the organization block to be measured

The system function OB_RT is not called in the program of the organization block whose runtime is to be determined. Example: OB_RT is called in the OB 1 and is as- signed a value of 30 in the parameter OB_NR. The last captured times for OB 30 are then read. Specification of the synchronous error OB with the numbers 121 and 122 is not permissible because these belong to the priority class of the error-causing or- ganization blocks and thus to their program.

Fig. 5.22 shows some examples for the OB_RT call outside of the organization block to be measured. The initial values after a STOP-RUN transition are –1 (example a).

LAST_RT indicates the runtime in microseconds of the last completed OB execution (examples s to h). The “net” runtimes are output. Interrupt times caused by OBs with higher priority classes are not included in LAST_RT (f).

LAST_ET indicates the time period in microseconds between the start request and the end of processing for the last completed execution of the organization block to be measured (examples s to h). Interrupt times caused by higher priority classes are included in LAST_ET (f).

CUR_T indicates the relative time in microseconds (status of the counter in the op- erating system) of the start request of the OB. After initialization CUR_T (a) con- tains –1. On completion of OB execution, CUR_T is set to zero. Since in these exam- ples OB_RT is called outside the organization block to be measured, OB_RT conse- quently outputs zero at this parameter.

CUR_RT indicates the effective OB execution time until the call of OB_RT in micro- seconds. After initialization CUR_RT (a) contains –1. After completion of OB execu- tion, the value in CUR_RT is transferred to LAST_RT and CUR_RT is set to zero. Since in these examples the call of OB_RT takes place outside the organization block to be measured, the value is always zero.

CUR_ET indicates the time period from the OB start request to calling of OB_RT in microseconds. After completion of OB execution, the value in CUR_ET is transferred to LAST_ET and CUR_ET is set to zero. Since in these examples the call of OB_RT takes place outside the organization block to be measured, the value is always zero.

Values at the parameters of OB_RT

Name a s d f g h

LAST_RT –1 t4 – t3 t8 – t7 (t14 – t13) + (t12 – t11) t19 – t18 t22 – t21

LAST_ET –1 t4 – t2 t8 – t6 t14 – t10 t19 – t16 t22 – t17

CUR_T –1 0 0 0 0 0

CUR_RT –1 0 0 0 0 0

CUR_ET –1 0 0 0 0 0

NEXT_ET –1 –1 –1 –1 –1 –1

Fig. 5.22 Call outside of the organization block to be measured

t1 t2 t3 t4 t5 t6 t7 t8 t9 t10t11t12t13t14 t15t16t17 t18 t19 t20 t21 t22 t23 b)

a)

c)

d)

a s d f g h

STOP RUN

a) Interruption by a higher-priority organization block b) Program execution in the organization block to be measured c) Start request of the organization block to be measured

If OB_RT is called outside of the organization block to be measured, the parameter OB_NR is provided with the number of the organization block to be measured.

d) Call of OB_RT with OB_NR = xx (= number of the organization block to be measured) OB_RT call outside of the organization block to be measured

NEXT_RT indicates the time from the next subsequent OB start request to calling of OB_RT in microseconds if further, unprocessed start requests are pending. A CPU 400 does not use the parameter NEXT_RT, the value is always –1.

OB_RT is called in the organization block to be measured

OB_RT can also be called in the program of the organization block to be measured.

The parameter OB_NR is then initialized with zero and the parameter RET_VAL re- turns the current OB number – in the case of error-free execution. The times for the organization block in which OB_RT is called are read. When calling in one of the synchronous error OBs with the numbers 121 and 122, this is the data of the orga- nization block causing the error, including the times of OB 121 or OB 122.

Fig. 5.23 shows some examples for the OB_RT call in the program of the organiza- tion block to be measured. This can be directly in the OB program or in one of the blocks called there. The initial values after a STOP-RUN transition are –1.

Values at the parameters of OB_RT

Name j k l ; A

LAST_RT –1 t4 – t2 t8 – t6 –1 (t16 – t13) + (t12 – t11)

LAST_ET –1 t4 – t1 t8 – t5 –1 t16 – t9

CUR_T t1 t5 t9 t9 t10

CUR_RT t3 – t2 t7 – t6 (t14 – t13) + (t12 – t11) (t15 – t13) + (t12 – t11) t18 – t17

CUR_ET t3 – t1 t7 – t5 t14 – t9 t15 – t9 t18 – t10

NEXT_ET –1 –1 –1 –1 –1

Fig. 5.23 Call within the organization block to be measured

t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 b)

a)

c)

d)

j k l ; A

STOP RUN

a) Interruption by a higher-priority organization block b) Program execution in the organization block to be measured c) Start request of the organization block to be measured d) Call of OB_RT with OB_NR = 0

OB_RT call within of the organization block to be measured

If OB_RT is called within the organization block to be measured, the parameter OB_NR is provided with zero.

LAST_RT indicates the runtime in microseconds of the last completed OB execution (examples k, l and A). If OB_RT is called again in the organization block to be measured, –1 is output (example ;). The “net” runtimes are output; interrupt times caused by higher priority classes are not included in LAST_RT (example l).

LAST_ET indicates the time period in microseconds between the start request and the end of processing for the last completed execution of the organization block to be measured (examples k and l). This also applies for the first call of OB_RT in the organization block to be measured (l). If OB_RT is called again in the organization block to be measured, –1 is output (example ;). LAST_ET also contains the inter- ruption times caused by program execution levels with higher priority (l).

CUR_T indicates the relative time in microseconds (status of the counter in the op- erating system) of the OB start request, when – as in the following examples – OB_RT is called within the organization block to be measured. On completion of OB execution, CUR_T is set to zero.

CUR_RT indicates the effective OB execution time until the call of OB_RT in micro- seconds. After completion of OB execution, the value in CUR_RT is transferred to LAST_RT and CUR_RT is set to zero. Interruption times caused by program execu- tion levels with higher priority are not included in CUR_RT (l and ;)

CUR_ET indicates the time period from the OB start request to calling of OB_RT in microseconds. After completion of OB execution, the value in CUR_ET is transferred to LAST_ET and CUR_ET is set to zero. CUR_ET also contains the interruption times caused by program execution levels with higher priority (;).

NEXT_RT indicates the time from the next subsequent OB start request to calling of OB_RT in microseconds if further, unprocessed start requests are pending. A CPU 400 does not use the parameter NEXT_RT, the value is always –1.

Một phần của tài liệu Automating with SIMATIC s7 400 inside TIA portal publicis (2013) (Trang 192 - 196)

Tải bản đầy đủ (PDF)

(747 trang)