FUNCTION_BLOCK STD_COUNTER
TITLE = 'SCL ve Sayıcılarla ilgili örnekler'
//Chapter 30.2 "Counter Functions"
//Chapter 8.6 "IEC Counter Functions"
VAR
BCD1, BCD2, BCD3 : WORD; //BCD_value
Bin1, Bin2, Bin3 : WORD; //Binary_value
PV1, PV2, PV3 : WORD; //Counter value
Set1, Set2, Set3 : BOOL; //Set counter
Up1, Up2, Up3 : BOOL; //Count up
Down1, Down2, Down3 : BOOL; //Count down
Reset1, Reset2, Reset3 : BOOL; //Reset counter
Status1, Status2, Status3 : BOOL; //Counter status
Up : CTU; //SFB 0 IEC up counter
Up4 : BOOL := FALSE;
Reset4 : BOOL := FALSE;
Status4 : BOOL := FALSE;
Svalue4 : INT := 0;
Zvalue4 : INT := 0;
Down : CTD; //SFB 1 IEC down counter
Down5 : BOOL := FALSE;
Set5 : BOOL := FALSE;
Status5 : BOOL := FALSE;
Svalue5 : INT := 0;
Zvalue5 : INT := 0;
UpDown : CTUD; //SFB 2 IEC up-down counter
Up6 : BOOL := FALSE;
Down6 : BOOL := FALSE;
Reset6 : BOOL := FALSE;
Set6 : BOOL := FALSE;
VStatus6 : BOOL := FALSE;
ZStatus6 : BOOL := FALSE;
Svalue6 : INT := 0;
Zvalue6 : INT := 0;
END_VAR
BEGIN
//*****************************************************************************
//Starting the SIMATIC counter functions
//Up counter
BCD1 := S_CU(
C_NO := "Counter1",
CU := Up1,
S := Set1,
PV := PV1,
R := Reset1,
CV := bin1,
Q := Status1);
//Down counter
BCD2 := S_CD(
C_NO := "Counter2",
CD := Up2,
S := Set2,
PV := PV2,
R := Reset2,
CV := bin2,
Q := Status2);
//Up-down counter
BCD3 := S_CUD(
C_NO := "Counter3",
CU := Up3,
CD := Down3,
S := Set3,
PV := PV3,
R := Reset3,
CV := bin3,
Q := Status3);
//*****************************************************************************
//Starting the IEC counter functions
Up ( //Up counter
CU := Up4,
R := Reset4,
PV := Svalue4);
Status4 := Up.Q;
Zvalue4 := Up.CV;
Down ( //Down counter
CD := Down5,
LOAD := Set5,
PV := Svalue5);
Status5 := Down.Q;
Zvalue5 := Down.CV;
UpDown ( //Up-down counter
CU := Up6,
CD := Down6,
R := Reset6,
LOAD := Set6,
PV := Svalue6);
VStatus6 := UpDown.QU;
ZStatus6 := UpDown.QD;
Zvalue6 := UpDown.CV;
//*****************************************************************************
END_FUNCTION_BLOCK