The CTU and RES ...... Counter Instructions
- From the LogixPro Simulations Menu, select the I/O Simulation.
- Clear out any existing program by selecting the "New" entry in the
File menu, and then select the "Clear Data Table" entry in the Simulations
menu.
- Now enter the following program being careful to enter the addresses
exactly as shown.
- Confirm that you have entered the number 10 as the counter's
preset value. This value is optionally used to set the point at which the
counter's Done Bit will be Set, indicating that the count is complete.
- Once you have your program entered, and have ensured that it is
correct, download it to the PLC.
- Ensure that Switch I:1/0 and I:1/1 are Open, and then place the PLC
into the Run mode.
- Right click on the CTU instruction, and select "GoTo
DataTable" from the drop-down menu.
- Note the initial value of Counter C5:1's accumulator and preset
in the spaces below. Also indicate the state of each of the Counter's
primary control bits in the spaces provided:
Initial State (Switch I:1/0=Open):
C5:1.ACC = _______ C5:1.PRE = _______ C5:1/CU = ___ C5:1/CD = ___ C5:1/DN = ___
- Open and Close switch I:1/00 a number of times and carefully observe
the incrementing of C5:1's accumulator and the operation of the enable and
done bits.
- Close switch I:1/01 and observe the effect that the "RES" instruction
has on the counter.
- Attempt to increment the counter while switch I:1/01 is closed. You
should not be able to increment the counter while the "RES" instruction
is held "True".
- Open switch I:1/01 to allow the "RES" instruction to go false, and
then increment the counter until the accumulator matches the preset.
- Increment the counter 2 or 3 more times and note the final value of
C5:1's accumulator, preset and status bits in the spaces below.
Final State (Switch I:1/0=Closed):
C5:1.ACC = _______ C5:1.PRE = _______ C5:1/CU = ___ C5:1/CD = ___ C5:1/DN = ___
Conclusions:
The CTU output instruction counts up for each false-to-true transition of conditions
preceding it in the rung and produces an output (DN) when the accumulated value
reaches the preset value. Rung transitions might be triggered by a limit switch or
by parts traveling past a detector etc.
The ability of the counter to detect a false-to-true transitions depends on the
speed (frequency) of the incoming signal. The on and off duration of an incoming
signal must not be faster than the scan time.
Each count (accumulator) is retained when the rung conditions again become false,
permitting counting to continue beyond the preset value. This way you can base
an output on the preset but continue counting to keep track of inventory/parts, etc.
Use a RES (reset) instruction with the same address as the counter, or another
instruction in your program to overwrite the value of the accumulator and control
bits.
The on or off status of counter done, overflow, and underflow bits is retentive.
The accumulated value and control bits are reset when a RES is enabled.
The CTD ...... Count Down Instruction
Ensure that switch I:1/00 and I:1/01 are open; then place the PLC into
the Program mode, and Insert a new rung containing a CTD instruction just
below the first rung in your program.
- Once you have completed this addition to your program, download
your program to the PLC and select RUN.
- Toggle the state of switch I:1/0 continuously until the accumulator
of C5:1 exceeds the preset.
- Now toggle switch I:1/02 and decrement counter C5:1 while carefully
observing the status bits of the counter.
Increment and decrement the counter from below zero to beyond the
preset a number of times.
Conclusions:
The CTD output instruction counts down for each false-to-true transition of
conditions preceding it in the rung and produces an output when the accumulated
value reaches the preset value. Rung transitions might be triggered by a limit
switch or by parts traveling past a detector.
Each count is retained when the rung conditions again become false. The count is
retained until a RES (reset) instruction with the same address as the counter is
enabled, or if another instruction in your program overwrites the value.
The accumulated value is retained after the CTU or CTD instruction goes false,
and when power is removed from and then restored to the processor. Also, the on
or off status of counter done, overflow, and underflow bits is retentive.
The accumulated value and control bits are reset when a RES is enabled.
Applying Counter Instructions .... An Up/Down Sequence Example
- Ensure that the I/O Simulation is still selected.
- Clear your existing program by selecting the "New" entry in the
File menu, and then select the "Clear Data Table" entry in the Simulations
menu.
- Note the use of the "EQU" instruction in rung 2 of the following program.
This input instruction will go true if the value referenced by the Source
entry is "Equal" to the value contained in the Source B entry.
In this example, the instruction will go true if the accumulator of the counter
is equal to zero.
- Now enter the following program being careful to enter the addresses
exactly as shown.
- Once you have your program entered, and have ensured that it is
correct, download it to the PLC.
- Confirm that you have configured switch I:1/0 as a N.O. pushbutton
then place the PLC into the "Run" mode.
- Continuously Open and Close switch I:1/00 while carefully observing
the incrementing of C5:1's accumulator.
- If you have entered your program correctly, the accumulator should
increment until the count of 10 is reached, and then start to decrement.
When the count reaches zero, the B3:1/0 flag bit should be cleared and the
up/down sequence should then repeat.
- Ensure that your program is operating as described, and carefully note
how bit B3:1/0 is being employed to track and control the direction of the
counting sequence.
- Note the conditions that must be present in order for bit B3:1/0 to
be latched On. The first XIC instruction ensures that the latching only occurs
when the pushbutton switch is released
- Delete this XIC instruction from rung 1, and then download and run your
program again.
- Without the XIC instruction, the latching will occur as soon as the count
of ten is reached and the CTD instruction will immediately decrement the
counter back to a count of 9.
- Set the scan speed to it's lowest value, and you should be able to see that
the count does reach 10, but it is then immediately decremented.
Conclusions:
The CTU is by far the most commonly used counter instruction. It can, and is
utilized in almost a limitless number of counting applications, and is typically
very easy to understand and employ.
The CTD instruction is less widely employed. It is extremely useful
however when paired with a CTU, where up/down counting operations are required.
Cars entering and leaving a parking lot, containers being filled and then emptied
are just 2 examples of where paired CTU/CTD counters might be employed.
The elegance of the CTU/CTD pairing can extract a price however in terms of ease
of use and program clarity. As the last exercise highlighted, one requires a very
clear understanding of the operation of these instructions and the PLC's scan
sequence, in order to employ them effectively.
This last exercise was definitely not the only way to setup an up/down counting
sequence, but it does highlight the attention to detail that you will need to
demonstrate when tackling the later sections of the next student exercise.
......
|