The attached download "STEP_7_TIA_Portal_D_Count" performs counting forwards and backwards in a bandwidth between -2147483648 and +2147483647 by an edge change at the "Up" and "Down" inputs. An edge change at the "L_Preset" input transfers a value preset at the "Preset" parameter to the "Count" output. The forwards and backwards counting with the parameters "Up" and "Down" increments/decrements the value at the "Count" output accordingly by "1". If during counting the "Count" output reaches a value that is equal to or greater than the value entered at the "Compare" input, "Q_Compare" output receives the signal "1".
Boxes are transported from A to B on a conveyor belt.
- Scan 1 detects the boxes placed on the conveyor and with the input E0.0 the value at the "Count" output is incremented by "1".
- Scan 2 detects the boxes removed from the conveyor and with the input E0.1 the value at the "Count" output is decremented by "1".
- If boxes are removed or sorted out during the course of the transport and are not detected by Scan 2, then the value at the "Count" output increases due to the difference by "1" for each box removed. For example, if a value of 20 boxes is set at the "Compare" parameter and the "Count" output reaches the value 20, the output A0.0 receives the signal "1". This is the difference value of the boxes removed in addition or lost.
Through a plug-in (not included in the download FB100), you can program stopping of the conveyor belt with reference to the signal at output A0.0.
The table below describes how to program the function block FB100 shown in Fig. 01. FB100 is called with its instance DB DB100 in OB1.
||Description of program in FB100|
A positive edge at the input "Up" (type: BOOL) increments the static variable "S_Count" (type: DINT) so that counting goes forwards by "1" at every edge change here.
A positive edge at the input "Down" (type: BOOL) decrements the static variable "S_Count" (type: DINT) so that counting goes backwards by "1" at every edge change here.
A positive edge at the input "L_Preset" (type: BOOL) transfers the preset value between the input "Preset" (type: DINT) and the static variable "S_Count".
The value of the static variable "S_Count" actually calculated from Networks 1, 2 or 3 is transferred to the output "Count" (type: DINT).
Here there is query as to whether the value at the output "Count" is greater or equal to the comparison value entered at the input "Compare" (type: DINT). In this case the output "Q_Compare" (type: BOOL) receives the signal "1".
The attached STEP 7 (TIA Portal) project includes one program for the S7-1500 and one program for the S7-300. Both programs contain the blocks described above (FB100, instance DB100 and OB1). You can also use the blocks for the S7-1500 for the S7-1200 and the blocks for the S7-300 for the S7-400.
STEP_7_TIA_Portal_ D_Count.zip ( 2330 KB )
Copy the "STEP_7_TIA_Portal_D_Count.zip" file into a separate directory and then start the file with a double-click. The STEP 7 (TIA Portal) project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 (TIA Portal) to open and process the extracted project.
The screens and download in this FAQ response were created with STEP 7 V12.