The text of a manual · part 28 of 55
Hand-Held Terminal (Catalog Number 1747-PT1) User Manual: 17 - Timer and Counter Instructions
Pages 233 to 246 of 486, from Hand-Held Terminal (Catalog Number 1747-PT1) User Manual
The original document is the PDF (1.5 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 1747-PT1
Page 233
Chapter
A–B
17
Timer and Counter Instructions This chapter covers the following timer and counter instructions for use with all processors except where noted: • Timer On-Delay (TON) • Timer Off-Delay (TOF) • Retentive Timer On-Delay (RTO) • Count Up (CTU) • Count Down (CTD) • High–Speed Counter (HSC) – fixed controller only • Counter or Timer Reset (RES)
Timer and Counter Instructions Overview
Timers and counters are output instructions. They include: • Timer On-Delay (TON). It counts timebase intervals when the rung is true and resets when the rung is false (non–retentive). The timebase is selectable as 0.01 sec or 1.0 sec for SLC 5/02 processors, and set at 0.01 sec for fixed controllers and SLC 5/01 processors. See page 17–3. • Timer Off-Delay (TOF). It counts timebase intervals when the rung is false and resets when the rung is true (non–retentive). The timebase is selectable as 0.01 sec or 1.0 sec for SLC 5/02 processors, and set at 0.01 sec for fixed controllers and SLC 5/01 processors. See page 17–4. • Retentive Timer On-Delay (RTO). An on-delay timer which retains its accumulated value when the rung goes false. See page 17–5. • Count Up (CTU). The count increments at each false-true transition of the rung. See page 17–7. • Count Down (CTD). The count decrements at each false-true transition of the rung. See page 17–7. • High–Speed Counter (HSC). A special CTU counter for use with fixed controllers having 24 VDC inputs. See page 17–9. • Counter or Timer Reset (RES). This instruction resets the accumulated value and status bits of a counter or timer. It cannot be used with TOF timers. See page 17–13. Timer and counter instructions have 3-word data file elements, illustrated on pages 17–2 and 17–7. Word 0 is the control word, containing the status bits of the instruction. Word 1 is the preset value. Word 2 is the accumulated value. The accumulated value is the current number of timebase intervals that have been measured for a timer instruction; for a counter instruction, it is the number of false-to–true transitions that have occurred. The preset value is the set point that you enter in the timer or counter instruction. When the accumulated value becomes equal to or greater than the preset value, the done status bit is set. You can use this bit to control an output device. 17–1
Page 234
Chapter 17 Timer and Counter Instructions
Preset and accumulated values for timers range from 0 to +32,767. If a timer preset or accumulated value is a negative number, a runtime error occurs and places the processor in a fault condition. Preset and accumulated values for counters range from –32,768 to +32,767. Indexed Word Addresses With SLC 5/02 processors, you have the option of referencing timer and counter preset and accumulated values in other areas of your program with indexed addressing. The purpose of using indexed addressing is to change the presets of several timers or counters or to reset several timers or counters. Before you do so, refer to the discussion of indexed addressing in 3–word elements, page 4–13.
Timer Data File Elements, Timebase, and Accuracy
Data File Elements Control word data for timer instructions includes three timer status bits, as indicated below. These are the only bits accessible in the control word. 15 14 13 EN TT DN
Internal Use
Preset Value Accumulated Value EN = Timer Enable Bit TT = Timer Timing Bit DN = Timer Done Bit
Timebase The timebase is a measure of the interval counted by a timer. Selectable as 0.01 sec or 1.0 sec for SLC 5/02 processors. Fixed at 0.01 sec for fixed controllers and SLC 5/01 processors. Accuracy Timing accuracy is minus 0.01 to plus 0 seconds, with a program scan of up to 2.5 seconds. Timing accuracy described here refers only to the length of time between the moment a timer instruction is enabled and the moment the timed interval is complete. Inaccuracy caused by the program scan can be greater than the timer time base. You must also consider the time required to energize the output device. Timing could be inaccurate if a Jump (JMP) or Jump to Subroutine (JSR) instruction is executed and skips over a rung containing the timer instruction while the timer is timing. If the skip duration is within 2.5 seconds, no time will be lost; if the skip duration exceeds 2.5 seconds, an undetectable timing error will occur. 17–2
Page 235
Chapter 17 Timer and Counter Instructions
Timer On-Delay (TON)
Timer On–Delay
HHT Ladder Display:
HHT Zoom Display: (online monitor mode)
TON
Output Instruction
(TON)
ZOOM on TON –(TON)– 2.0.0.0.2 NAME: TIMER ON DELAY TIMER: T4:0 TIME BASE .01 SEC PRESET: 120 ACCUM: 0 EN TT DN 0 0 0 EDT_DAT F1
Ladder Diagrams and APS Displays:
F2
F3
F4
F5
TON TIMER ON DELAY Timer T4:0 Time Base 0.01 Preset 120 Accum 0
(EN) (DN)
Operation: The TON instruction begins to count timebase intervals when rung conditions become true. As long as rung conditions remain true, the timer adjusts its accumulated value (ACC) each scan until it reaches the preset value (PRE). The accumulated value is reset when rung conditions go false, regardless of whether the timer has timed out. Status Bits The done bit (DN) is set when the accumulated value is equal to the preset value. It is reset when rung conditions become false. The timer timing bit (TT) is set when rung conditions are true and the accumulated value is less than the preset value. It is reset when the rung conditions go false or when the done bit is set. The enable bit (EN) is set when rung conditions are true; it is reset when rung conditions become false. Effects of processor mode changes: When the processor changes from the Run or Test mode to the Program mode or user power is lost while the instruction is timing but has not reached its preset value, the following occurs: • Timer enable and timing bits remain set. • Accumulated value remains the same. Upon return to the Run or Test mode, the following can happen: • If the rung is true, the accumulated value is reset, and the timing and enable bits remain set. • If the rung is false, the accumulated value is reset and the control bits are reset. 17–3
Page 236
Chapter 17 Timer and Counter Instructions
Timer Off-Delay (TOF)
Timer Off–Delay HHT Ladder Display:
HHT Zoom Display: (online monitor mode)
TOF
Output Instruction
(TOF) ZOOM on TOF –(TOF)– 2.0.0.0.2 NAME: TIMER OFF DELAY TIMER: T4:1 TIME BASE .01 SEC PRESET: 120 ACCUM: 0 EN TT DN 0 0 0 EDT_DAT F1
Ladder Diagrams and APS Displays:
F2
F3
F4
F5
TOF TIMER OFF DELAY Timer T4:1 Time Base 0.01 Preset 120 Accum 0
(EN) (DN)
Operation: The TOF instruction begins to count timebase intervals when the rung makes a true-false transition. As long as rung conditions remain false, the timer increments its accumulated value (ACC) each scan until it reaches the preset value (PRE). The accumulated value is reset when rung conditions go true regardless of whether the timer has timed out. Status Bits The done bit (DN) is reset when the accumulated value is equal to the preset value. It is set when rung conditions become true. The timing bit (TT) is set when rung conditions are false and the accumulated value is less than the preset value. It is reset when the rung conditions go true or when the done bit is reset. The enable bit (EN) is set when rung conditions are true; it is reset when rung conditions become false. Effects of processor mode changes: When processor operation changes from the Run or Test mode to the Program mode or user power is lost while a timer off-delay instruction is timing but has not reached its preset value, the following occurs: • Timer enable bit remains reset. • Timing and done bits remain set. • The accumulated value remains the same.
17–4
Page 237
Chapter 17 Timer and Counter Instructions
When you go back to the Run or Test mode, the following can happen: • If the rung is true, the accumulated value is reset, the timing bit is reset, the enable bit is set, and the done bit remains set. • If the rung is false, the accumulated value is set equal to the preset value and the control bits are reset. The counter/timer RES instruction cannot be used with the TOF instruction.
Retentive Timer (RTO)
Retentive Timer
HHT Ladder Display:
HHT Zoom Display: (online monitor mode)
RTO
Output Instruction
(RTO)
ZOOM on RTO –(RTO)– 2.0.0.0.2 NAME: RETENTIVE TIMER ON TIMER: T4:2 TIME BASE .01 SEC PRESET: 120 ACCUM: 0 EN TT DN 0 0 0 EDT_DAT F1
Ladder Diagrams and APS Displays:
F2
F3
F4
F5
RTO RETENTIVE TIMER ON Timer T4:2 Time Base 0.01 Preset 120 Accum 0
(EN) (DN)
Operation: The RTO instruction begins to count timebase intervals when rung conditions become true. As long as rung conditions remain true, the timer increments its accumulated value (ACC) each scan until it reaches the preset value (PRE). The accumulated value is retained when any of the following occurs: • Rung conditions become false. • You change processor operation from the Run or Test mode to the Program mode. • The processor loses power (provided that battery backup is maintained). • A fault occurs. When you return the processor to the Run or Test mode and/or rung conditions go true, timing continues from the retained accumulated value. By retaining its accumulated value, retentive timers measure the cumulative period during which rung conditions are true. You can use this instruction to turn an output on or off depending on your ladder logic.
17–5
Page 238
Chapter 17 Timer and Counter Instructions
Status Bits
• The done bit (DN) is set when the accumulated value is equal to the preset value. However, it is not reset when rung conditions become false; it is reset only when the appropriate RES instruction is enabled. • The timing bit (TT) is set when rung conditions are true and the accumulated value is less than the preset value. It is reset when the rung conditions go false or when the done bit is set. • The enable bit (EN) is set when rung conditions are true; it is reset when rung conditions become false. The accumulated value must be reset by the RES instruction. When the RES instruction having the same address as the RTO is enabled, the accumulated value and the control bits are reset. Effects of processor mode changes: When the processor changes from the Run or Test mode to the Program or Fault mode, or user power is lost while the timer is timing but not yet at the preset value, the following occurs: • The timer enable and timing bits remain set. • The accumulated value remains the same. When you return to the Run or Test mode or power is restored, the following can happen: • If the rung is true, the accumulated value remains the same and continues incrementing from where it stopped. The enable and timing bits remain set. • If the rung is false, the accumulated value remains the same, the timing and enable bits are reset, and the done bit remains in its last state.
17–6
Page 239
Chapter 17 Timer and Counter Instructions
Count Up (CTU) and Count Down (CTD)
Count Up, Count Down
HHT Ladder Displays:
HHT Zoom Displays: (online monitor mode)
CTU, CTD (CTU)
Output Instructions
(CTD)
ZOOM on CTU –(CTU)– NAME: COUNT UP COUNTER: C5:0 PRESET: 120 ACCUM: 0 CU CD DN OV UN 0 0 0 0 0 EDT_DAT F1
F2
F3
2.3.0.0.2
F4
ZOOM on CTD –(CTD)– NAME: COUNT DOWN COUNTER: C5:1 PRESET: 120 ACCUM: 0 CU CD DN OV UN 0 0 0 0 0 EDT_DAT F1
F2
F3
F5
2.4.0.0.2
F4
F5
Ladder Diagrams and APS Displays: CTU COUNT UP Counter Preset Accum
CTD (CU) C5:0 120 0
(DN)
COUNT DOWN Counter Preset Accum
(CU) C5:1 120 0
(DN)
CTU and CTD instructions are retentive. Count up and count down instructions count false-to-true rung transitions. These rung transitions could be caused by events occurring in the program such as parts traveling past a detector or actuating a limit switch. Each count is retained when the rung conditions again become false. The count is retained until an RES instruction having the same address as the counter instruction is enabled. Each counter instruction has a preset and accumulated value and a control word associated with it. 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.
17–7
Page 240
Chapter 17 Timer and Counter Instructions
Status Bits The control word for counter instructions includes six status bits, indicated in the figure below. 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 CU CD DN OV UN UA
Not Used
Preset Value Accumulated Value CU = Counter up enable bit CD = Counter down enable bit DN = Done bit OV = Overflow bit UN = Underflow bit UA = Update accumulator (HSC only)
Counter preset and accumulated values are stored as signed integers. Negative values are stored in two’s complementary form. When rung conditions for a CTU instruction have a false-to-true transition, the accumulated value increments by one count, provided that an evaluation occurs between these transitions. When this occurs successively so that the accumulated value becomes equal to the preset value, the counter done (DN) bit is set and remains set if the accumulator exceeds the preset. Bit 15 of the counter control word is the count up enable (CU) bit. It is set when rung conditions of the CTU instruction are true. The bit is reset when either rung conditions go false or an RES instruction having the same address as the CTU instruction is enabled. CTU instructions can count beyond their preset value. When counting continues past the preset value and reaches (32,767 + 1), an overflow condition results. This is indicated when bit 12, the overflow (OV) bit, is set. You can reset the overflow bit by enabling a RES instruction having the same address as the CTU instruction. You can also reset the overflow bit by decrementing the count less than or equal to 32,767 with a CTD instruction. When the OV bit is set, the accumulated value wraps around to – 32,768 and continues counting up from there.
17–8
Page 241
Chapter 17 Timer and Counter Instructions
CTD instructions also count false-to-true rung transitions. The counter accumulated value is decremented one count for each false-to-true transition. When a sufficient number of counts has occurred and the accumulated value becomes less than the preset value, the counter done bit (bit 13) is reset. Bit 14 of the counter control word is the count down enable (CD) bit. It is set when rung conditions of the CTD instruction are true. It is reset when either rung conditions go false (count down instruction disabled) or the appropriate reset instruction is enabled. When a CTD instruction counts beyond its preset value and reaches a count of (–32,768 – 1), the underflow bit (UN) is set. You can reset it by energizing the appropriate RES instruction. You can also reset the underflow bit by incrementing the count greater than or equal to –32,768 with a CTU instruction having the same address as the CTD instruction. When the UN bit is set, the accumulated value wraps around to +32,767 and continues counting down from there.
High–Speed Counter (HSC)
Fixed Controllers Only High–Speed Counter HHT Ladder Displays:
HHT Zoom Displays: (online monitor mode)
HSC
Output Instruction
(HSC)
ZOOM on HSC –(HSC)– NAME: HIGH–SPEED COUNTER COUNTER: C5:0 PRESET: 800 ACCUM: 0 CU CD DN OV UN UA 0 0 0 0 0 0 EDT_DAT F1
F2
F3
2.0.0.0.2
F4
F5
Ladder Diagrams and APS Displays: HSC HIGH–SPEED COUNTER Counter C5:0 Preset 800 Accum 0
(CU) (DN)
The High–Speed Counter is a variation of the CTU counter. The HSC instruction is enabled when the rung logic is true and disabled when the rung logic is false.
17–9
Page 242
Chapter 17 Timer and Counter Instructions
Important: This instruction provides high–speed counting on fixed controllers with 24 VDC inputs. One HSC instruction allowed per controller. To use the instruction, you must clip a jumper as described in the installation manual, catalog number 1747–NI002. Input I:0/0 then operates in the high–speed mode. The address of the high–speed counter enable bit is C5:0/CU. When rung conditions are true, C5:0/CU is set and transitions occurring at input I:0/0 are counted. The maximum pulse rate is 8 kHz. Do not program an XIC instruction with the I:0/0 address and the HSC instruction as the output. This will enable and disable the high–speed counter –missing counts. Instead, use an unconditional rung with the HSC instruction, or use a condition that only prevents the HSC instruction from counting. To begin high–speed counting, load a preset value into C5:0.PRE and enable the counter rung. To load a preset value, do one of the following: • Change to the Run or Test mode from another mode. • Power up the processor in the Run mode. • Reset the HSC using the RES instruction. Automatic reloading occurs when the HSC itself sets the DN bit on interrupt. Each input transition that occurs at input I:0/0 will cause the accumulator of the HSC to increment. When the accumulator value equals the preset value, the done bit (C5:0/DN) will be set, the accumulator will be cleared, and the preset value (C5:0.PRE) will be loaded into the HSC in preparation for the next high–speed transition at input I:0/0. The ladder program polls the done bit (C5:0/DN) to determine the state of the HSC. Once the done bit has been detected as set, the ladder program should clear bit C5:0/DN (use the unlatch OTU instruction) before the HSC accumulator again reaches the preset value, or the overflow bit (C5:0/OV) will be set. It is important to note that the HSC differs from the CTU and CTD counters in that the HSC is a hardware counter as opposed to a software counter and that the HSC operates asynchronously to the ladder program scan. The HSC accumulator value (C5:0.ACC) is normally updated each time the HSC rung is evaluated in the ladder program (this means that the HSC hardware accumulator value is transferred to the HSC software accumulator). Many HSC counts could occur between HSC evaluations which would make C5:0.ACC inaccurate when used throughout a ladder program. To allow for an accurate HSC accumulator value, the update accumulator bit (C5:0/UA) will cause C5:0.ACC to be immediately updated to the state of the hardware accumulator when set. (Use the OTE instruction only to reset the UA bit.) Note: The HSC instruction will immediately clear bit C5:0/UA following the accumulator update. The high–speed counter can be reset using the RES instruction at address C5:0. A reset will clear the HSC status bits, clear the accumulator, and load the preset value into the counter.
17–10
Page 243
Chapter 17 Timer and Counter Instructions
The HSC’s status bits and accumulator are non-retentive. At power-up or Run mode entry, the HSC instruction will clear the status bits, clear the accumulator, and load the preset value. Instruction Parameters Address C5:0 is the HSC counter 3-word element. 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 CU CD DN OV UN UA
Not Used
Preset Value Accumulated Value CU = Indicates enable/disable status of the HSC CD = Does not apply to HSC DN = Done bit OV = Overflow bit UN = Does not apply to HSC UA = Update accumulator
• Word 0 contains the status bits of the HSC instruction: – Bit 10 (UA) updates the accumulator word of the HSC to reflect the immediate state of the HSC when true.
– Bit 12 (OV) indicates if a HSC overflow has occurred. – Bit 13 (DN) indicates if the HSC preset value has been reached. – Bit 15 (CU) shows the enable/disable state of the HSC. • Word 1 contains the preset value that is loaded into the HSC when the RES instruction is executed, when the done bit is set, or when powerup takes place. The valid range is 1 – 32767. • Word 2 contains the HSC accumulated value. This word is updated each time the HSC instruction is evaluated and when the update accumulator bit is set using an OTE instruction. This accumulator is read only. Any value written to the accumulator is overwritten by the actual high–speed counter on instruction evaluation, reset, or Run mode entry. Application Example In the figure that follows, rungs 6, 16, and 31 of the main program file each consist of an XIC instruction addressed to the HSC done bit and a JSR instruction. These rungs poll the status of the HSC done bit. When the DN bit is set at any of these poll points, program execution moves to subroutine file 3, executing the HSC logic. After the HSC logic is executed, the DN bit is reset by an unlatch instruction, and program execution returns to the main program file.
17–11
Page 244
Chapter 17 Timer and Counter Instructions
Program File 2 – Poll for DN Bit in Main Program File Rung
] [
6
31
JSR JUMP TO SUBROUTINE SBR file number 3
]/[
JSR JUMP TO SUBROUTINE SBR file number 3
]/[
( )
] [ JSR
C5:0 ] [ DN ] [
( )
] [
C5:0 ] [ DN
] [
( )
] [
C5:0 ] [ DN
] [
16
]/[
JUMP TO SUBROUTINE SBR file number 3
]/[
( )
] [
Program File 3 – Execute HSC Logic Rung 0
1
SBR SUBROUTINE
] [
]/[
] [
( )
HSC Application Logic
( )
] [
Unlatch DN Bit C5:0 (U) DN
20
RET 21
17–12
RETURN
Page 245
Chapter 17 Timer and Counter Instructions
Reset (RES)
Reset
RES
HHT Ladder Displays:
(RES)
HHT Zoom Displays: (online monitor mode)
ZOOM on RES –(RES)– NAME: RESET COUNTER: C5:0
Output Instruction
2.3.0.0.2
EDT_DAT F1
F2
F3
F4
F5
Ladder Diagrams and APS Displays: C5:0 (RES)
You use a reset instruction to reset timing and counting instructions. The RES instruction can also be used to reset the position value and status bits (except FD) of a control file (R6:0) used in sequencers, shift registers, etc. Using the RES instruction with timers and counters: When the RES instruction is enabled, it resets the retentive on-delay timer, count up, or count down instruction having the same address as the RES instruction. • With timers, the RES instruction resets the accumulated value, done bit, timing bit, and enable bit. • With counters, the RES instruction resets the accumulated value, overflow or underflow bit, done bit, and enable bits. If the counter rung is enabled, the CU or CD bit will be reset as long as the RES instruction is enabled. If the counter preset value is negative, the RES instruction sets the accumulated value to zero. This in turn causes the done bit to be set by a count down or count up instruction.
!
ATTENTION: Because the RES instruction resets the accumulated value, and the done, timing, and enabled bits, do not use the RES instruction to reset a TOF instruction. Unpredictable machine operation or injury to personnel may occur.
17–13