You are on page 1of 14

PLC Laboratory

Fourth Year

Experiment no.6

The PLC Shift and Rotate Instructions

Student's Name: Ahmed Makki Abdul Al-Hassan

Student's No.: 4

Type of Studying: power and Machines

Prepared by:
Dr Ammar A. Aldair
Dr Mofeed T. Rashid

PLC Lab – Fourth Year Page 1


Objectives: To understand the meaning, where, and how to
use: 1- Shift Designated Array Elements (SHIFT_A).

2- Shift with Carry

(SHIFT_C). 3- Shift Right

(SHR).

4- Shift Left (SHL).

5- Rotate Designated Array Elements

(ROTATE_A). 6- Rotate With Carry (ROTATE_C).

7- Rotate To Right

(ROR). 8- Rotate To Left

(ROL).

9- FIFO and LIFO instructions

Discussion:

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 pattern 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. In the following, there are many types of shift and rotate
instructions:
5.1 Shift Designated Array Elements

Figure 5.1 shows the ladder symbol of the instruction under


investigation and also the shifting movement for one positive transition of
IN.
SHFT_A SRC SRC
BOOL EN ENO BOOL 0 0
1 IN=10 1
ANY IN OUT UINT
Start=2 2 10
ARRAY
ARRAY SRC SRC 3 2
OF AN
OF AN 4 3
START Y
UINT End=5 5 4
UINT END 6 6 OUT=5
UINT 7 7
N
Before Shifting After one pulse Shifting

Figure 5.1 SHIFT_A ladder symbol and behavior diagram

5.2 Shift with Carry

The shift with carry instruction (SHIFT_C) behaves the same way
the SHIFT_A instruction does. Figure 5.2 shows the ladder symbol of
this instruction and also the shifting movement for one positive
transition of IN.
SHFT_C SRC:%MB2 SRC:%MB2
BOOL BOOL EN BOOL BOOL
ENO 0 0
1 IN=1 1
CY OUT
Start=2 0 1
{
{Byte, Word, SRC SRC Byte, Word, 1 0
Dword, Lwor d} Dword, 1 1
START Lword} 0 1
UINT
End=5 0 0 OUT=0
UINT END
0 0
UINT N
gh
5.3 Shift R After one pulse Shifting
t Before Shifting
The sh ift
Figure
right5.2 SHIFT_C
instruction ladder
(SHR) symbol
shifts and behavior
the image diagram
of the bit string
Byte, Word, Double word, Long word) assigned to IN (instruction data
input) as N (instruction shifting times) bits number and stores the shifted
result in the instruction output variable OUT. Figure 5.3 highlights the
ladder symbol used and illustrates its operation for
different N values.
IN N OUT
1 64
2 32
3 16
%MB2 4 8
SHR =128 5 4
BOOL EN ENO BOOL 6 2
{Byte,Word, IN OUT {Byte, Word, 7 1
Dword, Lword} 8 0
Dword, Lword}
INT N

Figure 5.3 SHR ladder symbol and shifting process as function of N


5.4 Shift Left

The shift let instruction (SHL) does the reverse done by 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 5.4
displays the ladder symbol used and illustrates the instruction
operation for different N values.

