Chapter 5: Timers and Counters

advertisement
Chapter 5: Timers and Counters
Computer Aided Manufacturing TECH 4/53350
1
Ladder Logic
Learning objectives

Describe the use of timers and counters in ladder
logic

Describe such terms as retentive,
retentive cascade,
cascade delay on
and delay off

E l i the
Explain
th operation
ti off TON,
TON TOF,
TOF and
d RTO timers
ti

Explain
p
the use of CTU and CTD timers

Utilize timers and counters in ladder logic
Computer Aided Manufacturing TECH 4/53350
2
Timers
Overview

Ti
Timers
are used
d to
t delay
d l actions
ti



Timing functions are vital in PLC applications


Keep an output on for a specified time after an input turns off
Keep an output off for a specified time before it turns on
Cycle times are critical in many processes
Many PLCs use block-type timers and counters

Compliance with IEC 61131-3 standards
Computer Aided Manufacturing TECH 4/53350
3
Block-Type Timer
E
Example
l
TON
I:2
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
0.1
50
0
DN
Above Timer is labeled T4:0
Ti
Timer
Attributes
A ib
Time Base:
 Timers are typically
yp
yp
programmed
g
with several different time bases


1 second, 0.1 second, 0.01 second, 0.001 second
Suppose time base is set to 0.1 and Delay increments is set to 50 
timer has 5 seconds delay (0.1 x 50)
Computer Aided Manufacturing TECH 4/53350
4
Block-Type Timer
Example
TON
I:2
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
0.1
50
0
DN
Preset Attribute:
 Preset value is the number of time increments timer must count
before changing the state of the output


Time Delay = Preset value x Time Base ( refer to previous example)
Preset can be constant or a variable
Computer Aided Manufacturing TECH 4/53350
5
Block-Type Timer
Example
TON
I:2
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
0.1
50
0
DN
Accum Attribute:
 [Rockwell] Timers have one input. When the input transits from low
to high, the timer will begin timing (Accum value)



Timers that do not lose their accumulated time when the enable input line
transitions to low again are known as Retentive Timers
Retentive Timers continue to maintain accumulated time and increment
the time when the input line goes to high again
Non-retentive Timers lose the accumulated time whenever the enable
input transitions to low

The accumulated time resets to zero
Computer Aided Manufacturing TECH 4/53350
6
Timer Block
Numbering System
TON
I:2
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
0.1
50
0
DN
Above Timer is calledT4:0
Timer
T4:0
Computer Aided Manufacturing TECH 4/53350
T
4
:
0
File Type
Fil
T
(Timer)
(Ti
)
File Number of the Timer
Delimiter
Element (The actual timer number)
7
Block-Type Timer
E
Example
l
TON
I:2
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
0.1
50
0
DN
Timer On (TON) Delay
Timer On Delay
y Instruction:
 Turns an output on after a Timer has been on for a preset time
interval


TON starts accumulating
g time when rung
g becomes true
Continue accumulating until one of the following occurs:


Accumulated (Accum) value equals preset value
The rung conditions becomes false
Computer Aided Manufacturing TECH 4/53350
8
Block-Type Timer
Status Bits (EN, DN, TT)
Timer Status bits can be used in ladder logic
Bit
S t When
Set
Wh
R
Remains
i Set
S t Till
Timer done Bit
(bit 13 or DN)
Accumulated value is
equal to or greater than the
preset value
Rung conditions go false
Timer Timing bit
(bit 14 or TT)
Rung conditions are true
and the accumulated value
is less than the preset
value
Rung conditions go false or
when the done bit is set
Timer enable bit
(bit 15 or EN)
Rung conditions are true
Rung conditions go false
Computer Aided Manufacturing TECH 4/53350
9
Using Status Bits in Ladder Logic
EN Bit
Timer Enabled bit can be used in ladder logic

Consider timer T4:0 from the example:

The Timer Enable (EN) bit is set immediately when the rung
goes true. It stays set until the rung goes false


