Skip to content
Ladder (NT)Runs without an account · Updated

Bottle counter ladder logic with a CTU counter

A count-up counter adds one each time its rung goes from false to true. This example uses one to count bottles past a sensor into a case of six, flag the case as full, and reset for the next one.

Run it
The bottle counter example running in PLCflow Sim. Four bottles have been counted towards a case of six.
Bottle counter, running in the PLCflow Sim workspace.

The program

XIC(BottleSensor)CTU(BottleCount,6,0);
XIC(BottleCount.DN)OTE(CaseFull);
XIC(NextCase)RES(BottleCount);

How it works

Rung 0 is the counter. CTU(BottleCount,6,0) has a preset of 6 and an accumulator that starts at 0. Each time BottleSensor goes from off to on, ACC goes up by one. A bottle that sits in front of the sensor counts once, however long it stays there, because the counter only acts on the change.

When ACC reaches the preset, the counter's DN bit sets. Rung 1 uses it to turn on CaseFull.

The counter doesn't stop at its preset. A seventh bottle takes ACC to 7 and DN stays on. If the line has to stop at six, another rung has to stop it.

Rung 2 resets it. RES(BottleCount) puts ACC back to 0 and clears DN, so CaseFull drops and the next case starts counting.

One thing to know about RES: it also clears the bit the counter uses to remember that its rung was already true. If a bottle is in front of the sensor when you reset, the counter takes it for a new bottle and the next case starts at 1.

Try this

In the simulator, an input changes when you click it in the tag list: click once to turn it on and again to turn it off. To press a button, turn it on; to release it, turn it off; to pulse it, do both.

  1. Turn BottleSensor on and off six times. BottleCount.ACC reaches 6 and CaseFull turns on.
  2. Pulse it once more. ACC goes to 7 and CaseFull stays on.
  3. Pulse NextCase. ACC returns to 0 and CaseFull turns off.
  4. Leave BottleSensor on, then pulse NextCase. The count comes back as 1. Why?
Run it

Tags

TAGROLE
BottleSensorBOOL input. Photo-eye, on while a bottle is in front of it.
BottleCountCOUNTER. Counts up, preset 6.
CaseFullBOOL output. On once six bottles have been counted.
NextCaseBOOL input. Resets the count for the next case.

More examples

Conveyor with dwell

Ladder (NT)

The belt runs, a 5-second timer gives it time to get up to speed, and only then does the ready lamp light. Watch the accumulator climb.

RunRequestDwellTimer.ACCReadyLamp

One-shot toggle

Ladder (NT)

One button turns a lamp on, and the same button turns it off. A one-shot makes each press count exactly once, however long you hold it.

ButtonPulseLamp

Read more about the ladder logic simulator, or see all examples.