Q boxes have a binary output named “Q” which can be linked further. Q boxes are used to represent memory functions, edge evaluations, and timer and counter functions (Fig. 7.16).
With Q boxes, the first binary input (and in certain cases the associated parameter) must be connected; connection of the other inputs and outputs is optional. The bi- nary inputs of Q boxes cannot be directly connected to the left-hand power rail.
Fig. 7.16 Overview of Q boxes available with LAD
Binary tag Binary tag
SIMATIC timer
SIMATIC counter
SR RS
S_PULSE
S_CUD
S R
S
CU TV
CD
R1 S1
R
S PV R
Q Q
Q
Q BI
CV BCD
CV_BCD Edge trigger flag
SR memory box RS memory box
Edge trigger flag
P_TRIG N_TRIG
CLK Q CLK Q
TON
CTUD TON
CTUD
IN
CU R IN
CU R
PT
CD LD PV PT
CD LD PV
Q
QU CV Q
QU CV
ET
QD ET
QD
"Single instance"
"Single instance"
#Local instance
#Local instance Boxes with Q output
Time Time
Int Int
Evaluation with rising edge
Evaluation with falling edge
SIMATIC timer functions IEC timer functions TP, TON and TOF
SIMATIC counter functions IEC counter functions CTUD, CTU and CTD
When using Q boxes as program elements, you can:
b Program one single box per network, either within the current path or as its termination
b Arrange boxes in series by connecting the Q output of one box to a binary input of the following box
b Position boxes following T branches and in branches which commence on the left-hand power rail
7.4.1 Memory boxes
There are two versions of the memory function as box: as SR box (reset dominant) and as RS box (set dominant). With reset dominant, the memory function is reset or remains reset if both inputs have signal state “1”. With set dominant, the mem- ory function is set or remains set in such a case. The response of the memory box is described in Chapter 12.2 “Memory functions” on page 468.
For programming, drag the SR or RS symbol with the mouse from the program elements catalog under Basic instructions > Bit logic operation to the working area.
Fig. 7.17 shows a binary scaler: Each positive edge of the #Bin_input tag changes the signal status of #Bin_output. Thus half the input frequency is present at the output.
7.4.2 Edge evaluation of current flow
The edge evaluation with Q boxes registers a change in the current flow prior to the box. If the signal state changes from “0” to “1” (rising edge) at the CLK input of the P_TRIG box, signal state “1” is present at the Q output for the duration of one pro- gram cycle. If the result of the logic operation changes from “1” to “0” (falling edge) Fig. 7.17 Example of binary scaler
at the CLK input of the N_TRIG box, the Q output is activated for the duration of one program cycle. The response of the boxes for edge evaluation is described in Chap- ter 12.2 “Memory functions” on page 468.
For programming, drag the P_TRIG or N_TRIG symbol with the mouse from the program elements catalog under Basic instructions > Bit logic operation to the work- ing area.
The edge boxes require a preceding logic operation and may only be positioned within a current path.
In Fig. 7.18, #Measurement.Memory is set if #Measurement_temperature exceeds an upper limit. In turn, the #Measurement.Memory tag sets the #Measurement.Message memory. Setting is carried out in both cases by a pulse with positive edge so that acknowledgment is also possible with a set signal present. Acknowledgment is also carried out by a pulse so that, with an acknowledgment signal present, the measured value memory and the message memory are set if the upper limit is exceeded again.
7.4.3 SIMATIC timer functions
Timer functions are used to implement dynamic processes in the user program.
The box of a SIMATIC timer function contains all statements required for the sequence. A detailed description of the SIMATIC timer functions is provided in Chapter 12.3 “SIMATIC timer functions” on page 477.
For programming, drag the corresponding symbol S_PULSE, S_PEXT, S_ODT, S_ODTS or S_OFFDT with the mouse from the program elements catalog under Basic instructions > Timer operations to the working area. You can subsequently Fig. 7.18 Example of edge evaluations of current flow
change the function using a drop-down list which you can open using the small yel- low triangle when the box is selected.
The start input S and the time value TV must be connected; connection of the other box inputs and outputs is optional.
Fig. 7.19 shows a switch-on and switch-off delay. The timer function “Fan5.on-de- lay” is started by #Fan5.start. The Q output has signal state “1” after 3 s, which starts the timer function “Fan5.off-delay”. At the same time, the #Fan5.drive tag is started by the Q output of the box. The Q output still has signal state “1” for 5 s after
#Fan5.start has signal state “0”.
7.4.4 SIMATIC counter functions
Counter functions are used to implement counting tasks in the user program. The box of a SIMATIC counter function contains all statements required for the sequence. A detailed description of the SIMATIC counter functions is provided in Chapter 12.5 “SIMATIC counter functions” on page 495.
For programming, drag the corresponding symbol (S_CUD, S_CU or S_CD) with the mouse from the program elements catalog under Basic instructions > Counter oper- ations to the working area. You can subsequently change the function using a drop- down list which you can open using the small yellow triangle when the box is se- lected.
Fig. 7.19 Example of SIMATIC timer functions in the ladder logic
Fig. 7.20 Example of SIMATIC counter functions in the ladder logic
At least one of the counter inputs (CU or CD) must be connected; connection of the other box inputs and outputs is optional.
Fig. 7.20 shows a down counter. The name of the SIMATIC counter used is positioned above the counter box. #Quantity_set sets the counter to the count value W#16#0120. The count value is reduced by 1 with each pulse from #Workpiece_iden- tified. Once zero has been reached, #Quantity_reached is set.
7.4.5 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. A detailed description of the IEC timer functions is provided in Chap- ter 12.4 “IEC timer functions” 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 to the working area. When positioning, you select either as single instance or – possible in a function block – as local instance. The instance data block generated automatically when selecting as a single instance is saved in the project tree under Program blocks > System blocks > Program resources.
You can subsequently change the timer function using a drop-down list which you can open using the small yellow triangle when the box is selected.
With the IEC timer functions, the IN input must have a preceding logic operation and a duration must be connected to the PT input. The Q output can be supplied with a coil, but cannot be linked further. You can also directly access the output parameters using the instance data, for example with “DB_name”.Q or
“DB_name”.ET for a single instance.
Fig. 7.21 shows the IEC timer function #MessageDelay, which saves its data as local 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.
Fig. 7.21 Example of IEC timer functions
7.4.6 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- tem. 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 (CTUD, CTU or CTD) with the mouse from the program elements catalog under Basic instructions > Counter oper- ations to the working area. When positioning, you select either as single instance or – possible in a function block – as local instance. The instance data block generated automatically when selecting as a single instance is saved in the project tree under Program blocks > System blocks > Program resources.
You can subsequently change the timer function using a drop-down list which you can open using the small yellow triangle when the box is selected.
With the IEC counter functions, at least one counter input (CU or CD) must have a preceding logic operation. Connection of the other box inputs and outputs is optional. A coil can be positioned at the top output QU, but not a further logic oper- ation. The QD output cannot be supplied, but can be scanned indirectly via the corresponding component QD of the counter structure. For the QU output, this would be the component QU.
One can also directly access the output parameters using the instance data, for ex- ample with “DB_name”.QD for a single instance.
Fig. 7.22 shows the IEC counter function #LockCounter, 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 #LockCounter.CV. The example shows the passages through a lock, either forward or backward.
Fig. 7.22 Example of IEC counter functions