##
**Counters in PLC | Types of PLC Counter**

**Counters count rung transitions.**

The

**CTU**runs the accumulated value of the counter up on the false to

true rung transition, and the

**CTD**instruction runs the accumulated value

down. The CTU and CTD can be used in

conjunction with each other. Counters consist of the following components: ACC

Accumulated Value PRE Preset Value CD Count Down Bit CU Count Up bit OV

Overflow Bit UN Underflow bit By default, data file C5 stores counters, however,

other counter files can be added as well. Below is how the C5 Data file would

appear:

For the CTU instruction:

The CU bit is high when the CTU instruction is true. The ACC value increments by the value of 1

each time the CU bit goes high. When the

ACC reaches the PRE, the DN bit will be

set. The CTU will continue to increment

the accumulated value until it reaches

the maximum possible value for a 16 bit signed integer (32767).

If the CU bit goes high one more time, the OV bit will be set, and the

ACC value will go to -32768. Each time

the CU bit goes high, the ACC value will still continue to increment (become

less negative).

The CU bit is high when the CTU instruction is true. The ACC value increments by the value of 1

each time the CU bit goes high. When the

ACC reaches the PRE, the DN bit will be

set. The CTU will continue to increment

the accumulated value until it reaches

the maximum possible value for a 16 bit signed integer (32767).

If the CU bit goes high one more time, the OV bit will be set, and the

ACC value will go to -32768. Each time

the CU bit goes high, the ACC value will still continue to increment (become

less negative).

For the CTD instruction:

The CD bit is high when the CTD instruction is true. The ACC value decrements by the value of 1

each time the CD bit goes high. Any time

the ACC is above or equal to the PRE,

the DN bit will remain set. The DN bit is reset if the ACC falls below the PRE

at any time. The CTD will continue to

decrement the accumulated value until it reaches the minimum possible value for

a 16 bit signed integer (-32768). If the

CD bit goes high one more time, the UN bit will be set, and the ACC value will

go to 32767. Each time the CD bit goes

high, the ACC value will still continue to decrement (become less positive).

The CD bit is high when the CTD instruction is true. The ACC value decrements by the value of 1

each time the CD bit goes high. Any time

the ACC is above or equal to the PRE,

the DN bit will remain set. The DN bit is reset if the ACC falls below the PRE

at any time. The CTD will continue to

decrement the accumulated value until it reaches the minimum possible value for

a 16 bit signed integer (-32768). If the

CD bit goes high one more time, the UN bit will be set, and the ACC value will

go to 32767. Each time the CD bit goes

high, the ACC value will still continue to decrement (become less positive).

####
Here

is a practical example of a CTU/CTD implementation:

is a practical example of a CTU/CTD implementation:

Each time a pizza goes into the oven, the ACC value is incremented

by one. Each time a pizza comes out of

the oven, the ACC value is decremented by one.

Therefore, the ACC value represents how many pizzas are in the oven at

any given time. The DN bit could be used

to shut the conveyor down if pizzas are going into the oven and not coming out!

by one. Each time a pizza comes out of

the oven, the ACC value is decremented by one.

Therefore, the ACC value represents how many pizzas are in the oven at

any given time. The DN bit could be used

to shut the conveyor down if pizzas are going into the oven and not coming out!