Menu
CoddyTech

Counters in Text

Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 8 of 17.

Counters are blocks too. A CTU takes CU (count up), R (reset) and PV (the preset), and gives CV (the count) and Q (CV has reached PV):

VAR
    C1 : CTU;
END_VAR

C1(CU := Entry, PV := 6);
Display := C1.CV;

The CU input counts rising edges on its own: a box that blocks the eye for 80 scans counts once. A CTD counts down the same way, with CD, LD and PV.

The belt runs from a seal-in, already written for you as the first statement.

challenge icon

Challenge

Easy
  • Count the boxes that pass the Entry eye with a CTU.
  • Show the count on Display.
  • Light Lamp when 6 boxes have passed.

Press Run, try it on the machine, then Check.

Try it yourself

VAR
    C1 : CTU;
END_VAR

Belt := (Start OR Belt) AND Stop;

// Count boxes on Entry, then Display and Lamp

All lessons in Structured Text

Practice on your own: PLC playground