10.4.1 SIMATIC timer functions
Timer functions are used to implement dynamic processes in the user program.
SIMATIC timer functions are an operand area in the CPU's system memory and their number is limited. SCL handles a SIMATIC timer function like a function with func- tion value. Table 10.3 shows the parameters possible in association with a function call of a SIMATIC timer. How the SIMATIC timer functions respond is described in detail in Chapter 12.3 “SIMATIC timer functions” on page 477.
For programming, enter the tag for the function value and the assignment operator in a line. Drag the function call with the mouse from the program elements catalog under Basic instructions > Timer operations into the input line. Then replace the
//Set alarm memory with positive signal edge
#Alarm.pulse_pos := #Alarm.bit AND NOT #Alarm.edge_pos;
#Alarm.edge_pos := #Alarm.bit;
IF #Alarm.pulse_pos THEN #Alarm.memory := TRUE; END_IF;
//Reset alarm memory with negative signal edge IF NOT #Alarm.ack AND #Alarm.edge_neg
THEN #Alarm.memory := FALSE; END_IF;
#Alarm.edge_neg := #Alarm.ack;
Fig. 10.8 Examples of edge evaluation with SCL
Table 10.3 Call of SIMATIC timer functions with SCL Timer function Parameter Data type Description
Function value S5TIME, TIME Current time value S_PULSE
S_PEXT S_ODT S_ODTS S_OFFDT
Start timer as pulse Start timer as extended pulse Start timer as ON delay Start timer as retentive ON delay Start timer as OFF delay T_NO
S TV R BI Q
TIMER BOOL S5TIME BOOL WORD BOOL
Time operand (T) Start input Default time value Reset input
Current integer-coded time value Binary status of timer function
dummy values by the actual parameters in the function call. Delete non-required parameters including their name.
In Fig. 10.9, the time “Fan5.on_delay” is started as an ON delay by the positive edge of #Fan5.start. Following expiry of the duration, the timer function “Fan5.off_delay”
is started with the duration present as a value in the #Follow-up_time tag. The status of the timer function “Fan.off_delay” simultaneously has signal state “1” so that fan 5 is switched on following the ON delay. Once the start signal #Fan5.start has signal state “0”, fan 5 continues to run for the follow-up time and is then switched off.
10.4.2 SIMATIC counter functions
Counter functions are used to implement counting tasks in the user program.
SIMATIC counter functions are an operand area in the CPU's system memory and their number is limited. SCL handles a SIMATIC counter function like a function with function value. Table 10.4 shows the parameters possible in association with a function call of a SIMATIC counter. How a SIMATIC counter function responds is de- scribed in detail in Chapter 12.5 “SIMATIC counter functions” on page 495.
For programming, enter the tag for the function value and the assignment opera- tor in a line. Drag the function call with the mouse from the program elements cat- alog under Basic instructions > Counter operations into the input line. Then replace the dummy values by the actual parameters in the function call. Delete non-re- quired parameters including their name.
//Switch fan on and off with delay
#temp_S5Time := S_ODT(T_NO := “Fan5.on_delay”, S := #Fan5.start, TV := S5T#3s, Q => #temp_bool);
#temp_S5Time := S_OFFDT(T_NO := “Fan5.off_delay”, S := #temp_bool, TV := #Follow-up_time, Q => #Fan5.drive);
Fig. 10.9 Example of application of SIMATIC timer functions
Table 10.4 Call of SIMATIC counter functions with SCL Timer func-
tion
Parameter Data type Description Function value WORD Current count value S_CU
S_CD S_CUD
Up counter Down counter Up/down counter C_NO
S PV R BI Q
COUNTER BOOL WORD BOOL WORD BOOL
Counter operand (C) Set input
Default count value Reset input
Current integer-coded count value Binary status of counter function
Fig. 10.10 shows the counting of workpieces up to a specific quantity. The counter
#Parts_counter is set by the #Quantity_set tag to a start value of 120. Each positive edge at the #Workpiece_identified tag decrements the count value by one unit. If a value of zero is reached – the counter status is then “0” – #Quantity_reached is set.
10.4.3 IEC timer functions
Timer functions are used to implement dynamic processes in the user program.
With a CPU 400, an IEC timer function is a system function block (SFB) in the oper- ating system and is called in the user program like a function block. A detailed de- scription of the IEC timer functions is provided in Chapter 12.4 “IEC timer func- tions” on page 491.
For programming, drag the corresponding symbol (TP, TON, or TOF) with the mouse from the program elements catalog under Basic instructions > Timer opera- tions into a line on the working area. When positioning, you select either as single instance or as local instance. The instance data block generated automatically when selecting as a single instance is saved in the project tree under Program blocks > Sys- tem blocks > Program resources.
With the IEC timer functions, a binary tag must be connected to the IN input, and a duration to the PT input. You can also directly access the output parameters using the instance data, for example with “DB_name”.Q for a single instance or #In- stance_name.Q for a local instance.
Fig. 10.11 shows the IEC timer function #Message_delay, which saves its data as lo- cal instance in the instance data block of the calling function block. If the #Measure- ment_too_high tag has a signal state “1” for longer than 10 s, #Message_too_high is set.
10.4.4 IEC counter functions
A counter function implements counting processes in the user program. With a CPU 400, an IEC counter function is a system function block (SFB) in the operating sys-
//Simple parts counter
#temp_word := S_CD(C_NO := "Parts_counter", CD := #Workpiece_identified, S := #Quantity_set, PV := 16#0120, Q => #temp_bool);
#Quantity_reached := NOT #temp_bool;
Fig. 10.10 Example of application of a SIMATIC counter function with SCL
//Message delay
#Message_delay(IN := #Measurement_too_high, PT := T#10s, Q => #Message_too_high);
Fig. 10.11 Example of IEC timer function with SCL
tem and is called in the user program like a function block. A detailed description of the IEC counter functions is provided in Chapter 12.6 “IEC counter functions” on page 502.
For programming, drag the corresponding symbol (CTU, CTD, or CTUD) with the mouse from the program elements catalog under Basic instructions > Counter oper- ations into a line on the working area. When positioning, you select either as single instance or as local instance. The instance data block generated automatically when selecting as a single instance is saved in the project tree under Program blocks > Sys- tem blocks > Program resources.
With the IEC counter functions, a binary tag must be connected to at least one counter input (CU or CD). Connection of the other function inputs and outputs is optional. You can also directly access the output parameters using the instance data, for example with “DB_name”.QD for a single instance or #Instance_name.QD for a local instance.
Fig. 10.12 shows the IEC counter function #Lock_counter, which is called as a local instance. It has saved its data in the instance data block of the calling function block.
A component of the counter can be addressed globally with the name of the instance and the component name, for example #Lock_counter.CV. The example shows the passages through a lock, either forward or backward.