“Q boxes” is the abbreviation for boxes with an output parameter named “Q”. These are the memory boxes SR and RS, the edge evaluations P_TRIG and N_TRIG, and the timer and counter functions (Fig. 8.18).
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.
When using Q boxes as program elements, you can:
b Program one single box per network, either within the logic operation 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
Fig. 8.17 Example of standard boxes with counter response
8.4.1 Memory boxes
There are two versions of the memory function: 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 memory 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. 8.19 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.
Fig. 8.18 Overview of Q boxes available with FBD
Binary tag Binary tag
SR RS
S R
R1 Q S1
Edge trigger flag Edge trigger flag
P_TRIG N_TRIG
CLK Q CLK
Q
Q Boxes with Q output
SIMATIC timer
SIMATIC counter S_PULSE
S_CUD S
CU TV
CD R
S PV R
Q
Q BI
CV BCD
CV_BCD
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
Time Time
Int Int
Evaluation with rising edge
Evaluation with falling edge
SR memory box RS memory box
SIMATIC timer functions IEC timer functions TP, TON and TOF
SIMATIC counter functions IEC counter functions CTUD, CTU and CTD
8.4.2 Edge evaluation of result of logic operation
The edge evaluation with Q boxes registers a change in the result of the logic oper- ation prior to the box. If the result of the logic operation 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 program cycle. If the result of the logic operation changes from “1” to “0” (falling edge) at the CLK input of the N_TRIG box, the Q out- put is activated for the duration of one program cycle.
For programming, drag the P_TRIG or N_TRIG symbol with the mouse from the pro- gram elements catalog under Basic instructions > Bit logic operation to the working area.
The P_TRIG and N_TRIG boxes require a preceding logic operation and may only be positioned within a logic operation.
In Fig. 8.20, #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.
8.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.
Fig. 8.19 Example of binary scaler
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 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. 8.21 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”.
Fig. 8.20 Example of edge evaluation of the result of the logic operation
Fig. 8.21 Example of SIMATIC timer functions in the function block diagram
8.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 operations 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 selected.
At least one of the counter inputs (CU or CD) must be connected; connection of the other box inputs and outputs is optional.
Fig. 8.22 shows a down counter. The name of the SIMATIC counter used is posi- tioned 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.
8.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 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.
Fig. 8.22 Example of SIMATIC counter functions in the function block diagram
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 an assignment, 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. 8.23 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.
8.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 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 standard box can be positioned at the bottom output QU, but not a fur- ther logic operation. The QD output cannot be supplied, but can be scanned indi- rectly 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. 8.23 Example of IEC timer functions in the function block diagram
Fig. 8.24 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.