Page 187 - Programmable Logic Controllers, Fifth Edition - Mobile version
P. 187

Enter     Ladder logic program
                             L1    Inputs                                                     Output    L2
                                                switch
                                                          CTU
                                      Enter               COUNT-UP COUNTER         CU      Lot full
                                      switch              Counter     C5:1         DN       light
                                                          Preset       150
                                                          Accumulated   0
                                                 Exit
                                                switch
                                                          CTD
                                       Exit               COUNT-DOWN COUNTER       CD
                                      switch              Counter       C5:1
                                                          Preset        150        DN
                                                          Accumulated       0   Lot full
                                               C5:1/DN                           light

                                      Reset
                                                Reset
                                                                                 C5:1
                                                                                  RES

                             Figure 8-23  Parking garage counter.


                 •  As a car leaves, the exit switch triggers the down-  Input           Ladder logic program  Output
                    counter output instruction and decrements the accu-  L1            CTD                           L2
                    mulated count by 1.                                   I:1/0   I:1/0  COUNT-DOWN COUNTER      0:2/0
                                                                                       Counter                    C5:0  CU
                 •  Because both the up- and down-counters have the                    Preset                             2  PL
                    same address, C5:1, the accumulated value will                     Accumulated                  4  DN
                    be the same in both instructions as well as the
                    preset.
                                                                                 C5:0
                 •  Whenever the accumulated value of 150 equals                                     0:2/0
                    the preset value of 150, the counter output is                  DN
                    energized by the done bit to light up the Lot
                    Full sign.                                       Figure 8-24  Count-down counter instruction.
                 •  A reset button has been provided to reset the accu-
                    mulated count.
                                                                       •  When the input rung condition makes another
                  Figure  8-24 shows an example of the count-down         false-to-true transition, the accumulated value will
               counter instruction used as part of the  Allen-Bradley     decrease to 2.
               SLC 500 controller instruction set. The information to be
               entered into the instruction is the same as for the count-up   •  When the input makes one more false-to true transi-
               counter instruction.                                       tion, the accumulated value will drop to 1.
                  The CTD instruction decrements its accumulated value   •  At this point the accumulated value of 1 is less than
               by 1 every time it is transitioned. It sets its done bit when   the preset value of 2 so the done bit will be reset (0)
               the accumulated value is equal to or greater than the preset   de-energizing output O:2/0.
               value. The program of Figure 8-24 contains a count-down
               counter instruction, the operation of which can be sum-  Figure  8-25 shows an up/down-counter program
               marized as follows:                                   that will increase the counter’s accumulated value
                                                                     when pushbutton PB1 is pressed and will decrease the
                 •  With the program in the state shown, the CTD done   counter’s accumulated value when pushbutton PB2
                    bit will be set (1) and output 0:2/0 will be energized   is pressed. Note that the same address is given to the
                    because the accumulated value of 4 is greater than   up-counter instruction, the down-counter instruction,
                    the preset value of 2.                           and the reset instruction. All three instructions will be
                 •  When the CTD instruction rung makes a            looking at the same address in the counter file. When
                    false-to-true transition, the accumulated value   input A goes from false to true, one count is added to
                    decreases by one count to 3.                     the accumulated value. When input B goes from false



               168        Chapter 8  Programming Counters







          pet73842_ch08_156-183.indd   168                                                                              03/11/15   3:58 PM
   182   183   184   185   186   187   188   189   190   191   192