1. Classification of timers
The Siemens S7-200 SmartCPU has three types of on delay timer TON, hold on delay timer TONR, and off delay timer TOF. However, the total number of timer calls in STEP 7 Micro/WIN SMART is limited to 256, and the timer cannot be used when S7-200SMART subroutine is called for multiple times. Therefore, the start interval time instruction (BGN_ITIME) and the calculation interval time instruction CAL_ITIME can be used to realize the timing function of the positional signal. And can be called multiple times in the subroutine.
2. Know the interval timer
(1) Start interval instruction: when the conditions of the EN end of the instruction are met (it is necessary to use the pulse signal) to capture the moment when EN is on, read the current value of the built-in 1ms counter, and store the value in OUT; the data type is DWORD.
② Calculate interval time instruction: calculate the time difference between the current time and the time provided IN the IN address, and then store the difference IN OUT; the data type is also DWORD. The maximum timing interval for a two-word millisecond value is
Or 49.7 days. Depending on the execution time of the BGN_ITIM instruction, the CAL_CITIM instruction automatically handles the one-millisecond timer flip that occurs within the maximum interval.
Timer Application
Let us go through a simple application to fully understand the interval instructions; this is shown in Figure 2.
When the EN of BGN_ITIM instruction in program segment 1 is on for a scan cycle, the system will read the specific time of switching on in this scan cycle and store it in OUT address VD0. At the same time, the CAL_CITIM instruction IN program segment 2 will calculate the difference between address VD4 IN OUT and address VD0 IN the IN end, so as to obtain the actual time for EN end to be connected, and the unit of this time is milliseconds.
Timer in subroutine application
In many practical applications, subroutines will be established for multiple calls, and the timer, counter and other instructions will be used. But because the timer of 200SMART series PLC can not be used for multiple calls of subroutines, at this time you can use the time interval instruction; specific operation we can refer to the following sample program.
1. Open STEP 7 Micro/WIN SMART software to create a SBR_0 subroutine, and establish variables in the subroutine variable table, as shown in Figure 3.
2. Call BGN_ITIM and CAL_CITIM instructions in the subprogram editing area, as shown in Figure 4. Note that you cannot use edge pulses in a subroutine, so you need to use edge pulses in the MAIN program.
3. Select the MAIN program, open the "call subroutine" in the project tree, drag the built subroutine SBR_0 to the MAIN program, and assign arguments to each form parameter, and can realize multiple calls; execute different conditions, then can realize the corresponding time record
The function of the program is:
Program segment 1: V20.0 The timing of the process from switch on to disconnect. The timing result (in milliseconds) can be viewed in VD4.
Program segment 2: V20.1 The timing of the process from switch on to disconnect. The timing result (in milliseconds) can be viewed in VD12.
conclusion
Time interval instruction is one of the methods used to record time through subroutines. Two points should be noted when using this method: First, pulse impulse signal needs to be used to trigger the EN end of BGN_ITIM instruction, while edge pulse signal cannot be used in the subroutine. Therefore, when the main program assigns arguments to this formal parameter, the edge pulse instruction must be added, otherwise the CAL_CITIM instruction OUT will have no value. Second, CAL_CITIM instruction OUT address is DWORD data type, and the unit is millisecond, we need to perform the second operation before the actual running time.