You are on page 1of 2

SIMATIC SCL_Book\ 08/15/2019 12:38:54 PM

30 SCL Functions\Source Files\...\Counter Functions

1 FUNCTION_BLOCK STD_COUNTER
2 TITLE = 'Call examples for counter functions'
3 //Chapter 30.2 "Counter Functions"
4 //Chapter 8.6 "IEC Counter Functions"
5
6 NAME : STD_CNTR
7 FAMILY : SCL_Book
8 AUTHOR : Berger
9 VERSION : '1.0'
10
11 VAR
12 BCD1, BCD2, BCD3 : WORD; //BCD_value
13 Bin1, Bin2, Bin3 : WORD; //Binary_value
14 PV1, PV2, PV3 : WORD; //Counter value
15 Set1, Set2, Set3 : BOOL; //Set counter
16 Up1, Up2, Up3 : BOOL; //Count up
17 Down1, Down2, Down3 : BOOL; //Count down
18 Reset1, Reset2, Reset3 : BOOL; //Reset counter
19 Status1, Status2, Status3 : BOOL; //Counter status
20
21 Up : CTU; //SFB 0 IEC up counter
22 Up4 : BOOL := FALSE;
23 Reset4 : BOOL := FALSE;
24 Status4 : BOOL := FALSE;
25 Svalue4 : INT := 0;
26 Zvalue4 : INT := 0;
27
28 Down : CTD; //SFB 1 IEC down counter
29 Down5 : BOOL := FALSE;
30 Set5 : BOOL := FALSE;
31 Status5 : BOOL := FALSE;
32 Svalue5 : INT := 0;
33 Zvalue5 : INT := 0;
34
35 UpDown : CTUD; //SFB 2 IEC up-down counter
36 Up6 : BOOL := FALSE;
37 Down6 : BOOL := FALSE;
38 Reset6 : BOOL := FALSE;
39 Set6 : BOOL := FALSE;
40 VStatus6 : BOOL := FALSE;
41 ZStatus6 : BOOL := FALSE;
42 Svalue6 : INT := 0;
43 Zvalue6 : INT := 0;
44
45 END_VAR
46
47 BEGIN
48 //*****************************************************************************
49 //Starting the SIMATIC counter functions
50
51 //Up counter
52 BCD1 := S_CU(
53 C_NO := "Counter1",
54 CU := Up1,
55 S := Set1,
56 PV := PV1,
57 R := Reset1,
58 CV := bin1,
59 Q := Status1);
60
61 //Down counter
62 BCD2 := S_CD(
63 C_NO := "Counter2",
64 CD := Up2,
65 S := Set2,
66 PV := PV2,
67 R := Reset2,
68 CV := bin2,
69 Q := Status2);
70
71 //Up-down counter
72 BCD3 := S_CUD(
73 C_NO := "Counter3",
74 CU := Up3,
75 CD := Down3,
Page 1 of 2
SIMATIC SCL_Book\ 08/15/2019 12:38:54 PM
30 SCL Functions\Source Files\...\Counter Functions

76 S := Set3,
77 PV := PV3,
78 R := Reset3,
79 CV := bin3,
80 Q := Status3);
81
82 //*****************************************************************************
83 //Starting the IEC counter functions
84
85 Up ( //Up counter
86 CU := Up4,
87 R := Reset4,
88 PV := Svalue4);
89
90 Status4 := Up.Q;
91 Zvalue4 := Up.CV;
92
93 Down ( //Down counter
94 CD := Down5,
95 LOAD := Set5,
96 PV := Svalue5);
97
98 Status5 := Down.Q;
99 Zvalue5 := Down.CV;
100
101 UpDown ( //Up-down counter
102 CU := Up6,
103 CD := Down6,
104 R := Reset6,
105 LOAD := Set6,
106 PV := Svalue6);
107
108 VStatus6 := UpDown.QU;
109 ZStatus6 := UpDown.QD;
110 Zvalue6 := UpDown.CV;
111
112 //*****************************************************************************
113 END_FUNCTION_BLOCK
114

Page 2 of 2

You might also like