SHL
BOOL EN ENO BOOL IN N OUT
{Byte,Word, IN 1 2
OUT {Byte,Word,
Dword,Lword 2 4
Dword,Lword} 3 8
INT N %MB2=1 4 16
5 32
6 64
7 128
8 0
Figure 5.4 SHL ladder symbol and shifting Process as function of N

5.5 Rotates Designated Array Elements

Figure 5.5 shows the ladder symbol of the instruction under


investigation and also the shifting movement for three different
configurations.
ROTATE_A
BOOL BOOL
EN ENO
Array of any
SRC SRC Array of any
Type except g Type except
stri string
UINT START OUT
Same Type
UINT END Of SRC
UINT N Elements

SRC Initial value {1,2,3,4,5,6,7} where 1 represents the content of SRC[0].


Pulse 1st configuration OUT 2nd configuration OUT 3rd configuration OUT
number Start=0, End=6, Start=0, End=6, N=2 Start=1, End=5, N=1
N=1
1 7 6 6
2 6 4 5
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 5.5 ROTATE_A ladder symbol and behavior for three different configuration.

5.6 Rotate with Carry

Figure 5.6 shows the ladder symbol of this shifting instruction and its
behavior under different configurations.
ROTATE_C
BOOL ENO BOOL
EN
{Byte, Word, SRC
Dword, Lword} SRC {Byte, Word,
Dword, Lword}

UINT
STARTOUT END BOOL
UINT N
UINT

SRC Initial value {16#12}


Pulse 1stconfiguration SRC 2nd configuration SRC 3rdconfiguration SRC 4th configuration OUT
No. Start=0, End=6, N=1 Start=0, End=6, N=2 Start=6, End=0, N=1 Start=1, End=5, N=1
1 24 48 09 24
2 48 22 44 0A
3 11 9 22 14
4 22 24 11 28
5 44 11 48 12
6 09 44 24 24
7 12 12 12 0A
8 24 48 09 14
9 48 22 44 28

Figure 5.6 ROTATE_C ladder symbol and behavior for four different configuration.

5.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
number, fills the leftmost locations with the values shifted out of the
right most locations such that for M bits string, the least significant bit B0
of IN is rounded to image B(M-N) bit. The modified ( shifted and
rounded) version of the input bit string is stored in the output variable
OUT. Figure 5.7 shows the ladder symbol and enhances the
aforementioned explanation.
ROR
BOOL ENO BOOL
EN
{ Byte, Word, IN { Byte, Word,
Dword, Lword} OUT Dword,
INT Lword}

IN vale {2#10101010}
Bit IN OUT (N=1) OUT (N=2) OUT (N=3)
7 1 OUTB7=INB0=0 OUTB7=INB1=1 OUTB7=INB2=0
6 0 OUTB6=INB7=1 OUTB6=INB0=0 OUTB6=INB1=1
5 1 OUTB5=INB6=0 OUTB5=INB7=1 OUTB5=INB0=0
4 0 OUTB4=INB5=1 OUTB4=INB6=0 OUTB46=INB7=1
3 1 OUTB3=INB4=0 OUTB3=INB5=1 OUTB3=INB6=0
2 0 OUTB2=INB3=1 OUTB2=INB4=0 OUTB2=INB5=1
1 1 OUTB1=INB2=0 OUTB1=INB3=1 OUTB1=INB4=0
0 0 OUTB0=INB1=1 OUTB0=INB2=0 OUTB0=INB3=1

Figure 5.7 ROR ladder symbol and its behavior under different values of
N

5.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, fills the
rightmost locations with the values shifted out of the left most locations
such that for M bits string, the most significant bit B M-1 of IN is rounded to
image BN-1 bit. The modified version of the input bit string is stored in
the output variable OUT. Figure 5.8 shows the ladder symbol and
tabulates the left rotation of %MB3 for different values of N.
ROL
BOOL ENO BOOL
EN
{Byte, Word,
Dword, Lword}
IN {Byte, Word,
OUT Dword, Lword}
INT
N

IN vale=%MB3= {2#10101010}
Bit IN OUT (N=1) OUT (N=2) OUT (N=3)
7 1 OUTB7=INB6=0 OUTB7=INB5=1 OUTB7=INB4=0
6 0 OUTB6=INB5=1 OUTB6=INB4=0 OUTB6=INB3=1
5 1 OUTB5=INB4=0 OUTB5=INB3=1 OUTB5=INB2=0
4 0 OUTB4=INB3=1 OUTB4=INB2=0 OUTB46=INB1=1
3 1 OUTB3=INB2=0 OUTB3=INB1=1 OUTB3=INB0=0
2 0 OUTB2=INB1=1 OUTB2=INB0=0 OUTB2=INB7=1
1 1 OUTB1=INB0=0 OUTB1=INB7=1 OUTB1=INB6=0
0 0 OUTB0=INB7=1 OUTB0=INB6=0 OUTB0=INB5=1

Figure 5.8 ROL ladder symbol and its OUT value as function of N

5.9 First IN First OUT (FIFO)

The first-in-first-out (FIFO_XXXXX) is two gates controlled queue. Its


inlet gate is controlled by the input marked LOAD, its exit gate is
controlled by the UNLD input. The function block of this instruction is
shown in Fig.5.9.

5.10 Last IN First OUT (LIFO)

The last-in-first-out (LIFO_XXXXX) is a stack in which the inlet and


exit share the same terminal (opening). The function block of this instruction
is well illustrated in Fig.5.10.
FIFO_XXXXX
BOOL BOOL
REQ DONE
{Any type IN
except string {Any type
OUT
} except string
}
{Array of any
type except FIFO
string }
LOAD PNT
BOOL INT

BOOL UNLD FULL BOOL

BOOL RST EMPTY BOOL

Figure 5.9 FIFO function block.

BOOL
{Any type BOOL
except string }
ny type except string }
{Array of any type
except string}

INT
BOOL

BOOL BOOL

BOOL BOOL
Figure 5.10 LIFO function block.
Procedure:

Implement all instructions mentioned above using GMWIN or XG5000 PLC


software.
Exercises:
The bottles going to the heat based shrink system should be in 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 illustrated in
Fig.5.11. Assume P1 to be the detection location, P2 the rejection station,
and the sensor LS1 generates 10 pulses when the conveyor travels from
location P1 to P2, design the required control system.

P1 P2 P3
LS2
LS1

LS1

Fig.5.11

You might also like