The EN bit indicates that the timer T4:0 is enabled
The EN bit from any timer can be used for logic:

T4:0/EN could be used as a contact in a ladder
Computer Aided Manufacturing TECH 4/53350
10
Using Status Bits in Ladder Logic
TT Bit
Timer Timing (TT) bit can be used
sed in ladder
logic

C
Consider
id timer
ti
T4
T4:0
0 from
f
the
th example:
l

The Timer Timing (TT) bit is set when the rung goes true. It stays
set until the rung goes false or the Timer Done (DN) bit is set (i
(i.e.,
e
when accumulated value equals preset value)

The TT bit from any timer can be used for logic:

T4:0/TT could be used as a contact in a ladder
Computer Aided Manufacturing TECH 4/53350
11
Using Status Bits in Ladder Logic
DN Bit
Timer Done bit can be used
sed in ladder logic

Consider timer T4:0 from the example:

The Timer Done (DN) bit is not set until the accumulated value is
equal to the preset value. It stays set until the rung goes false

When DN bit is set, it indicates Timing operation is complete

The DN bit from any timer can be used for logic:

T4:0/DN could be used as a contact in a ladder
Computer Aided Manufacturing TECH 4/53350
12
Using Other Bits in Ladder Logic
Preset (PRE)

PRE can be used in ladder logic

T4:0 PRE would access the preset value of T4:0
T4:0.PRE


Accumulated Value (ACC)


Note, PRE value is an integer
T4:0.ACC would access the accumulated value of timer T4:0
Time Bases are available in 1 second intervals, 0.01 and 0.001
second intervals

Potential time ranges:
Time Base
Potential Time Range
1 Second
To 32,767 intervals (up to
9.1 hrs)
0 01 Second
0.01
To 32,767
32 767 intervals (up to
5.5 minutes)
0.001 Second
To 32,767 intervals (up to
0.546 minutes)
What if a longer time is needed?
Computer Aided Manufacturing TECH 4/53350
13
Memory Storage
Timers



15
14
13
EN
TT
DN
12
11
10
9
8
7
6
5
4
3
2
1
0
Internal Use
Bits
0 T4:0
Preset Value
1 T4:0.PRE
Accumulated Value
2 T4:0
T4:0.ACC
ACC
Current status of timer bits (EN, TT and DN) stored in first 16 bits
PRE value is held in the second 16 bit of timer storage
Third 16 bit holds accumulated value of timer
Computer Aided Manufacturing TECH 4/53350
14
TON Timer
Ladder Diagram
TON
I:2
3
T4:0
TIMER OFF DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
1.0
180
0
DN
O:5
TT
T4:0
DN
1
O:5
2
When input I:2/3 is true  timer begins to increment the accumulated value of TON Timer
T4:0 in 1 second intervals
The TT bit is used in rung 2 to turn on Output O:5/1, while the timer is timing (ACC <PRE)
The DN bit of timer 4:0 is used in rung 3 to turn an output O:5/2 when the timer is done
timing (ACC = PRE)





Note: the Preset for this timer is 180  The timer will have to accumulate 180 1-second intervals to time
out
Note: This is a non-retentive timer: If Input I:2/3 goes low before 180 is reached, the accumulated value
is reset to zero
Computer Aided Manufacturing TECH 4/53350
15
Timer OFF Delay
TOF
Timer OF (TOF) -Delay
Used to turn an output On or OFF after rung has
been off for a desired time

1.
2.
3.
4.
TOF starts to accumulate time when the rung becomes false
It continues to accumulate time until the accumulated value
equals the preset value or the rung becomes true
The timer enable bit (EN bit 15) is set when the rung becomes
true. It is reset when the rung becomes false and ACC < PRE or
the DN bit is reset (ACC = PRE)
The done bit (DN bit 13) is reset when the ACC value is equal to
g becomes true
the PRE value. The DN bit is set when the rung

Computer Aided Manufacturing TECH 4/53350
16
Timer Off Delay
TOF Bits
Bit
S t When
Set
Wh
R
Remains
i Set
S t Till
Timer done Bit
(bit 13 or DN)
Rung conditions are true
Rung conditions go false
and the accumulated value
is greater than or equal to
the preset value
Timer Timing bit
(bit 14 or TT)
Rung conditions are false
and the accumulated value
is less than the preset
value
Rung conditions go true or
when the done bit is reset
Timer enable bit
(bit 15 or EN)
Rung conditions are true
Rung conditions go false
Computer Aided Manufacturing TECH 4/53350
17
Ladder Logic
TOF Timer
TOF
I:2
3
TIMER OFF DELAY
Timer
Time Base
Preset
Acc
EN
T4:0
1.0
180
0
T4:0
This output is energized while the timer is timing
DN
O:5
TT
1
T4:0
This output is energized when the timer is done timing O:5
DN
2
Input I:2/3 is used to enable the timer



When input I:2/3 transitions from true to false  The ACC value is incremented
as long as the input stays false and ACC ≤ PRE
The TT bit for timer T4:0 (T4:0/TT) is used to turn output O:5/1 on while timer is
timing
The DN bit of timer 4:0 (T4:0/DN) is used to turn on output O:5/2 when the timer
has completed the timing (ACC = PRE)
Computer Aided Manufacturing TECH 4/53350
18
Retentive Timer On
RTO
RTO Instruction:
Used to turn an output On after a set time period

1.
The RTO timer is an accumulating timer. It retains the ACC
value
l even if th
the rung goes ffalse
l

2.
To zero the ACC value, use a reset (RES) instruction in another rung with
the same address as the RTO
The status bits can be used as contacts in the ladder diagram
Computer Aided Manufacturing TECH 4/53350
19
Retentive Timer On
Status Bits
Bit
Set When
Remains Set Till
Timer done Bit
(bit 13 or DN)
Accumulated value
≥ preset value
The appropriate RES
Instruction is enabled
Timer Timing bit
(bit 14 or TT)
Rung conditions are true
and the accumulated value
< preset value
Rung conditions go false
or when the done bit is set
Timer enable bit
(bit 15 or EN)
Rung conditions are true
Rung conditions go false
Computer Aided Manufacturing TECH 4/53350
20
Ladder Logic
RTO Timer
RTO
I0:2
3
TIMER OFF DELAY
Timer
Time Base
Preset
Accum
I0:2
EN
T4:0
10
1.0
180
0
DN
T4:0
RES
4

EN bit is set when rung becomes true

When EN is 1  Indicates Timer is timing



Note: EN remains 1until rung becomes false
TT bit is set when rung becomes true and remains set until ACC value equals
the preset value or RES instruction resets the timer
DN bit is set when the timer’s ACC value is equal to the preset value

When DN bit is set it indicates timing is complete
Computer Aided Manufacturing TECH 4/53350
21
Cascading Timers

When Application requires longer time delays
than a single timer can provide

Use multiple timers

When the first timer times out, it becomes an input to
start the second timer timing
Cascading Timers
TON
O
I:2.0
1
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:0
1.0
32,767
0
DN
TON
T4:0
DN
TIMER ON DELAY
Timer
Time Base
Preset
Accum
EN
T4:1
1.0
7233
0
DN
Two timers are used to extend the time delay

The first timer output, T4:0/DN, acts as input to second timer

When Input I:2.0 becomes true, timer 1 begins to count to 32,767
seconds (the limit of the timers)



When it gets to 32,767 seconds, output T4:0/DN turns on
This energizes timer T4:1
Timer T4:1 times to 7233 seconds (its preset value)

T4:1/DN turns on
What is the delay?
23
Counters

Counting is critical in industrial applications



Suppose 24 can go into a case
Then the 24th can must be sensed by the PLC
and the case is sealed
Primaryy Counter
C
Types
yp

UP Counters
Down Counters

Up/Down Counters

- PLC sense how many finished products leaving the machine
- PLC sense how many parts are left
- PLC monitors an automated storage system to track how
many are coming and how many are leaving to determine total number in stock

Choice used depend on the task
Counters
A ib
Attributes


Counters usually use low-to-high
low to high transition from
an input to trigger the counting action
Counters count the number of low-to-high
g
transitions on the input line


Similar to Timers, which count the number of time
increments
Counters also have a reset instruction to clear
th accumulated
the
l t d countt
Counters (CTU)
Edge-Triggered
Edge
Triggered
CTU
I:2
Count Up
Counter
Preset
Accum
3
EN
C5:0
10
0
DN
C5:0
O:5
Energized when the Accum >= Preset
DN
Input I:2/3
Status
1
On
Of
Output O:5/1 On
Of
Status
0
1
2
10
11
The rising edge triggers the counter

I:2/3 counts the pulses:


Each time there is an Of to On transition, the Counter increments its count by 1 (CTU)
When the Accumulate count equals the preset value, the counter turns on

Turns on Output O:5/1
How does CTD work?
Computer Aided Manufacturing TECH 4/53350
26
Counters
Numbering System
How counters are addressed:
C5:0
Computer Aided Manufacturing TECH 4/53350
C
5
:
0
File Type
File Number of the counter
Delimiter
Element (The actual counter number)
27
Counters in Ladder Logic
Accessing Counter Values
To use the Done Bit:
C5 4 DN
C5:4.DN
To use the Preset Value
C5:4.PRE
To use the Accumulated Value
Computer Aided Manufacturing TECH 4/53350
C5:4.ACC
28
Memory Storage
CTU Counter Bits
15
Bits
CU



13
12
DN
OV
11
10
9
8
7
6
5
4
3
2
1
Internal Use
0
Element
0 C5:0
Preset Value
1 C5:0.PRE
Accumulated Value
2 C5:0
C5:0.ACC
ACC
Count Up
p ((CU),
), Done ((DN)) and Overflow ((OV)) bits are stored in first 16 bits
The CPU sets the OV bit when the counter exceeds upper limit +32,767


14
ACC wraps around to -32,767 and continues from there towards zero
PRE value is held in the second 16 bit of counter storage
Thi d 16 bit h
Third
holds
ld accumulated
l t d value
l off counter
t
Computer Aided Manufacturing TECH 4/53350
29
CTU Counter Bits
Bit
S t When
Set
Wh
R
Remains
i Set
S t Till
Count-up Overflow bit
(bit 12 or OV)
Accumulated value wraps
around to -32,768 (from
+32 767) and continues up
+32,767)
from there towards zero
A RES instruction that has
same address as the CTU
instruction is executed or
the count is decremented
less than or equal to
+32,767 with a CTD
instruction
Done bit
(bit 13 or DN)
The accumulated value is
=> the preset value
The accumulated value
becomes less than the
preset value
Count up enable bit (bit 15
Count-up
or CU)
Rung conditions are true
Rung conditions go false or
a RES instruction that has
the same address as the
CTU instruction is enabled
Count-Up Counter
Ladder Diagram
CTU
I:2
3
COUNT UP
Counter
Preset
Accum
EN
C5:0
4
0
C5:0
Energized
g
when the Accumulated ≥ Preset
DN
O:5
DN
1
C5:0
Energized
g
when the counter overflows
O:5
OV
2
Input I:2/3 is used to enable the counter
Each time I:2/3 makes a low-to-high transition, the counter ACC value gets
incremented by1


