Skip to main content

How to Use the Shift and Rotate Instructions in PLC?

 Let’s study the working shift and rotate instructions and its function in Siemens PLC programming with example ladder logic.

Shift and Rotate Instructions in PLC


Block Description

Shift Right Integer:

Shift Right Integer instruction is used to shift bits 0 to 15 of input IN bit by bit to the right. The input N specifies the number of bits by which to shift.


After shifting, the bit position shifted in from the left to fill vacated bit position are filled with 0 if 15th bit (Sign bit) of input data is 0 or 1 id 15th bit (Sign bit) of input is 1.


Example 1:


Input IN: 1010 0110 1000 1000


N: 2


OUT: 1110 1001 1010 0010


Example 2:


Input IN :0011 0001 0001 1100


N:2


Output OUT : -0000 1100 0100 0111


Shift Right Double Integer:

Shift Right Double Integer instruction is used to shift bits 0 to 31 of input IN bit by bit to the right. The input N specifies the number of bits by which to shift.


After shifting, the bit position shifted in from the left to fill vacated bit position are filled with 0 if 15th bit (Sign bit) of input data is 0 or 1 id 15th bit (Sign bit) of input is 1.


Example 1:


Input IN: 0001 0111 1010 0111 1110 0011 1010 0101


N: 3

OUT: 0000 0010 1111 0100 1111 1100 0111 0100

Example 2:

Input IN :1011 1111 1111 0100 1110 0011 1010 0101

N:3

Output OUT : -1111 0111 1111 1110 1001 1100 0111 0100

Shift right Word:

Shift right Word instruction is used to shift bits 0 to 15 of input IN bit by bit to the right. The input N specifies the number of bits by which to shift.

After shifting, the bit position shifted in from the left to fill vacated bit position are filled with 0.

Example 1:

Input IN: 0011 0110 1100 0110

N: 2

OUT: 0000 1101 1011 0001

Example 2:

Input IN: 1111 0110 1100 1111

N: 2

Output OUT: -0011 1101 1011 0011

Shift Right double Word:

Shift Right double Word instruction is used to shift bits 0 to 31 of input IN bit by bit to the right. The input N specifies the number of bits by which to shift. After shifting, the bit positions shifted in from the left to fill vacated bit position are filled with 0.

Example 1:

Input IN: 0011 0110 1110 0011 1000 0110 0111 0111

N: 3

OUT: 0000 0110 1101 1100 0111 0000 1100 1110

Example 2:

Input IN : 1111 0110 1110 0011 1000 0110 0111 0111

N:3

Output OUT: -0001 1110 1101 1100 0111 0000 1100 1110

Read: Data Inside PLC

Rotate Right Double Word:

Rotate Right Double Word instruction is used to rotate the entire content of input IN bit by bit to the right. Input N specifies the number of bits by which to rotate.


The bit position shifted in from the left is assigned the logic states of the bits which were rotated out to the right.


Example 1:


Input IN : 1100 0110 0111 0011 0101 0101 1010 1100


N: 2


Output OUT: 0011 0001 1001 1100 1101 0101 0110 1011


Ladder Logic


Network 1:

Input I0.0 is pressed, SHR_I instruction reads the value in MW0, shifting 2 bit right and result the output to MW4. Q0.0 enables as long as I0.0 enables.


Network 2:

Input I0.0 is pressed, SHR_DI  instruction read the value in MD8, Shifting 3 bit right and result the output to MW14. Q0.1 enables as long as I0.0 enables.

Network 3:

Input I0.0 is pressed, SHR_W instruction reads the value in MW18, shifting 2 bit towards rights and result the output to MW22. Q0.2 enables as long as I0.0 enables.

Network 4:

Input I0.0 is pressed, SHR_DW instruction reads the value in, Shifting 3 bit towards the right and result the output to MD30. Q0.3 enables as long as I0.0 enables.

 Network 5 :

Input I0.0 is pressed, ROR_DW instruction reads the value in MD34, rotate the bits towards and result the output to MD40. Q0.4 enables as long as I0.0 enables.

Variable Table:

Variable is used to view the inputs and outputs in different formats.


In Siemens, MW is the address used for integer data, MD is the address used for double integer data.

Status Value in Variable table is used to see the input and output values.

Modify the value in the variable table is used to give input data.

Comments

Popular posts from this blog

PLC Program for Mixing Tank

 Create a ladder diagram for controlling a batch mixing process. Implement a PLC program for mixing tank or Mixing Process using PLC Ladder Logic. PLC Program for Mixing Tank Fig : Mixing tank A tank is used to mix two liquids. The required control circuit operates as follows: A. When the START button is pressed, solenoids A and B energize. This permits the two liquids to begin filling the tank. B. When the tank is filled, the float switch trips. This de-energizes solenoids A and B and starts the motor used to mix the liquids together. C. The motor is permitted to run for 1 minute. After 1 minute has elapsed, the motor turns off and solenoid C energizes to drain the tank. D. When the tank is empty, the float switch de- energizes solenoid C. E. A STOP button can be used to stop the process at any point. F. If the motor becomes overloaded, the action of the entire circuit will stop. G. Once the circuit has been energized, it will continue to operate until it is manually stopped. Solution...

What is Relay? How it Works? Types, Applications, Testing

 We use relays for a wide range of applications such as home automation, cars and bikes (automobiles), industrial applications, DIY Projects, test and measurement equipment, and many more. But what is Relay? How a Relay Works? What are the Applications of Relays? Let us explore more about relays in this guide. What is a Relay? A Relay is a simple electromechanical switch. While we use normal switches to close or open a circuit manually, a Relay is also a switch that connects or disconnects two circuits. But instead of a manual operation, a relay uses an electrical signal to control an electromagnet, which in turn connects or disconnects another circuit. Relays can be of different types like electromechanical, solid state. Electromechanical relays are frequently used. Let us see the internal parts of this relay before knowing about it working. Although many different types of relay were present, their working is same. Every electromechanical relay consists of an consists of an Elect...

Ferrules and Cross Ferruling

 Ferrules are identification labels provided for every wire terminations in an instrument, equipment, or electrical/instrumentation control panels. These tube-shaped sleeves can be inserted easily on each individual wire in a multi-core cable. In earlier days fixed digits/letters are used as ferrules, but now Instrumentation engineers/technicians prints out desired ferrules by using a ferrule printing machine. Typical Ferrule The numbers/ letters on the ferrules will be given as per the approved electrical hook up or loop diagrams. This helps technicians to easily identify a particular loop/wiring from a series of terminal blocks and to troubleshoot the desired terminal connection. Separate numbers on the ferrules distinguish the positive and negative polarities of wires, thus ensure the polarity protection of the instrument. Cross Ferruling  As a wire is connected on its both ends, it is quite useful to use a cross reference method for wire identification. Unlike normal ferru...