0% found this document useful (0 votes)
63 views18 pages

Chapter 10

Uploaded by

Saif Alabdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
63 views18 pages

Chapter 10

Uploaded by

Saif Alabdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 18
Chapter 10 PLC Shift & Rotate Instructions Scanned with CamScanner 161 PLC Shift & Rotate Instructions PLC shift and rotate instructions are often used to track parts on automated manufacturing lines by shifting either status or values through data files. The PLC not only uses a fixed pattem of register (word) bits but also can easily manipulate and change individual bits. A bit shift register is a register that allows the shifting of bits through a single register or group of registers. There are many types of shift and rotate instructions that are demonstrated in the following sections: 10.1 Shift Designated Array Elements. “The shift designated array elements (SHIFT_A) shifts the subarray elements starting from the start shifting location (Start) and terminating at the end shifting location (End). Each time the instruction enable bit (EN) experiences a positive transition, the subarray elements are shifted N times. The subarray first N elements (from the Start position) are filled by the data stored in the IN input variable. The data leaving the end position (overflowing data) is shifted to the output variable OUT. The direction of shifting is determined by the comparison state of Start and End, For Start > End, the shift direction is from the upper positions to the lower ones and vice versa. The source array (SRC) data type can be any type except the string type. Figure 10.1 shows the ladder symbol ofthe instruction under investigation and also the shifting movement for one positive transition of EN. SHFT_A SRC SRC BOOL—lgn ENO} BOOL ro] 1 ANY | out UINT Start=2 ARRAY ARRAY src SRC }- OF ANY OF ANY End=5 as OUT=5 UINT —sTART umt | ae Before Shifting After one pulse Shifting uINT Figure 10.1: SHIFT_A ladder symbol and behavior diagram Scanned with CamScanner 162 PLC Shift & Rotate Instructions Example 10.1: Using SHIFT_A instruction, write ladder program to generate the following repeated sequence [ 0, 1, 4, 8, 16, 32, 64, 128]. Solution: The solution is as drawn in Figure 10.2 with an ini ial value of A equals to {1, 4, 8, 16, 32, 64, 128}. , %QWO0.0.0 -%QW0.0.0 Figure 10.2: Example 10.1 ladder diagram 10.2 Shift with Carry ‘The shift with carry instruction (SHIFT_C) behaves the same way the SHIFT_A instruction does. It can be considered as SHIFT_A with Boolean data type but SRC is not an array data type. Here SCR may be Byte, Word, Dword, or Lword. Therefore, to treat SHIFT. C as SHIFT_A, the byte type data should be treated as if itis an array of 8 as an array of 16 Boolean type elements, dword as an Boolean type elements, word type data Lword as an array of 64 Boolean type elements. array of 32 Boolean type elements, and ——————— Scanned with CamScanner yr 163 PLC Shift & Rotate Instructions Figure 10.3 shows the ladder symbol of this instruction and also the shifting movement for cone positive transition of IN. SHET_C SRC:%MB; 4MB2 BOOL en ENO/~ BOOL “e 2 sae BOOL —cy —oUT}~ BOOL 1 1 Start=2 L {Bytes src src} (Byte, Word, Waa aa Dword, Endes Lword} Lword) 7 7 “Lout-o UINT —sTART 0 0 INT SEND Before Shifting After one pulse Shifting UINT + Figure 10.3: SHIFT_C ladder symbol and behavior diagram Using SHIFT_C instruction, write a ladder program to generate the Example 10.2: 0,1,2,4, 8 16, 32, 64, 128]. following repeated sequence [ Solution: The solution is as drawn in Figure 10.3 with an initial value of %MW2 equals 1. %~MW2 Figure 10.4: Example 102 ladder diagram Scanned with CamScanner ry oy 164 PLC Shift & Rotate Instructions 10.3 Shift Right The shift right instruction ( SHR) shifts the image of the bit string ( Byte, Word, Dword, Lword ) assigned to IN (instruction data input) as N (instruction shifting times) bits ‘number and stores the shifted result in the instruction output variable OUT. As compared to SHIFT_C, this one has one shift direction (from left to right). The shifting process is executed over the whole string image, the overflow dats lost, and there is no specific inlet to substitute the left end bit or bits. Figure 10.5 highlights the ladder symbol used and illustrates its operation for different N values. N | ouT SHR IN 11 6 BOOL rN ENOL BOOL 2 | 32 3 [16 {Byte,Word, ty our | {Byte,Word, %MB2=128 | 4 8 Dword,Lword Dword,Lword} 5 [4 | 6 | 2 INT 4N {2 so Figure 10.5: SHR ladder symbol and shifting Process as function of N Example 10.3: Draw a ladder diagram to copy the upper byte of %MWéyo the lower byte of %QW0.0.0 without affecting the content of the upper part of gwoon) Solution: See Figure 10.6. %QWO0.0.0 %QW0.0.0 x %QW0.0.0 Figure 10.6; Example10.3 ladder diagram Scanned with CamScanner 165 PLC Shift & Rotate Instructions 10.4 Shift Left The shift left instruction (SHL) does the reverse of its predecessor SHR. SHR does the integer division by two, but SHL does the multiplication by 2. It shifts the image of the bit string IN as N times from the least significant bit towards the most significant one. Figure 10.7 displays the ladder symbol used and illustrates the instruction operation for different N values. SHL IN N | OUT BOOL EN ENO|_ BooL {2 | {ByteWord,—IN OUT L (Byte, Word, 2 4 Dword,Lword Dword,L1 3 8 | NT worttword} | opa=1 [a] 16 | 5 32 6 | 64 7 [128 | 256 Figure 10.7: SHL ladder symbol and shifting Process as function of N Example 10.4: Draw ladder diagram to copy the lower byte of %MW4 to the upper byte of %QW0.0.0 without affecting the content of the lower part of %QW0.0.0. Solution: See Figure 10.8. %QWO.0.0 %QW0.0.0 16#00FF %QW0.0.0 8: Example 10.4 ladder diagram Figure 10: Scanned with CamScanner ON 166 PLC Shift & Rotate Instructions 10.5 Rotates Designated Array Elements The rotate designated array elements (ROTATE_A) shifts the subarray elements Starting from the start shifting location (Start) and terminating at the end shifting location (End) Each time the instruction enable bit (EN) experiences a positive transition, the subarray elements are shifted N times. The subarray first N elements (from the Start position) are filled with the data coming from the end location. The data leaving the end position (overflowing data) is stored in the output variable OUT. The direction of shifting is determined by the comparison state of Start and End. For start > End, the shift direction is from the upper positions to the lower one and vice versa. The source array (SRC) data type can be any type except the string type. Figure 10.9 shows the ladder symbol of the instruction under investigation and also the shifting movement for three different configurations, ROTATE_A BOOL4 EN ENO } BOOL Array ofany — SRC grc L Amay of. ‘any type except string type except string UINT —START OUT {Same type of SRC elements UINT SEND UINT Sn SRC Initial vale {1, 2, 3, 4, 5, 6, 7} where 1 represents the content of SRC [0] Pulse number | 1*' configuration OUT | 2” configuration OUT | 3" configuration OUT Start=0, End=6, N=1_| Start=0, End=6, N=2_| Start=1, End=5, N=1 1 7 6 6 2 6 4 3 3 5 2. 4 4 4 7 3 5 3 5 2 6 2 3 6 7 1 1 5 8 7 6 4 9 6 4 3 Figure 10.9: ROTATE_A ladder symbol and behavior for three different Configuration Scanned with CamScanner 167 PLC Shift & Rotate Instructions Example 10.5: Propose ladder diagram to control the ON/OFF switching of eight lamps according to the data listed in Figure 10.10. Assume the step rhythm to be 20 sec. Step [Output State Step | Output State 87654321 87654321 1 00011000 9 Tititiid 7 [00100100 10 [00000000 3 01000010 Vitiiiit 4| 10000001 12 [00000000 5 01000010 13 didiiiit 600100100 7100011000 [s[ 00000000 Figure 10.10: Data table of example 10.5 Solution: Figure 10.11 details the solution in which the array Y is initialized with the hexadecimal values {18, 24, 42, 81, 42, 24, 18, 00, FF, 00, FF, 00, FF}. ROTATE_A EN ENO SRC Y START SRC OUT %QB0.0.0 Figure 10.11: Example 10.5 ladder diagram Scanned with CamScanner 168 PLC Shift & Rotate Instructions 10.6 Rotate With Carry The rotate with carry instruction (ROTATE_C) shifts the bit string variable gRc ( ay be Byte, Word, Sword, Lword) bits starting from the start shifting location (st : terminating at the end shifting location (END). Each time the instruction enable bit . experiences a positive transition, the string bits are shifted N times. The string first x a (from the Start position) are filled with the data coming from the end location. The pe leaving the end position (overflowing data) is stored in the Boolean output variable our The direction of shifting is determined by the comparison state of Start and End, For starts End, the shift direction is from the upper positions to the lower ones and vice versa, Fi 10.12 shows the ladder symbol of this shifting instruction and its behaviour under differen configurations. RC — ROTATE_C BOOL —|py — ENOL__BOOL {Byte, Word, Dword, — src SRC {Byte, Word, Dword, Lword) Lword} . UINT START outL goon uINT [en unt _| SRC Initial vale {16#12) Pulse | 1*configuration | 2 configuration | 3"configuration | 4th configuration No, SRC SRC SRC OUT Start=0, | Start=0, End=6, | Start=6, End=0, | Start=1, End=5, N=1 End=6, N=1_| N=2 N=I i 24 8 @ 24 2 48 22 44 0A 3 i 9 22 14 4 22 24 I 28 5 44 U1 48 2 [6 09 44 24 24 7 12 12 12 OA 8 24 48 09 14 9 48 22 44 28 Figure 10.12: ROTATE_C ladder symbol and behavior for four different Configuration Scanned with CamScanner Dini 169 PLC Shift & Rotate Instructions example 10.6: The water circulation forthe cooling tower i to be 24 hours. Propose @ three ester pump system in which each pump runs one hour and rests (wo. olutlon: Figure 10.13 shows the three pump controller ladder diagram. Run TI TMR_FLK EN goats Q 1#30M ON T#30M — OFF ET o4 ROTATE_C Figure 10. 13: The proposed three pump controller 10.7 Rotate Right ‘The rotate right instruction ( ROR) shifts the image of the input bit string IN (Byte, Word, Dword, Lword) as N (shifting times) bits umber. It also fills the leftmost locations with the values shifted out of the rightmo: such that for M bits string, the least significant bit Bo of INis rounded to image Bou bit. The modified (shifted and rounded) red in the output variable OUT. Figure 10.14 shows the version of the input bit string is sto! ; the aforementioned explanation. ladder symbol and enhances Scanned with CamScanner 170 PLC Shift & Rotate Instructions ROR BOOL gn ENOL BOOL {Byte, Word, IN {Byte, Word, Dword, Lword} OUT} Dword, Lword} INT IN value {2#10101010) Bit [IN| OUT (N= OUT (N=) OUT (N=3 TL 6 |0 | OUTB6=INB7=1 5_| 1 | OUTBS=INB6=0_|_OUTBS=INB7=1 a1 40, OUTB4=INB6=0 Bis [ual 1 2 OUTB2=INB4=0 1 OUTBI=INB3=1 |=INB4=0_ 0 OUTBO=INB1=1 OUTBO=INB2=0 | OUTBO=INB3=1 Figure 10.14: ROR ladder symbol and its behavior under different values of N Example 10.7: Using ROR instruction, write a ladder program to generate the following repeated sequence [16, 8, 4, 2, 1] Solution: See Figure 10.15. axe %QB0.0.0 Figure 10.15: Ladder diagram of example 10.7 Scanned with CamScanner 171 PLC Shift & Rotate Instructions 10.8 Rotate Left. The rotate left instruction (ROL) shifts the image of the input bit string IN (Byte, Word, Dword, Lword) as N bits number. It also fills. the rightmost locations with the values shifted out of the leftmost locations such that for M bits string, the most significant bit Bu of IN is rounded to image By, bit. The modified version of the input bit string is stored in the output variable OUT. Figure 10.16 shows the ladder symbol and tabulates the left rotation of %MB3 for different values of N. } IN value=%MB3= {2#10101010} Bit | IN OUT (N=!) OUT (N=2) ‘QUTB7=INBS=1 ‘QUTB6=INB4=0 S)—[NJe]s]e]o]2 o|-lo|-lo Figure 10.16: ROL ladder symbol and its OUT value as function of N Example 10.8: Using ROL instruction, write a ladder program to generate the following repeated sequence [1, 2,4, 8; 16) “Solution: See Figure 10.17. ! Ladder dingram of example 10.8 solution 7: Scanned with CamScanner 172 PLC Shift & Rotate Instructions 10.9 First IN First OUT The first-in-first-out (FIFO_XXXXX) is two gates controlled queue. Its inlet gate jg controlled by the input marked LOAD, while its exit gate is controlled by the UNLD input, The queue itself is an array of any type of data except the string one (XXXXX € {BOOL, BYTE, WORD, DWORD, LWORD, SINT, INT, DINT, LINT, USINT, UINT, UDiNT. ULINT, REAL, LREAL, TIME, DATE, TOD, DT}. It has two flags and one pointer. The flags are the empty flag (EMPTY) which rises 1 when the queue is free from any item, and the full flag (FULL) which declares that there is no empty position in the queue (the queue is full). The pointer (PNT) points to the top of the queue, it ranges from 0 to the queue capacity. The in and out traffic of items are controlled by the queue request input (REQ). New item entering depends upon the states of the REQ, LOAD, the FULL, a new item is allowed to enter only if REQ=1, LOAD=1, and Full =0. Pushing items out of the queue depends upon UNLD and REQ states. UNLD should be "1" and also REQ should be "1", The function block of this instruction is shown in Figure 10.18. FIFO_XXXXX BOOL _lREQ DONE |- BOOL {Any type JIN except string} OUT |_ {Any type except string} {Array of any type except string} =~ | fe BOOL—|LOAD PNT |—_ INT BOOL—+ UNLD FULL }— BOOL BOOL_RST EMPTY }+— BOOL Figure 10,18; FIFO function block : Example 10.9; Write a ladder program to keep track of the last 12 values of a certain integer type variable. Bere ge Scanned with CamScanner . 173 PLC Shift & Rotate Instructions aewrsreal cu Get_Out \-first-out (LIFO_XXXXX) is a stack in which the inlet and exit share the same (opening). The stack itself is an array of any type of data except the string one tics new item) i is done int the request is one (REQ=1). The stack i is not full 0), and the load enables is active (LOAD=1). Unloading the stack (releasing the is ok when the request is one, and the unload input is active (UNLD=1). The also includes an integer type pointer (PNT) to keep track the top of the stack 1). The function block of ‘this instruction is well illustrated in Figure 10.20. Scanned with CamScanner 174 PLC Shift & Rotate Instructions LIFO_XXXXX BOOL REQ DONE BOOL {Any type IN except string)| OUT | {Any type {Amay of any type rip except string} except string} BOOL—|LOAD PNT [— INT BOOL~]UNLD FULL [— BOOL BOOL>RST EMPTY ;~ BOOL Figure 10.20: LIFO function block Example 10.10: Write a ladder program to capture the first N values of a certain word type variable. Solution: See Figure 10.21. LIFO_WORD REQ ~ DONE UNLD [RST FULL EMPTY Figure 10.21: Storing the first N values Scanned with CamScanner 175 PLC Shift & Rotate Instructions 10.11 Problems 1. Using only shift and logical instructions, write a PLC ladder diagram that allows the teacher to teach AND, OR, XOR, NAND, NOR, and XNOR through using 100 and 101 for the gates inputs, and Q00 for the output of the selected function. 2. Write a PLC ladder diagram to achieve the swit ‘Assume the switching clock pulse is 10 seconds. logic gates 113, 114, 115 for the function selection, ching pattem shown in Figure 10.22. Figure 10.22: Problem 2 Scanned with CamScanner os 176 PLC Shift & Rotate Instructions 3. The bottles going to the heat based shrink system should be in an upstanding situation, and any fallen bottles should not be allowed to enter the grouping station (P3), They should be rejected at a location prior to the grouping station (say at rejection station). The system is as illustrated in Figure 10.23. Assume P1 to be the detection location, P2 the rejection station, and the sensor LS3 generates 10 pulses when the conveyor travels from location P1 to P2, design the required control system. Write a PLC ladder program to do that. PL P2 Figure 10.23: Problem 3 4. Write a ladder program to sequentially run 8 motors. Let the separation period between two adjacent switching process equals 10s. Write a PLC ladder program for the parts sorting machine that is shown in Figure 10.24, In this application, defective products are detected and rejected from those being carried on the conveyor. A photosensor (ph) serves as a data input to shift register. The signal output from this sensor tums on when a defective product is detected, otherwise, it remains off. A. photosensor (ph2) is used as a clock generator that serves as the clock input to the shift register. It generates one pulse each time the product spaced at a fixed interval from each other and it has travelled a predetermined distance, From the moment phi detects a defective product, it is traced by the shift register until the product arrives at the predetermined position on the conveyor where the magnetic valve MV rejects it. y Scanned with CamScanner yr 177 PLC Shift & Rotate Instructions A Figure 10.24: Problem 5 Scanned with CamScanner

You might also like