The DN bit is set when the ACC value ≥ the Preset value
The DN bit of C5:0 (C5:0/DN) is used to turn on O:5/1 when ACC ≥ Preset value
The OV bit of C5:0 (C5:0/OV) is used to set O:5/2 when <What happens?>



See next slide
Computer Aided Manufacturing TECH 4/53350
31
Count-Up Counter
Ladder Diagram
CTU
I:2
3
COUNT UP
Counter
Preset
Accum
EN
C5:0
4
0
C5:0
Energized
g
when the Accumulated >= Preset
DN
O:5
DN
1
C5:0
Energized
g
when the counter overflows
O:5
OV
I:2
2
Reset
ese cou
counter
e to
o zero
eo
C5:0
RES
1
The OV bit of C5:0 (C5:0/OV) is used to set O:5/2



if the count reaches +32,767
Bit 1 of contact I:2/1 is set to true(1) this causes the RES instruction to reset CTU C5:0’s ACC value (i.e
“Accum”) to zero
Computer Aided Manufacturing TECH 4/53350
32
Count-Down Counter
Ladder Diagram
CTD
I:2
3
COUNT DOWN
Counter
Preset
Accum
CD
C5:0
4
0
C5:0
Energized
g
when the Accumulated ≥ Preset
DN
O:3
DN
1
C5:0
Energized
g
when the counter underflows
O:3
UN
I:2
2
Resets
ese s cou
counter
e to
o zero
eo
C5:0
RES
1
Input I:2/3 is used to enable the counter

