Файл: Programmable logic controllers. Methods and Applications (Hackworth J., Prentice Hall).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 2136
Скачиваний: 0
Chapter 4 - Advanced Programming Techniques
If we implement this expression using ladder contact logic, the ladder portion would be as shown in Figure 4-9. The input definitions already set are used in this figure.
Figure 4-9 - Contact Logic Required to
Implement T = KQ + J Q
If you refer back to Figure 4-8, you will see this contact configuration in the first rung of the ladder controlling the triggering of the one shot from IN3. The result is that the ladder diagram of Figure 4-8 will function as a J-K flip flop.
4-10. Counters
A counter is a special function included in the PLC program language that allows the PLC to increment or decrement a number each time the control logic for the rung switches from false to true. This special function generally has two control logic lines, one which causes the counter to count each time the control becomes true and one which causes the counter to reset when the control line is true. A typical counter is shown in Figure 4-10.
Figure 4-10 - Counter
4-15
Chapter 4 - Advanced Programming Techniques
Notice that this special function has two control lines one containing a normally open contact IN1 and one containing normally open contact IN2. The counter itself has a coil associated with it that is numbered CTR1. Notice too, that inside the function block are two labels, ACTUAL and PRESET. These ACTUAL and PRESET items contain numbers. The PRESET value is the maximum count allowed for the counter. This number may be held as a constant value in permanent memory or as a variable in a Holding Register. A holding register is a memory location in RAM which may be altered as required. The programmer would use a holding register for the PRESET value of the counter if the maximum count value needed to change depending upon program operation such as in a program that needed to count items to be placed in a box. If different size boxes were used depending upon the product and quantity to be shipped, the counter maximum may need to change. The ACTUAL value is maintained in a RAM location because it is the present value of the counter. As the counter counts, this value must change and it is this value compared to the PRESET value that the PLC uses to determine if the counter is at its maximum value. As the ACTUAL value increases with each count it is compared to the PRESET value. When the ACTUAL value is equal to the PRESET value, the counter will stop counting and the coil associated with the counter (in this case CTR1) will be energized.
In our example in Figure 4-10, contacts IN1 and IN2 control the counter. The top line, containing IN1, is referred to as the COUNT LINE. The lower control line, containing IN2 is referred to as the RESET LINE. Note that with some PLC manufacturers the two input lines are reversed that shown in Figure 4-10, with the RESET line on top and the
COUNT line below. In operation, if IN2 is closed the counter will be held in the reset condition, that is, the ACTUAL value will be set to zero no matter whether IN1 is open or closed. As long as the reset line is true, the ACTUAL value will be held at zero regardless of what happens to the count line. If the RESET LINE is opened, the counter will be allowed to increment the ACTUAL value each time the count control line switches from false to true (off to on). In our example that will be each time IN1 switches from open to closed. The counter will continue to increment the ACTUAL value each time IN1 switches from open to closed until the ACTUAL value is equal to the PRESET value. At that time the counter will stop incrementing the ACTUAL value and coil CTR1 will be energized. If at any time during the counting process the RESET control line containing IN2 is made to switch to true, the ACTUAL value will be reset to zero and the next count signal from IN1 will cause the ACTUAL value to increment to 1.
Different PLC manufacturers handle counters in different ways. Some counters operate as described above. Another approach taken in some cases is to reset the ACTUAL value to the PRESET value (rather than reset it to zero), and decrement the
ACTUAL value toward zero. In this case the coil associated with the counter is energized when the ACTUAL value is equal to zero rather than when it is equal to the PRESET value.
4-16
Chapter 4 - Advanced Programming Techniques
Some manufacturers have counters that are constructed using two separate rungs.
These have an advantage in that the reset rung can be located anywhere in the program and does not need to be located immediately following the count rung. Figure 4-11 shows a counter of this type. In this sample program, note that N/O IN1 in rung 1 causes the counter to increment (or decrement, if it is a down counter) and N/O IN2 in rung 2 causes the counter C1 to reset to zero (or reset to the preset value if it is a down counter). Rung
3 has been added to show how a counter of this type can be used. Contact C1 in rung 3 is a contact of counter C1. It is energized when counter C1 reaches its preset value (if it is a down counter, it will energize when C1 reaches a count of zero). The result is that output OUT1 will be energized when input IN1 switches on a number of times equal to the preset value of counter C1.
* IN1 C1 1)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(CTR)1
*
*
*
* IN2 C1 2)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[RSctr]1
*
*
*
* C1 OUT1 3)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(OUT)1
*
Figure 4-11 - Two-Rung Counter and Output Rung
In some cases it is convenient to have a counter that can count in either of the two directions, called a bidirectional counter. For example, in a situation where a PLC needs to maintain a running tally of the total number of parts in a que where parts are both entering and exiting the que, a bidirectional counter can be incremented when a part enters and decremented when a part exits the que. Figure 4-12 shows a bidirectional counter, C2, which has three inputs and consists of three rungs. Rung one controls the counting of C2 in the up direction, rung two controls C2 in the down direction, and rung three resets C2.
4-17
Chapter 4 - Advanced Programming Techniques |
||
* IN1 |
C2 |
|
1)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[Upctr]1
*
*
*
* IN2 C2 2)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[DNctr]1
*
*
*
* IN3 C2 3)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[RSctr]1
*
Figure 4-12 - UP/Down Counter
4-11. Sequencers
Some machine control applications require that a particular sequence of events occur, and with each step of the controller, a different operation be performed. The programming element to do this type of control is called a sequencer. For example, the timer in a washing machine is a mechanical sequencer in that it has the machine perform different operations (fill, wash, drain, spin) in a predetermined sequence. Although a washing machine timer is a timed sequencer, sequencers in a PLC are not necessarily timed. An example of a non-timed sequencer is a garage door opener. It performs the sequence ...up, stop, down, stop, up stop,... with each step in the sequence being activated by a switch input or remote control input.
PLC sequencers are fundamentally counters with some extra features and some minor differences. Counters will generally count to either their preset value (in the case of up counters) or zero (for down counters) and stop when they reach their terminal count. However, sequencers are circular counters; that is, they will “roll over” (much like an automobile odometer) and continue counting. If the sequencer is of the type that counts up from zero to the preset, on the next count pulse after reaching the preset, it will reset to zero and begin counting up again. If the sequencer is of the type that counts down, on the next count pulse after it reaches zero, it will load the preset value and continue counting down. Like counters, sequencers have reset inputs that reset them either to zero (for the types that count up) or to the preset value (for the types that count down). As with counters, some PLC manufacturers provide sequencers with a third input (usually called
UP/DN) that controls the count direction. These are called bidirectional sequencers or reversible sequencers. Alternately, other bidirectional sequencers have separate count up and count down inputs.
4-18
Chapter 4 - Advanced Programming Techniques
Unlike counters, sequencers have contacts that actuate at any specified count of the sequence. For example, if we have an up-counting sequencer SEQ1 with a preset value of 10, and we would like to have a rung switch on when the sequencer reaches a count of 8, we would simply put a N/O contact of SEQ1=8 (or SEQ1:8) in the rung. For this contact, when the sequencer is at a count of 8, the contact will be on. The contact will be off for all other values of sequencer SEQ1. In our programs, we are allowed as many contacts of a sequencer as desired of either polarity (N/O or N/C), and of any sequence value. If for example, we would like our sequencer, SEQ1, to switch on an output OUT1 whenever the sequencer is in count 3 or 8 of it’s sequence, we would simply connect N/O contacts
SEQ1:3 and SEQ1:8 in parallel to operate OUT1. This is shown in Figure 4-13. In rung one, N/O contact IN1 advances the sequencer SEQ1 each time the contacts close. In rung two, N/O contact IN2 resets SEQ1 when the contact closes. In rung three, output OUT1 is energized when the sequencer SEQ1 is in either state 3 or state 8.
* IN1 Seq1 1)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[AVseq]1
*
*
*
* IN2 Seq1 2)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[RSseq]1
*
*
*
* Seq1:3 OUT1 3)))1 /)))0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(OUT)1 * Seq1:8 *
/)))1 /)))-
*
Figure 4-13 - Sequencer and Output Rung
4-12. Timers
A timer is a special counter ladder function which allows the PLC to perform timing operations based on a precise internal clock, generally 0.1 or 0.01 seconds per clock pulse. Timers usually fall into two different categories depending on the PLC manufacturer. These are retentive and non-retentive timers. A non-retentive timer is one which has one control line, that is, the timer is either timing or it is reset. When this type of timer is stopped, it is automatically reset. This will become more clear as discussion of timers continues. The retentive timer has two control lines, count and reset. This type of timer may be started, stopped then restarted without resetting. This means that it may be used as a totalizing timer by simply controlling the count line. Independent resetting occurs by activating the reset control line. At the beginning of this section, it was stated that a timer is a special
4-19
Chapter 4 - Advanced Programming Techniques
counter. The timing function is performed by allowing the counter to increment or decrement at a rate controlled by the internal system clock. Timers typically increment or decrement at 0.1 second or 0.01 second rates depending upon the PLC manufacturer.
An example of a non-retentive timer is shown in Figure 4-14. Notice that this timer has only one control line containing normally open contact IN1. Also notice that, like the counter, there are two values, ACTUAL and PRESET. These values are, as with the counter, the present and final values for the timer. While the control line containing, in this case, IN1 is false (IN1 is open) the ACTUAL value of the timer is held reset to zero. When the control line becomes true (IN1 closes), the timer ACTUAL value is incremented each 0.1 or 0.01 second. When the ACTUAL value is equal to the PRESET value, the coil associated with the timer (in this case TIM1) is energized and ACTUAL value incrementing ceases. The PRESET value must be set so that the timer counter ACTUAL value will increment from zero to the PRESET value in the desired time. For instance, suppose a timer of 5.0 seconds is required using a 0.1 second rate timer. The PRESET value would have to be 50 for this function since it would take 5.0 seconds for the counter to count from zero to 50 utilizing a 0.1 second clock (50 X 0.1 second = 5.0 seconds). If a 0.01 second clock were available, the PRESET value would have to be 500.
Figure 4-14 - Non-retentive Timer
An example of a retentive timer is shown in Figure 4-15. This type of timer looks more like the counter discussed earlier. The two control lines operate in much the same manner as the counter in that the lower line is the reset line. The top line, however, in the case of the timer is the time line. As long as the reset line is true and the time line is true, the timer will increment at the clock rate toward the PRESET value. As with the nonretentive timer, when the ACTUAL value is equal to the PRESET value, the coil associated with the timer will be energized and timer incrementing will cease. As with the timer, the
PRESET value must be chosen so that the ACTUAL value will increment to the PRESET value in the time desired dependent upon the clock rate.
4-20
Chapter 4 - Advanced Programming Techniques
Figure 4-15 - Retentive Timer
In some cases the PLC manufacturer will, as with the counter, design the timer to decrement the ACTUAL value from the PRESET value toward zero with the coil associated with the timer being energized when the ACTUAL value is equal to zero.
As can be seen from the above explanation for timers and counters, these functions are very similar in operation. Typically, the maximum number of timers and counters a PLC supports is a represented as the total combined number. That is, a system may specify a maximum total of 64 timer/counters. This means that the total of timers and counters can only be 64: therefore, if the program contains 20 timers, it can only contain 44 counters (20 timers + 44 counters = 64 timer/counters). The numbering of the timers and counters is handled differently by different manufacturers. In some cases they are numbered sequentially (TIM1 - TIM.. and CTR1 - CTR..) while in other cases they may not be allowed to share the same number (if TIM1 is present there cannot be a CTR1). Numbering and operation are dependent upon manufacturer and in some instances on the model of the PLC.
Example Problem:
Design a PLC program that will operate a light connected to output OUT1 when input IN1 is ON. When IN1 is ON, the output OUT1 is to flash continuously ON for 0.5 second and off for 1.0 second.
Solution:
Since there are two times specified in this problem (0.5 second and 1.0 second), we will need two timers.
4-21
Chapter 4 - Advanced Programming Techniques
Chapter 4 Review Questions and Problems
1.Draw the ladder rung for an R-S type flip flop that will energize when both IN1
AND IN2 are on and will de-energize when both IN3 AND IN4 are ON. The condition where all inputs are on will not be a defined state for this problem, i.e., it will not be allowed to occur so you do not have to plan for it.
2.Draw the ladder diagram for a T flip flop CR1 which will toggle only when IN1 and IN2 are both OFF.
3.Develop the ladder for a system of two T flip flops which will function as a two bit binary counter. The least significant bit should be CR1 and the most significant bit should be CR2. The clock input should be IN17.
4.Develop the ladder diagram for a 3 bit shift register using J-K flip flops that will shift each time IN1 is switched from OFF to ON. The input for the shift register is to be IN2. The three coils for the shift register may be any coil numbers you choose.
5.Design the ladder diagram for a BCD counter using T flip flops. The LSB of the counter is to be CR1 and the MSB is to be CR4. The clock input is IN2.
6.Design the ladder diagram for a device that will count parts as they pass by an inspection stand. The sensing device for the PLC is a switch that will close each time a part passes. This switch is connected to IN1 of the PLC.
A reset switch, IN2, is also connected to the PLC to allow the operator to manually reset the counter. After 15 parts have passed the inspection stand, the PLC is to reset the counter to again begin counting parts and turn on a light which must stay on until reset by a second reset switch connected to IN3. The output from the PLC that lights the light is OUT111.
7.Design the ladder diagram for a program which needs a timer which will cause a coil CR24 to energize for one scan every 5.5 seconds.
4-22