The text of a manual · part 4 of 14
Mini-PLC-2 Programmable Controller Programming and Operations Manual, pages 31 to 40
Pages 31 to 40 of 132
The original document is the PDF (13 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 1772-LN2 and Allen-Bradley 1772-LN3
Page 31
Page 4-1
Section 4 TIMER AND COUNTER INSTRUCTIONS
4.0 GENERAL
Timer and Counter instructions are output instructions internal to the Processor. They provide many of the capabilities available with timing relays and solid state timing/counting devices. Usually conditioned by Examine in- structions, timers and counters keep track of timed intervals or counted events according to the logic continuity of the rung. Up to 40 internal timers and/or counters can be pro- grammed.
Each Timer or Counter instruction has two 3-digit values associated with it, and thus requires two words of Data Table memory. These 3-digit values are:
e Accumulated (AC) Value, Stored in the Accumulated Value area of the Data Table starting at word address 030,. For timers, this is the number of timed intervals that have elapsed. For counters, this is the number of events that have been counted.
e Preset (PR) Value, Stored in a Preset Value area of the Data Table, always 100, words greater than its corresponding AC Value. This value is entered into memory. The Preset value is the number of timed intervals or events to be counted. When the Accumulated value equals the Preset value, a status bit is set ON and can be examined to turn ON or OFF an output device.
The Accumulated and Preset values are stored in the Data Table in 3-digit BCD (Binary Coded Decimal) format. BCD numbers can range from 000 to 999 when stored in the lower 12 bits of a memory word (Figure 4-1). Each BCD digit is represented by a group of 4 bits. The arrangement of “1’s” and “0’s” in a group of 4 bits corresponds to a decimal number from 0 to 9. For more information on number- ing systems, refer to Section 13.
The remaining 4 bits in a word (bits 14-17) are not used to form a BCD number. In the Accumulated Value word, they are used as status bits. In the Preset Value word, they are not used and are available for internal storage. With .01 second timers, these bits are used for internal timing functions and cannot be used for storage. For more information on bit storage, refer to Section 8.3.4.
4.1 TIMER INSTRUCTIONS
A timer counts elapsed time-base intervals (1.0, 0.1 or .01 seconds) and stores this count in its Accumulated Value word. When timing is complete (when AC = PR), bit 15 is either set ON or OFF depending on the type of timer instruction. For all timers, bit 17 is set ON when rung conditions are TRUE and is set OFF when they are FALSE. Both status bits are located in the Accumulated Value word as shown in Figure 4-2., - - - - - - _ LOWER 12 BITS
~, >>
| 1 |
22 22 21 90193 92 91 90 le LACE VALUE OF BITS*
_J“ - DATA TABLE WORD
!
23 22 21 90 Oy; 4/1) O0}4)7 0}; 0} 141]0}0]0)1 ‘Y \ ‘ 7
_~ \ / a
\ 10 _ 6 \ 9 / 1 L Zz »~ \ vo
* EXPONENTIAL FORM: 2°= 1, 2'=2,2?=423=8
FIGURE 4-1, BCD Format
Page 32
Page 4-2
ACCUMULATED VALUE
IN BCD FORM A .
f
17 16 15 14 13 12
11-10 07 O06 05 04 03 02 01 00
ENABLE BIT.
THIS BIT IS SET
TO 1 WHEN TIMER RUNG CONDITIONS ARE TRUE
MOST | SIGNIFICANT | DIGIT DIGIT =!
TIMED BIT.
THIS BIT IS SET TO 1 ORO WHEN THE TIMER HAS TIMED OUT, THAT IS AC = PR
MIDDLE | LEAST | SIGNIFICANT DIGIT
FIGURE 4-2, Timer Accumulated Value Word
The four timer instructions available with the Mini-PLC-2 Controller are:
e TIMER ON-DELAY -(TON)- e TIMER OFF-DELAY -(TOF)- e RETENTIVE TIMER -(RTO)- e RETENTIVE TIMER RESET -(RTR)-
The timers differ in the way they set and reset Status bits, respond to rung logic continuity and reset the Accumulated Value. They are similar in time base selection. One of the following time bases must be selected when entering the instruction.
e 1.0 second e 0.1 second ¢ 0.01 second (10 milliseconds)
Bit 16 of the timer Accumulated value word reflects the time base. It willgo ON and OFF at the selected time base rate. Therefore, do not use bit 16 of a timer instruction in User Program as an output or storage bit.
4.1.1 TIMER ON-DELAY Instruction
The TIMER ON-DELAY instruction (TON) can be used to turn a device ON or OFF once an interval is timed out.
Refer to Figure 4-3. When the rung condition for a TIMER ON-DELAY instruction becomes TRUE, the timer begins to count time-base intervals. The “Enable” bit, bit 17, is set ON whenever the rung condition is TRUE and the timer is enabled (rung 1). As long as the rung condition remains TRUE, the timer increments its Accumulated value for each interval. When the Accumulated value equals the programmed Preset value, the timer stops incrementing its Accumulated value and sets the “timed” bit, bit 15, of this word ON. Bit 15 is then used to turn an output device ON or OFF, as acondi- tion for program logic (rung 2).
Whenever the rung condition for the TON instruction goes FALSE, the Accumulated value is reset to 000 and bits 15 and 17 of that word are reset to zero. The Accumulated value and status bits are also reset when the Mode Select Switch is turned to the PROG position or when there is a loss of power.
4.1.2 TIMER OFF-DELAY Instruction
The TIMER OFF-DELAY instruction (TOF) can be used to turn a device OFF or ON aftera timed interval. Like the other timer instructions, the TOF instruction counts time-base intervals which are stored in its Accumulated Value word. The TOF instruction, however, varies from the other instructions in significant ways.
Refer to Figure 4-4. The TIMER OFF-DELAY instruction begins to time an interval as soon as its rung condition goes FALSE. The Enable bit, bit 17, goes FALSE when the timer begins (rung 1). Aslong as its rung condition remains FALSE, the TOF instruction continues to time, until the Accumulated Value equals the Preset
Page 33
Page 4-3
ACCUMULATED VALUE AND STATUS BITS ARE RESET WHEN INPUT SWITCH IS OPENED.
el
ON INPUT SWITCH 113/02 OFF VAN, Yjy nL | ON =, >. PRESET VALUE =~ ~~, _ - ____ Po 3°! | | ACCUMULATED VALUE 0 ON TIMED BIT 033/15 OFF ; | ON OUTPUT LAMP 011/04 OFF | | 01 2 3 45 6 7 8 9 10 11 12 TIME IN SECONDS INPUT SWITCH TIMER ON DELAY 113 033 RUNG 1, TON INSTRUCTION |} (TON) PRESET FOR 9 SEC DELAY 02 10 PR 009 AC 009 TIMED BIT OUTPUT LAMP RUNG 2, TIMER TURNS ON 033 on, _ i { kH BIT 011/04 WHEN TIMED OUT. 15 64
FIGURE 4-3, TIMER ON-DELAY Timing Diagram & Programming
Value. When the TOF instruction times out, bit 15 is set to zero (OFF) which turns OFF the Output (rung 2).
The Accumulated Value is reset to 000 and bit 15 is set ON when the rung condition again goes TRUE. The next timed interval begins when the rung condition goes FALSE.
Bit 17, the enabled bit, is controlled by the logic continuity of the rung. When the rung is TRUE, bit 17 is set to ONE (ON); when it is FALSE, bit 17 is set to zero (OFF).
4.1.3 RETENTIVE TIMER Instruction
The RETENTIVE TIMER instruction (RTO), like the TON instruction, can be used toturna device ON or OFF once a programmed Preset value is reached.
Unlike the TIMER ON-DELAY instruction, the RETENTIVE TIMER instruction retains its Accumulated value when any of the following conditions occur:
e Rung condition goes FALSE.
Page 34
Page 4-4
| ON
STATUS BITS ARE SET TO 1 AND ACCUMULATED VALUE IS RESET WHEN INPUT SWITCH IS CLOSED.
INPUT SWITCH 113/05 OFF YU. | ON ENABLE BIT 047/17 OFF Wijj3
] PRESET VALUE, - -, - -~ - - ~ ~~~, JI- - - --- KK 8-
|
|
I
ACCUMULATED VALUE 0 ON |
TIMED BIT 047/15
OFF Ye
YY Y
OUTPUT LAMP 011/04 ore LI:
LL.
01 2 3 4 5 6 7 8 9 10 114 12 TIME IN SECONDS INPUT SWITCH TIMER OFF DELAY RUNG 1 - TOF INSTRUCTION |_| vor ~ (TOF PRESET FOR 9 SEC DELAY r 05 “40 PR 009 AC 009 TIMED BIT OUTPUT LAMP 047 011 RUNG 2, TIMER TURNS OFF } - ( 4 BIT 011/04 WHEN TIMED OUT. 15 04
FIGURE 4-4, TIMER OFF-DELAY Timing Diagram & Programming
* The Mode Select Switch is changed to the PROG position.
e A power outage occurs provided memory backup power is maintained.
Refer to Figure 4-5. When the rung condition goes TRUE, the enabled bit (bit 17) is set ON and the timer starts counting time-base intervals (rung 1). Any time the rung goes FALSE, bit 17 is set OFF but the Accumulated value is retained. When the timer times out, the timed bit (bit 15) is set ON which turns ON an output (rung 2).
By retaining its Accumulated value, the RTO instruction measures the cumulative period during which the rung condition is TRUE. Because this timer retains its Accumulated value, it must be reset by a separate instruction, the RETENTIVE TIMER RESET (RTR) instruction (rung 3).
4.1.4 RETENTIVE TIMER RESET Instruction
The RETENTIVE TIMER RESET instruction (RTR) is used to reset the Accumulated value and timed bit of the Retentive Timer to zero. This instruction is given the same word address
Page 35
Page 4-5 as its corresponding RTO instruction as shown in figure 4-5. When the rung condition goes true, the RTR instruction resets the Accumu- lated value and status bits of the RTO instruction to zero.
4.1.5 Timer Accuracy for 10 msec Timers
The accuracy of the 10 msec timer is related to nominal scan time. When scan times are 9 msec or less, the 10 msec timer is accurate to
TRUE
BIT IS INPUT SWITCH 113/06 FALSE LL.M Uj Mf RESET
ENABLE BIT 052/17 |
PRESET VALUE _o We
AC VALUE RETAINED WHEN RUNG CONDITION GOES FALSE ee Vs , SWITCH IS
WHEN RESET SWITCH IS CLOSED, TIMED BIT {S RESET. ACCUMULATED VALUE IS RESET AND HELD AT
ZERO UNTIL RESET SWITCH IS OPENED.
j~< - - ! ENABLE t l
WHEN INPUT
OPENED.
| 0 FY ACCUMULATED VALUE oe on | TIMED BIT 052/15 OFF _4 ! ON |! | | OUTPUT LAMP 011/04 OFF | MA. ON | I RESET SWITCH 113/07 OFF __| Y2 | | 01 2 3 4 5 67 8 9 10 11°12 TIME IN SECONDS INPUT SWITCH RUNG 1: RETENTIVE || 113 052 TIMER PRESETFOR -4 |, {RTO}~+ 9 SEC DELAY 06 1.0 PR 009 AC 009 TIMED BIT OUTPUT LAMP RUNG 2: TIMER TURNS ON 052 010 BIT 010/04 WHEN TMES OUT. [4 FE { a RESET SWITCH 113 052 RUNG 3:RESETSTHE Ly (RTR) - RETENTIVE TIMER. 07 PR 009 AC 009
FIGURE 4-5, RETENTIVE TIMER with RESET Timing Diagram & Programming
Page 36
Page 4-6 plus or minus one time base (+10 msec). When the scan time is greater than 9 msec, accuracy of +10 msec can be achieved through special programming techniques described in Programming 0.01-Second Timers, Section 11.4.
4.2 COUNTER INSTRUCTIONS
Three types of counter instructions are available with the Mini-PLC-2 Controller. They are:
e UP-COUNTER -(CTU)- e COUNTER RESET -(CTR)-
¢ DOWN-COUNTER -CTD)-
A counter counts the number of events that occur and stores this count in its Accumulated Value word. The remaining four bits in the Accumulated Value word are used as status bits. See Figure 4-6.
e Bit 14 is the Overflow/Underflow bit. It is set to 1 when the AC value of the CTU instruc- tion exceeds 999 or the AC value of the CTD instruction goes below 000.
e Bit 15 is set to 1 when a count has been reached or exceeded, that is, when the AC value is = PR value.
e Bit 16 is the Enable bit for a CTD instruction. It is set ON when the rung condition is TRUE.
e Bit 17 is the Enable bit for a CTU instruction. It is set ON when the rung condition is TRUE.
Counter instructions differ from Timer instructions because they have no time-base. They count one event each FALSE-to-TRUE transi- tion of the rung condition.
4.2.1 UP-COUNTER Instruction
The UP-COUNTER instruction (CTU) incre- ments its Accumulated value for each FALSE- to-TRUE transition of the rung condition. Because only the FALSE-to-TRUE transition causes acount to be made, the rung condition must go from TRUE to FALSE and back to TRUE before the next count is registered. The CTU instruction retains its Accumulated value when:
¢ Mode Select Switch is changed to the PROG position.
AC >PR v
-SET TO 1 WHEN
UP-COUNTER ENABLE BIT
ACCUMULATED VALUE IN BCD FORM i a, N\ 17 16 15 14 13 12 11 10 07 06 05 04 03 02 01 00
1 MOST 4} | SIGNIFICANT ! DIGIT |
MIDDLE ! LEAST DIGIT ! SIGNIFICANT 1 DIGIT
OVERFLOW/UNDERFLOW BIT SET TO 1 WHEN CTU OVERFLOWS 999 OR CTD UNDERFLOWS 000.
DOWN-COUNTER ENABLE BIT
FIGURE 4-6, Counter Accumulated Value Word
Page 37
Page 4-7 e The rung condition goes FALSE.
e A power outage occurs provided memory backup power is maintained.
Refer to Figure 4-7. Each time the CTU rung goes TRUE, bit 17, the Enable bit, is set ON (rung 1). When the Accumulated value reaches the Preset value, the Count Complete bit, bit 15, is set ON (rung 2). Unlike a timer, the CTU instruction continues to increment its Accumulated value after the Preset value has been reached. If the Accumulated value goes above 999, bit 14 is set ON to indicate an overflow condition and the CTU continues up-counting from 000 (rung 3). Bit 14 stays ON until the counter is reset. Bit 14 can be examined to cascade counters for counts greater than 999 (Section 4.3). Because this counter retains its Accumulated value, it must be reset by a separate instruction, the COUNTER RESET (CTR) instruction.
ACCUMULATED VALUE
EVENT TO BE COUNTED,111/11
| ENABLE BIT ON 053/17 OFF | | =PR - p + 2 | COUNT COMPLETE ON; AC=PR GF Yh Y BIT 053/15 OFF! ! Yo | | De OUTPUT LAMP ON; Yy Y YF YY 013/06 OFF | Vj l | | | OVERFLOW BIT ON; | ( ( Gg Yi 053/14 OFF! | Ys | ana OVERFLOW OUTPUT ON| l ( ( LL: 013/07 OFF |__ | )) VY RUNG 1:CTU| 111 COUNT SWITCH 053 INSTRUCTION PRESET 1 } - (CTU}H TO9. 11 PR 009 AC 009
RUNG 2: COUNTER TURNS ON BIT
013/06 AT COUNT [44
COMPLETE.
RUNG 3: COUNTER
TURNS ON BIT 013/07 |
AT OVERFLOW.
1 2 3
7
OVERFLOW BIT COMES ON AT 1000th EVENT. THE COUNTER DOES NOT
RESET. NY
I
8 997 998 999 !0
9 10 11 1 2
ON OFF
053 COUNT COMPLETE BIT ouTPuT Lamp 913
15
053 OVERFLOW BIT
\
06
OVERFLOW Lamp 013
14
4 07
FIGURE 4-7, UP-COUNTER Diagram & Programming
Page 38
Page 4-8
4.2.2 COUNTER RESET Instruction
The COUNTER RESET instruction (CTR) is an output instruction that resets the CTU Accumulated value and status bits to zero when the reset rung goes TRUE.
Refer to Figure 4-8. The counter operates in the same manner as described for the CTU instruction, with the addition of the Reset instruction (rung 3).
In this example, the reset pushbutton is pressed after count 12. When the pushbutton is released, the next event starts the sequence at count 1.
The CTR instruction is given the same word address as the CTU instruction. The Preset and Accumulated values are automatically displayed when the word address is entered.
4.2.3 DOWN-COUNTER Instruction
The DOWN-COUNTER instruction (CTD) sub- tracts one from its Accumulated value for each FALSE-to-TRUE transition of its rung condition. Because only the FALSE-to-TRUE transition causes a count to be made, the rung condition must go from TRUE to FALSE and back to TRUE before the next count is registered.
The CTD instruction Accumulated value is retained when:
¢ Mode Select Switch is changed to the PROG position.
¢ The rung condition goes FALSE.
e A power outage occurs provided memory backup power is maintained.
ACCUMULATED VALUE 1 2 3 4 5 6 7
8 191011 12
EVENT TO BE COUNTED 111/11
RUNG 2: COUNTER
053 COUNT COMPLETE BIT i I ENABLE BIT oy | 05917 cert |] | TE] ni PUL UL WLU l COUNT _ | WHEN RESET COMPLETE BIT ON! AC=PR, s ! PUSHBUTTON IS 053/15 OFF | Yi CLOSED, COUNT | ; | | COMPLETE BIT OUTPUT LAMP ON, % t IS RESET. 013/06 OFF! “iy | ACCUMULATED RESET 7 1 VALUE IS PUSHBUTTON ON! PUSHBUTTON IS 111/05 OFF} I YW RELEASED. RUNG 1:CTU | 111 COUNT SWITCH 053 INSTRUCTION PRESET }{ }~ {CTU} TOY. if PR 009 AC 009
OUTPUT LAMP 013
TURNS ON BIT | ( 013/06 AT COUNT 15 06 COMPLETE. RUNG 3: RESET SWITCH | 111 RESET PUSHBUTTON 053 RESETS THE CTU +4 + {CTR} INSTRUCTION. 05 PR 009 AC 009
FIGURE 4-8, UP-COUNTER with RESET Diagram & Programming
Page 39
Page 4-9
Each time the CTD instruction rung goes TRUE, bit 16, the Enable bit, is set ON. When the Accumulated value is greater than or equal to the Preset value, bit 15 is set ON. When the Accumulated value goes below 000, bit 14 is set ON to indicate an underflow condition and the CTD instruction continues down-counting from 999.
Normally, the DOWN-COUNTER instruction is paired with the UP-COUNTER instruction to form an up/down counter, using the same word address, AC value and PR value as shown in Figure 4-9.
NOTE: Bit 14 of the Accumulated Value word is set ON when the Accumulated value either “overflows” or “underflows.” Because of this, bit 14 may require monitoring in some appli- cations. When a DOWN-COUNTER Preset is set to 000, Underflow bit 14 will not be set ON when the count goes below zero.
When used alone, the CTD instruction’s Ac- cumulated value may need to be “reset” in the program to its original value (usually a value other than 000). For this reason, a GET/PUT transfer (described in Section 5.1) rather than a CTR instruction is usually used to load a value in the CTD instruction’s Accumulated Value word.
4.3 CASCADING TIMERS OR COUNTERS
An individual timer or counter can time or count up to 999 intervals or events. By “cascading” two or more timers or counters, the timing or counting capability within the program can be increased beyond three digits.
To cascade timers or counters, each timer or counter is assigned a different word address (Figure 4-10). The status bit of the first timer (bit 15) changes status each time the Preset value is reached. The status bit of a counter (bit 14) is set ON each time a counter over- flows. The status bit of the timer or counter is then used to increment the second timer or counter and reset the first to 000.
4.4 PROGRAMMING TIMER AND COUNTER INSTRUCTIONS
Timer and Counter instructions are pro- grammed from the Industrial Terminal key- board with the Processor in the PROGRAM mode. Allowable addresses are 030, through 077,.
Timer instructions are programmed by enter- ing the word address of the Accumulated value, atime base and a Preset value. With the RTO instruction, an Accumulated value can also be entered. The time base of 1.0, 0.1 or 0.01 second is entered as [1][0], [0][1], or [0][0] respectively.
Counter instructions are programmed by entering the word address of the Accumulated value, a Preset value, and if desired, an Accumulated value. Press [CANCEL COM- MAND] if no Accumulated value is desired.
110 046 op Roe | ~ Up-count AC 114 EVENT 110 046 bp tem | pown-count AC 114 EVENT 110 046 Mt by these | ~ COUNTER AC 114 RESET EVENT
FIGURE 4-9, UP/DOWN COUNTER Example
Page 40
Page 4-10
UP-COUNT
COUNTER 050 OVERFLOW BIT
FIRST INCREMENTS COUNTER 051 tT R
HEN OVERFLOW BIT ESETS COUNTER 050
FIGURE 4-10, Cascading Counters Example
When entered, these instructions will be displayed as intensified and blinking. The default word address above the instruction will havea reverse-video cursor positioned at the first digit. The instruction will continue to blink until all the data is entered.
Refer to Table 4-1 and 4-2 for a complete summary of Timer and Counter instructions.