Each time input I:2/3 makes a 01 transition, the counter ACC value gets decremented by1




The DN bit is set when the ACC value ≥ the Preset value
The DN bit of C5:0 (C5:0/DN) is used to turn output O:3/1 on when Accum ≥ Preset value
The UN bit of C5:0 (C5:0/UN) is used to set OUTPUT O:3/2 ON when the ACC value
underflows (-32,768)
Input I:2/1 is used to reset the C5:0’s ACC value to zero
Computer Aided Manufacturing TECH 4/53350
33
CTD Counter Bits
Bit
S t When
Set
Wh
R
Remains
i Set
S t Till
Count-down Underflow bit
(bit 11 or UN)
Accumulated value wraps
around to +32,768 (from:
-32,767)
32 767) and continues
counting from there
A RES instruction that has
same address as the CTD
instruction is executed or
the count is incremented
greater than or equal to
+32,767 with a CTU
instruction
Done bit
(bit 13 or DN)
The accumulated value is
≥ the preset value
The accumulated value
becomes less than the
preset value
Count down enable bit (bit
Count-down
14 or CD)
Rung conditions are true
Rung conditions go false or
a RES instruction that has
the same address as the
CTDinstruction is enabled
Memory Storage
CTU and CTD Counter Bits
Bits
15
14
13
12
11
CU
CD
DN
OV
UN


