Introduction
Counters help count events in machines. Preset sets a target count. Reset clears the count back to zero.
COUNTER_NAME: CTU (CU, R, PV, CV, Q); Where: CU = Count Up input (boolean) R = Reset input (boolean) PV = Preset Value (integer) CV = Current Value (integer, output) Q = Output bit (true when CV >= PV)
Counter1: CTU(CU:=StartButton, R:=ResetButton, PV:=10, CV=>Counter1Value, Q=>Counter1Done);Counter2: CTU(CU:=SensorTrigger, R:=EmergencyStop, PV:=5, CV=>CountVal, Q=>DoneFlag);PROGRAM CounterExample VAR StartButton: BOOL := FALSE; ResetButton: BOOL := FALSE; CounterValue: INT := 0; CounterDone: BOOL := FALSE; END_VAR // Simulate pressing StartButton 3 times StartButton := TRUE; IF StartButton THEN IF NOT CounterDone THEN CounterValue := CounterValue + 1; IF CounterValue >= 3 THEN CounterDone := TRUE; END_IF END_IF END_IF StartButton := FALSE; // Reset the counter ResetButton := TRUE; IF ResetButton THEN CounterValue := 0; CounterDone := FALSE; END_IF ResetButton := FALSE; // Output current count and done status END_PROGRAM
preset value in a PLC counter do?CNT1 in ladder logic?RES is the standard instruction to reset a counter.PRE sets preset, INC increments, SET sets bits, not reset counter.RES CNT1 instruction. -> Option APass the test and this pattern moves unknown