Counter – ST

The IEC 61131 standard offers a definition of Counters. PLC3000 integrates up and down Counters. It is necessary to define a preselection value %Ci.PV, which can be set with an integer value. The current value of a counter is set to 0 when %Ci.R is activated. The current value of a counter is set to the preselection value %Ci.PV, when %Ci.LD is activated. The current value of a counter is incremented each time the %Ci.CU input is activated, and decremented each time the %Ci.CD input is activated.

A counter has two outputs; %Ci.QU goes to 1 when the current counter value is equal to or higher than the preselected value %Ci.PV; %Ci.QD goes to 1 when the current counter value is equal to 0.

Generation in ST

IF %S1 THEN
   %C1.PV := 5;
END_IF

Illustration with a Grafcet

Let’s considering the following Grafcet

Programming in ST – Step/Step with Crossing Bits

PROGRAM Counter
(* TIMER *)
IF %S1 THEN
    %C0.PV := 5;
END_IF

(* EDGE *)
%M4 := %I1 AND NOT %M3;
%M3 := %I1;

(* STEP *)
%M10 := (%M2 AND %C0.QU) OR (%M0 AND NOT %I0) OR %S2;
%M11 := ((%M0 AND %I0) OR (%M2 AND NOT %C0.QU) OR (%M1 AND NOT %M4)) AND NOT %S2;
%M12 := (%M1 AND %M4) AND NOT %S2;

(* CROSSING *)
IF %M10 THEN
    %M0 := TRUE;
    %M1 := FALSE;
    %M2 := FALSE;
END_IF

IF  %M11 THEN
    %M1 := TRUE;
    %M0 := FALSE;
    %M2 := FALSE;
END_IF

IF  %M12 THEN
    %M2 := TRUE;
    %M0 := FALSE;
    %M1 := FALSE;
END_IF

(* ACTIONS *)
%C0.R := %M0;
%C0.CU := %M2;

END_PROGRAM