8
7
6
5
4
3
2
Internal Use
1
0
Element
0 C5:0
Preset Value
1 C5:0.PRE
Accumulated Value
2 C5:0
C5:0.ACC
ACC
ACC wraps around to -32,767 and continues incrementing from there towards
zero to +32,767
The CPU sets the UN bit when the counter exceeds lower limit -32,767



9
Count Up (CU), Count Down (CD), Done (DN), Overflow (OV) and
Underflow (UN) bits are stored in first 16 bits
The CPU sets the OV bit when the counter exceeds upper limit +32
+32,767
767


10
ACC wraps around
d tto +32,767
32 767 and
d continues
ti
d
decrementing
ti ffrom th
there ttowards
d
zero to -32,767
PRE value is held in the second 16 bit of counter storage
Third 16 bit holds accumulated value of counter
Computer Aided Manufacturing TECH 4/53350
35
Cascading Counters
CTU
I:2.0
1
COUNT UP
Counter
Preset
Accum
EN
C5:0
24
0
DN
CTU
C5:0
DN
COUNT UP
Counter
Preset
Accum
EN
C5:1
5000
257
DN
C5:0
RES
Two counters are used to extend the count

Counter C5:0 is used to count 24 cans for each case


When C5:0 ACC value ≥ 24, DN bit is set
The CTU C5:0/DN energizes CTU C5:1

The C5:1 Acc value is incremented to count number of cases of 24 cans

The ladder diagram shows 257 cases of 24 cans
36
Download